CommonNetInterface.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. #define PHMS_DLL_EXPORTS
  2. #include "CommonNetInterface.h"
  3. #include "Poco/UUIDGenerator.h"
  4. #include "Poco/UUID.h"
  5. #include "Poco/Exception.h"
  6. #include "Poco/Thread.h"
  7. #include "Util.h"
  8. #include "PhmsLogger.h"
  9. #include "ExternalNetInterface.h"
  10. #include "ErrorCode.h"
  11. #include <map>
  12. #include "NetThreadManager.h"
  13. #include "SessionIdManager.h"
  14. #include "HandleMutexManager.h"
  15. #include "PushObjectManager.h"
  16. #include "AllObjectManagerUtil.h"
  17. #include "GlobalTerminalLogoString.h"
  18. using Poco::UUID;
  19. using Poco::UUIDGenerator;
  20. using Poco::Thread;
  21. using namespace std;
  22. string g_stringTerminalType;
  23. string g_stringContecServerAddr;
  24. string g_stringContecServerPort;
  25. string g_stringUsername;
  26. string g_stringPassword;
  27. void SetContecServerInfo(const char* stringContecServerAddr, const char* stringContecServerPort)
  28. {
  29. g_stringContecServerAddr = stringContecServerAddr;
  30. g_stringContecServerPort = stringContecServerPort;
  31. }
  32. void SetAppDir(const char* stringWorkDir)
  33. {
  34. return CUtil::SetAppDir(stringWorkDir);
  35. }
  36. int SetTerminalType(const char* stringTerminalType)
  37. {
  38. if(stringTerminalType == NULL)
  39. {
  40. return COMMON_PARAMETER_NULL;
  41. }
  42. g_stringTerminalType = stringTerminalType;
  43. return PHMS_SUCCESSFUL_RESULT;
  44. }
  45. NET_HANDLE InitializeNetLibObject()
  46. {
  47. CAllObjectManagerUtil::InitializeSSL();
  48. CAllObjectManagerUtil::InitializeLocale();
  49. //初始化日志对象Logger
  50. NET_HANDLE handle = new char[128];
  51. memset(handle, 0, 128);
  52. string stringUuid;
  53. stringUuid = CNetThreadManager::GetHandleByThreadId(Thread::currentTid());
  54. if(stringUuid.size() != 0)
  55. {
  56. strcpy(handle, stringUuid.c_str());
  57. return handle;
  58. }
  59. try
  60. {
  61. CPhmsLogger::GetPhmsLogger();
  62. }
  63. catch(Exception& error)
  64. {
  65. CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
  66. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_GENERATE_LOG_FILE_ERROR), __FUNCTION__, __FILE__, __LINE__);
  67. delete handle;
  68. return NULL;
  69. }
  70. if(g_stringTerminalType.size() == 0)
  71. {
  72. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_SET_TERMINAL_TYPE), __FUNCTION__, __FILE__, __LINE__);
  73. delete handle;
  74. return NULL;
  75. }
  76. stringUuid = UUIDGenerator::defaultGenerator().createOne().toString();
  77. int nRet = PHMS_SUCCESSFUL_RESULT;
  78. nRet = CNetThreadManager::InsertNetThread(stringUuid);
  79. if(nRet != PHMS_SUCCESSFUL_RESULT)
  80. {
  81. delete handle;
  82. return NULL;
  83. }
  84. nRet = CHandleMutexManager::InsertHandleMutex(stringUuid);
  85. if(nRet != PHMS_SUCCESSFUL_RESULT)
  86. {
  87. delete handle;
  88. return NULL;
  89. }
  90. strcpy(handle, stringUuid.c_str());
  91. return handle;
  92. }
  93. int DeleteNetLibObject(NET_HANDLE handle)
  94. {
  95. if(handle == NULL)
  96. {
  97. return COMMON_PARAMETER_NULL;
  98. }
  99. string stringUuid = handle;
  100. int nRet = PHMS_SUCCESSFUL_RESULT;
  101. //DeleteNetLibObject接口也不允许handle跨线程
  102. CExternalNetInterface* pNetInterface = NULL;
  103. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  104. if(pNetInterface == NULL)
  105. {
  106. //写日志
  107. return COMMON_INVALID_HANDLE;
  108. }
  109. Thread::yield();
  110. Mutex* pMutex = CHandleMutexManager::GetHandleMutex(handle);
  111. if(pMutex == NULL)
  112. {
  113. return COMMON_INVALID_HANDLE;
  114. }
  115. Thread::yield();
  116. pMutex->lock();
  117. nRet = CNetThreadManager::DeleteNetThread(stringUuid);
  118. if(nRet == PHMS_SUCCESSFUL_RESULT)
  119. {
  120. CAllObjectManagerUtil::UnInitializeSSL();
  121. CAllObjectManagerUtil::UnInitializeLocale();
  122. delete handle;
  123. }
  124. pMutex->unlock();
  125. nRet = CHandleMutexManager::DeleteHandleMutex(stringUuid);
  126. CAllObjectManagerUtil::ReleasePhmsLogger();
  127. return nRet;
  128. }
  129. int SetSessionId(const char* stringSessionId)
  130. {
  131. if(stringSessionId == NULL)
  132. {
  133. return COMMON_PARAMETER_NULL;
  134. }
  135. string stringTempSessionId = stringSessionId;
  136. int nRet = PHMS_SUCCESSFUL_RESULT;
  137. nRet = CSessionIdManager::SetSessionId(stringTempSessionId);
  138. return nRet;
  139. }
  140. int GetSessionId(char* bufSessionId, unsigned int nBufMaxLen)
  141. {
  142. if(bufSessionId == NULL)
  143. {
  144. return COMMON_PARAMETER_NULL;
  145. }
  146. string stringSessionId;
  147. int nRet = PHMS_SUCCESSFUL_RESULT;
  148. nRet = CSessionIdManager::GetSessionId(stringSessionId);
  149. if(nRet != PHMS_SUCCESSFUL_RESULT)
  150. {
  151. return nRet;
  152. }
  153. if(stringSessionId.size() <= nBufMaxLen)
  154. {
  155. strcpy(bufSessionId, stringSessionId.c_str());
  156. }
  157. else
  158. {
  159. return COMMON_BUF_SMALL;
  160. }
  161. return PHMS_SUCCESSFUL_RESULT;
  162. }
  163. int SetUsernameAndPassword(const char* stringUsername, const char* stringPassword)
  164. {
  165. if(stringUsername==NULL || stringPassword==NULL)
  166. {
  167. return COMMON_PARAMETER_NULL;
  168. }
  169. g_stringUsername = stringUsername;
  170. g_stringPassword = stringPassword;
  171. return PHMS_SUCCESSFUL_RESULT;
  172. }
  173. int KeepSession(NET_HANDLE handle)
  174. {
  175. if(handle == NULL)
  176. {
  177. return COMMON_PARAMETER_NULL;
  178. }
  179. string stringUuid = handle;
  180. CExternalNetInterface* pNetInterface = NULL;
  181. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  182. if(pNetInterface == NULL)
  183. {
  184. //写日志
  185. return COMMON_INVALID_HANDLE;
  186. }
  187. return pNetInterface->KeepSession();
  188. }
  189. int Logout(NET_HANDLE handle)
  190. {
  191. if(handle == NULL)
  192. {
  193. return COMMON_PARAMETER_NULL;
  194. }
  195. string stringUuid = handle;
  196. CExternalNetInterface* pNetInterface = NULL;
  197. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  198. if(pNetInterface == NULL)
  199. {
  200. //写日志
  201. return COMMON_INVALID_HANDLE;
  202. }
  203. return pNetInterface->Logout();
  204. }
  205. int UploadIm(NET_HANDLE handle, const char* stringSenderId, const char* stringSenderName, const char* stringReceiverId, const char* stringMsgDirection, const char* stringMsgType,
  206. const char* stringMsgContent, const char* stringAudioFilePath, const char* stringCaseId, const char* stringCaseType)
  207. {
  208. if(handle==NULL || stringSenderId==NULL || stringSenderName==NULL || stringReceiverId==NULL || stringMsgDirection==NULL || stringMsgType==NULL ||
  209. stringMsgContent==NULL || stringAudioFilePath==NULL || stringCaseId==NULL || stringCaseType==NULL)
  210. {
  211. return COMMON_PARAMETER_NULL;
  212. }
  213. string stringUuid = handle;
  214. CExternalNetInterface* pNetInterface = NULL;
  215. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  216. if(pNetInterface == NULL)
  217. {
  218. //写日志
  219. return COMMON_INVALID_HANDLE;
  220. }
  221. return pNetInterface->UploadIm(stringSenderId, stringSenderName, stringReceiverId, stringMsgDirection, stringMsgType, stringMsgContent, stringAudioFilePath, stringCaseId, stringCaseType);
  222. }
  223. int GetImList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringSenderId, const char* stringCaseId, const char* stringCaseType, const char* stringMsgDirection, const char* stringMsgType)
  224. {
  225. if(handle==NULL || stringLocalFilePath==NULL || stringSenderId==NULL || stringCaseId==NULL || stringCaseType==NULL || stringMsgDirection==NULL || stringMsgType==NULL)
  226. {
  227. return COMMON_PARAMETER_NULL;
  228. }
  229. string stringUuid = handle;
  230. CExternalNetInterface* pNetInterface = NULL;
  231. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  232. if(pNetInterface == NULL)
  233. {
  234. //写日志
  235. return COMMON_INVALID_HANDLE;
  236. }
  237. return pNetInterface->GetImList(stringLocalFilePath, stringSenderId, stringCaseId, stringCaseType, stringMsgDirection, stringMsgType);
  238. }
  239. int GetImList2(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringNextId)
  240. {
  241. if(handle==NULL || stringLocalFilePath==NULL || stringNextId==NULL)
  242. {
  243. return COMMON_PARAMETER_NULL;
  244. }
  245. string stringUuid = handle;
  246. CExternalNetInterface* pNetInterface = NULL;
  247. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  248. if(pNetInterface == NULL)
  249. {
  250. //写日志
  251. return COMMON_INVALID_HANDLE;
  252. }
  253. return pNetInterface->GetImList2(stringLocalFilePath, stringNextId);
  254. }
  255. int DownloadIm(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringMsgId, const char* stringUri, unsigned long nFileSize)
  256. {
  257. if(handle==NULL || stringLocalFilePath==NULL || stringMsgId==NULL || stringUri==NULL)
  258. {
  259. return COMMON_PARAMETER_NULL;
  260. }
  261. string stringUuid = handle;
  262. CExternalNetInterface* pNetInterface = NULL;
  263. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  264. if(pNetInterface == NULL)
  265. {
  266. //写日志
  267. return COMMON_INVALID_HANDLE;
  268. }
  269. return pNetInterface->DownloadIm(stringLocalFilePath, stringMsgId, stringUri, nFileSize);
  270. }
  271. int DownloadImComplete(NET_HANDLE handle, const char* stringMsgId)
  272. {
  273. if(handle==NULL || stringMsgId==NULL)
  274. {
  275. return COMMON_PARAMETER_NULL;
  276. }
  277. string stringUuid = handle;
  278. CExternalNetInterface* pNetInterface = NULL;
  279. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  280. if(pNetInterface == NULL)
  281. {
  282. //写日志
  283. return COMMON_INVALID_HANDLE;
  284. }
  285. return pNetInterface->DownloadImComplete(stringMsgId);
  286. }
  287. int ChangePwd(NET_HANDLE handle, const char* stringOldPwd, const char* stringNewPwd)
  288. {
  289. if(handle==NULL || stringOldPwd==NULL || stringNewPwd==NULL)
  290. {
  291. return COMMON_PARAMETER_NULL;
  292. }
  293. string stringUuid = handle;
  294. CExternalNetInterface* pNetInterface = NULL;
  295. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  296. if(pNetInterface == NULL)
  297. {
  298. //写日志
  299. return COMMON_INVALID_HANDLE;
  300. }
  301. return pNetInterface->ChangePwd(stringOldPwd, stringNewPwd);
  302. }
  303. int Feedback(NET_HANDLE handle, const char* stringTitle, const char* stringNotes, const char* stringPhone, const char* stringPicPath)
  304. {
  305. if(handle==NULL || stringTitle==NULL || stringNotes==NULL || stringPhone==NULL || stringPicPath==NULL)
  306. {
  307. return COMMON_PARAMETER_NULL;
  308. }
  309. string stringUuid = handle;
  310. CExternalNetInterface* pNetInterface = NULL;
  311. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  312. if(pNetInterface == NULL)
  313. {
  314. //写日志
  315. return COMMON_INVALID_HANDLE;
  316. }
  317. return pNetInterface->Feedback(stringTitle, stringNotes, stringPhone, stringPicPath);
  318. }
  319. int GetReportListOfCase(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCaseId)
  320. {
  321. if(handle==NULL || stringLocalFilePath==NULL || stringCaseId==NULL)
  322. {
  323. return COMMON_PARAMETER_NULL;
  324. }
  325. string stringUuid = handle;
  326. CExternalNetInterface* pNetInterface = NULL;
  327. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  328. if(pNetInterface == NULL)
  329. {
  330. //写日志
  331. return COMMON_INVALID_HANDLE;
  332. }
  333. return pNetInterface->GetReportListOfCase(stringLocalFilePath, stringCaseId);
  334. }
  335. int GetHospitalListOfGroup(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringGroupId, const char* stringType, const char* stringCaseType, unsigned int nPageTo, unsigned int nPageSize)
  336. {
  337. if(handle==NULL || stringLocalFilePath==NULL || stringGroupId==NULL || stringType==NULL)
  338. {
  339. return COMMON_PARAMETER_NULL;
  340. }
  341. string stringUuid = handle;
  342. CExternalNetInterface* pNetInterface = NULL;
  343. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  344. if(pNetInterface == NULL)
  345. {
  346. //写日志
  347. return COMMON_INVALID_HANDLE;
  348. }
  349. return pNetInterface->GetHospitalListOfGroup(stringLocalFilePath, stringGroupId, stringType, stringCaseType, nPageTo, nPageSize);
  350. }
  351. int GetDoctorListOfHospital(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringDoctorId, const char* stringCaseType, const char* stringDoctorType, unsigned int nPageTo, unsigned int nPageSize)
  352. {
  353. if(handle==NULL || stringLocalFilePath==NULL || stringHospitalId==NULL || stringDoctorId==NULL)
  354. {
  355. return COMMON_PARAMETER_NULL;
  356. }
  357. string stringUuid = handle;
  358. CExternalNetInterface* pNetInterface = NULL;
  359. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  360. if(pNetInterface == NULL)
  361. {
  362. //写日志
  363. return COMMON_INVALID_HANDLE;
  364. }
  365. return pNetInterface->GetDoctorListOfHospital(stringLocalFilePath, stringHospitalId, stringDoctorId, stringCaseType, stringDoctorType, nPageTo, nPageSize);
  366. }
  367. int AbortSession(NET_HANDLE handle)
  368. {
  369. if(handle==NULL)
  370. {
  371. return COMMON_PARAMETER_NULL;
  372. }
  373. Mutex* pMutex = CHandleMutexManager::GetHandleMutex(handle);
  374. if(pMutex == NULL)
  375. {
  376. return COMMON_INVALID_HANDLE;
  377. }
  378. Mutex::ScopedLock lock(*pMutex);
  379. string stringUuid = handle;
  380. CExternalNetInterface* pNetInterface = NULL;
  381. pNetInterface = CNetThreadManager::GetNetThread(stringUuid, true);
  382. if(pNetInterface == NULL)
  383. {
  384. //写日志
  385. return COMMON_INVALID_HANDLE;
  386. }
  387. return pNetInterface->AbortSession();
  388. }
  389. int GetEventStream(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCaseId, const char* stringOriginalHospital)
  390. {
  391. if(handle==NULL || stringLocalFilePath==NULL || stringCaseId==NULL || stringOriginalHospital==NULL)
  392. {
  393. return COMMON_PARAMETER_NULL;
  394. }
  395. string stringUuid = handle;
  396. CExternalNetInterface* pNetInterface = NULL;
  397. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  398. if(pNetInterface == NULL)
  399. {
  400. //写日志
  401. return COMMON_INVALID_HANDLE;
  402. }
  403. return pNetInterface->GetEventStream(stringLocalFilePath, stringCaseId, stringOriginalHospital);
  404. }
  405. int GetCaseTypeList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLanguage)
  406. {
  407. if(handle==NULL || stringLocalFilePath==NULL || stringLanguage==NULL)
  408. {
  409. return COMMON_PARAMETER_NULL;
  410. }
  411. string stringUuid = handle;
  412. CExternalNetInterface* pNetInterface = NULL;
  413. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  414. if(pNetInterface == NULL)
  415. {
  416. //写日志
  417. return COMMON_INVALID_HANDLE;
  418. }
  419. return pNetInterface->GetCaseTypeList(stringLocalFilePath, stringLanguage);
  420. }
  421. int DownloadPhoto(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback)
  422. {
  423. if(handle==NULL || stringLocalFilePath==NULL || stringUri==NULL)
  424. {
  425. return COMMON_PARAMETER_NULL;
  426. }
  427. string stringUuid = handle;
  428. CExternalNetInterface* pNetInterface = NULL;
  429. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  430. if(pNetInterface == NULL)
  431. {
  432. //写日志
  433. return COMMON_INVALID_HANDLE;
  434. }
  435. return pNetInterface->DownloadPhoto(stringLocalFilePath, stringUri, nFileSize, pCallback);
  436. }
  437. int GetServerFileSize(NET_HANDLE handle, const char* stringUri, int& nFileSize)
  438. {
  439. if(handle==NULL || stringUri==NULL)
  440. {
  441. return COMMON_PARAMETER_NULL;
  442. }
  443. string stringUuid = handle;
  444. CExternalNetInterface* pNetInterface = NULL;
  445. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  446. if(pNetInterface == NULL)
  447. {
  448. //写日志
  449. return COMMON_INVALID_HANDLE;
  450. }
  451. return pNetInterface->GetAlreadyUploadFileSize(stringUri, nFileSize);
  452. }
  453. int SendPhoneMsg(NET_HANDLE handle, const char* stringCardId, const char* stringPhone, const char* stringMsg)
  454. {
  455. if(handle==NULL || stringCardId==NULL || stringPhone==NULL || stringMsg==NULL)
  456. {
  457. return COMMON_PARAMETER_NULL;
  458. }
  459. string stringUuid = handle;
  460. CExternalNetInterface* pNetInterface = NULL;
  461. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  462. if(pNetInterface == NULL)
  463. {
  464. //写日志
  465. return COMMON_INVALID_HANDLE;
  466. }
  467. return pNetInterface->SendPhoneMsg(stringCardId, stringPhone, stringMsg);
  468. }
  469. int GetFileWithHttp(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUrl, int bContinue)
  470. {
  471. if(handle==NULL || stringLocalFilePath==NULL || stringUrl==NULL)
  472. {
  473. return COMMON_PARAMETER_NULL;
  474. }
  475. string stringUuid = handle;
  476. CExternalNetInterface* pNetInterface = NULL;
  477. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  478. if(pNetInterface == NULL)
  479. {
  480. //写日志
  481. return COMMON_INVALID_HANDLE;
  482. }
  483. return pNetInterface->GetFileWithHttp(stringLocalFilePath, stringUrl, bContinue);
  484. }
  485. int PostForm(NET_HANDLE handle, char* stringResponse, unsigned int nResponseSize, const char* stringHost, const char* stringUrl, const char* stringKey[], const char* stringValue[], int nSize)
  486. {
  487. if(handle==NULL || stringResponse==NULL || stringHost==NULL || stringUrl==NULL || stringKey==NULL || stringValue==NULL || nSize==0 || nResponseSize==0)
  488. {
  489. return COMMON_PARAMETER_NULL;
  490. }
  491. map<string, string> mapParams;
  492. for(int i=0; i<nSize; i++)
  493. {
  494. mapParams[stringKey[i]] = stringValue[i];
  495. }
  496. string stringUuid = handle;
  497. CExternalNetInterface* pNetInterface = NULL;
  498. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  499. if(pNetInterface == NULL)
  500. {
  501. //写日志
  502. return COMMON_INVALID_HANDLE;
  503. }
  504. int nRet = PHMS_SUCCESSFUL_RESULT;
  505. string stringTempResponse;
  506. nRet = pNetInterface->PostForm(stringTempResponse, stringHost, stringUrl, mapParams);
  507. if(nRet != PHMS_SUCCESSFUL_RESULT)
  508. {
  509. return nRet;
  510. }
  511. if(stringTempResponse.size() != 0)
  512. {
  513. if(stringTempResponse.size() > nResponseSize)
  514. {
  515. strncpy(stringResponse, stringTempResponse.c_str(), nResponseSize);
  516. }
  517. else
  518. {
  519. strcpy(stringResponse, stringTempResponse.c_str());
  520. }
  521. }
  522. return nRet;
  523. }
  524. int GetVerificationCode(NET_HANDLE handle, const char* stringType, const char* stringPhone)
  525. {
  526. if(handle==NULL || stringType==NULL || stringPhone==NULL)
  527. {
  528. CPhmsLogger::GetPhmsLogger()->WriteLog(handle, __FUNCTION__, __FILE__, __LINE__);
  529. CPhmsLogger::GetPhmsLogger()->WriteLog(stringType, __FUNCTION__, __FILE__, __LINE__);
  530. CPhmsLogger::GetPhmsLogger()->WriteLog(stringPhone, __FUNCTION__, __FILE__, __LINE__);
  531. return COMMON_PARAMETER_NULL;
  532. }
  533. string stringUuid = handle;
  534. CExternalNetInterface* pNetInterface = NULL;
  535. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  536. if(pNetInterface == NULL)
  537. {
  538. //写日志
  539. return COMMON_INVALID_HANDLE;
  540. }
  541. return pNetInterface->GetVerificationCode(stringType, stringPhone);
  542. }
  543. int ApplyQRCode(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringScene)
  544. {
  545. if(handle==NULL || stringLocalFilePath==NULL || stringType==NULL || stringScene==NULL)
  546. {
  547. return COMMON_PARAMETER_NULL;
  548. }
  549. string stringUuid = handle;
  550. CExternalNetInterface* pNetInterface = NULL;
  551. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  552. if(pNetInterface == NULL)
  553. {
  554. //写日志
  555. return COMMON_INVALID_HANDLE;
  556. }
  557. return pNetInterface->ApplyQRCode(stringLocalFilePath, stringType, stringScene);
  558. }
  559. int ValidateUserAccount(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLoginId, const char* stringPassword, const char* stringRole)
  560. {
  561. if(handle==NULL || stringLocalFilePath==NULL || stringLoginId==NULL || stringPassword==NULL || stringRole==NULL)
  562. {
  563. return COMMON_PARAMETER_NULL;
  564. }
  565. string stringUuid = handle;
  566. CExternalNetInterface* pNetInterface = NULL;
  567. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  568. if(pNetInterface == NULL)
  569. {
  570. //写日志
  571. return COMMON_INVALID_HANDLE;
  572. }
  573. return pNetInterface->ValidateUserAccount(stringLocalFilePath, stringLoginId, stringPassword, stringRole);
  574. }
  575. int UploadCommonFile(NET_HANDLE handle, char* stringUri, const char* stringType, const char* stringExtra, const char* stringLocalFilePath, const char* stringFileType, pProgressAndSpeedCallback pCallbcak)
  576. {
  577. if(handle==NULL || stringType==NULL || stringExtra==NULL || stringLocalFilePath==NULL)
  578. {
  579. return COMMON_PARAMETER_NULL;
  580. }
  581. string stringUuid = handle;
  582. CExternalNetInterface* pNetInterface = NULL;
  583. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  584. if(pNetInterface == NULL)
  585. {
  586. //写日志
  587. return COMMON_INVALID_HANDLE;
  588. }
  589. string stringTempUri;
  590. int nRet = pNetInterface->UploadCommonFile(stringTempUri, stringType, stringExtra, stringLocalFilePath, stringFileType, pCallbcak);
  591. if(stringTempUri.size() != 0)
  592. {
  593. strcpy(stringUri, stringTempUri.c_str());
  594. }
  595. return nRet;
  596. }
  597. int GetListOfHealthyKnowledge(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringSenderId, const char* stringNextId, const char* stringIds, const char* stringPageSize, const char* stringOrderBy)
  598. {
  599. if(handle==NULL || stringSenderId==NULL || stringNextId==NULL || stringIds==NULL || stringLocalFilePath==NULL || stringPageSize==NULL || stringOrderBy==NULL)
  600. {
  601. return COMMON_PARAMETER_NULL;
  602. }
  603. string stringUuid = handle;
  604. CExternalNetInterface* pNetInterface = NULL;
  605. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  606. if(pNetInterface == NULL)
  607. {
  608. //写日志
  609. return COMMON_INVALID_HANDLE;
  610. }
  611. return pNetInterface->GetListOfHealthyKnowledge(stringLocalFilePath, stringSenderId, stringNextId, stringIds, stringPageSize, stringOrderBy);
  612. }
  613. int GetCardUserReportList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringReportId, const char* stringReportStartDate, const char* stringReportEndDate, const char* stringCaseType, const char* stringState, const char* stringOrderBy,
  614. const char* stringThirdIdType, const char* stringThirdId, const char* stringNextId, const char* stringPageSize)
  615. {
  616. if(handle==NULL || stringLocalFilePath==NULL || stringReportId==NULL || stringReportStartDate==NULL || stringReportEndDate==NULL || stringCaseType==NULL || stringState==NULL || stringOrderBy==NULL ||
  617. stringThirdIdType==NULL || stringThirdId==NULL || stringNextId==NULL || stringPageSize==NULL)
  618. {
  619. return COMMON_PARAMETER_NULL;
  620. }
  621. string stringUuid = handle;
  622. CExternalNetInterface* pNetInterface = NULL;
  623. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  624. if(pNetInterface == NULL)
  625. {
  626. //写日志
  627. return COMMON_INVALID_HANDLE;
  628. }
  629. return pNetInterface->GetCardUserReportList(stringLocalFilePath, stringReportId, stringReportStartDate, stringReportEndDate, stringCaseType, stringState, stringOrderBy, stringThirdIdType, stringThirdId, stringNextId, stringPageSize);
  630. }
  631. int MyFans(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUserId, const char* stringNextId)
  632. {
  633. if(handle==NULL || stringLocalFilePath==NULL || stringUserId==NULL || stringNextId==NULL)
  634. {
  635. return COMMON_PARAMETER_NULL;
  636. }
  637. string stringUuid = handle;
  638. CExternalNetInterface* pNetInterface = NULL;
  639. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  640. if(pNetInterface == NULL)
  641. {
  642. //写日志
  643. return COMMON_INVALID_HANDLE;
  644. }
  645. return pNetInterface->MyFans(stringLocalFilePath, stringUserId, stringNextId);
  646. }
  647. int GetPayCode(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringCaseId)
  648. {
  649. if(handle==NULL || stringLocalFilePath==NULL || stringType==NULL || stringCaseId==NULL)
  650. {
  651. return COMMON_PARAMETER_NULL;
  652. }
  653. string stringUuid = handle;
  654. CExternalNetInterface* pNetInterface = NULL;
  655. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  656. if(pNetInterface == NULL)
  657. {
  658. //写日志
  659. return COMMON_INVALID_HANDLE;
  660. }
  661. return pNetInterface->GetPayCode(stringLocalFilePath, stringType, stringCaseId);
  662. }
  663. int GetOrderInfo(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringCaseId)
  664. {
  665. if(handle==NULL || stringLocalFilePath==NULL || stringType==NULL || stringCaseId==NULL)
  666. {
  667. return COMMON_PARAMETER_NULL;
  668. }
  669. string stringUuid = handle;
  670. CExternalNetInterface* pNetInterface = NULL;
  671. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  672. if(pNetInterface == NULL)
  673. {
  674. //写日志
  675. return COMMON_INVALID_HANDLE;
  676. }
  677. return pNetInterface->GetOrderInfo(stringLocalFilePath, stringType, stringCaseId);
  678. }
  679. int AbortSessionByThreadId(THREAD_ID threadId)
  680. {
  681. #if(POCO_OS == POCO_OS_MAC_OS_X)
  682. return PHMS_SUCCESSFUL_RESULT;
  683. #else
  684. string handle = CNetThreadManager::GetHandleByThreadId(threadId);
  685. if(handle.size() == 0)
  686. {
  687. return COMMON_INVALID_THREAD_ID;
  688. }
  689. return AbortSession((char*)handle.c_str());
  690. #endif
  691. }
  692. NET_HANDLE NET_API BeginMsgListPush(const char* stringSenderId, const char* stringCaseId, const char* stringCaseType, const char* stringMsgType, const char* stringMsgDirection, const char* stringVersion,
  693. pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback)
  694. {
  695. CAllObjectManagerUtil::InitializeSSL();
  696. CAllObjectManagerUtil::InitializeLocale();
  697. //初始化日志对象Logger
  698. string stringUuid;
  699. try
  700. {
  701. CPhmsLogger::GetPhmsLogger();
  702. }
  703. catch(Exception& error)
  704. {
  705. CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
  706. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_GENERATE_LOG_FILE_ERROR), __FUNCTION__, __FILE__, __LINE__);
  707. return NULL;
  708. }
  709. if(stringSenderId==NULL || stringCaseId==NULL || stringCaseType==NULL || stringMsgType==NULL ||stringMsgDirection==NULL ||
  710. pCallback==NULL || pFailCallback==NULL)
  711. {
  712. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PARAMETER_NULL), __FUNCTION__, __FILE__, __LINE__);
  713. return NULL;
  714. }
  715. if(g_stringTerminalType.size() == 0)
  716. {
  717. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_SET_TERMINAL_TYPE), __FUNCTION__, __FILE__, __LINE__);
  718. return NULL;
  719. }
  720. if(CPushObjectManager::SomeTypePushIsRun(MSG_LIST_PUSH))
  721. {
  722. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SAME_PUSH_IS_RUN), __FUNCTION__, __FILE__, __LINE__);
  723. return NULL;
  724. }
  725. stringUuid = UUIDGenerator::defaultGenerator().createOne().toString();
  726. int nRet = PHMS_SUCCESSFUL_RESULT;
  727. nRet = CPushObjectManager::InsertPushMsgListObject(stringUuid, stringSenderId, stringCaseId, stringCaseType, stringMsgType, stringMsgDirection, stringVersion, pCallback, pFailCallback);
  728. if(nRet != PHMS_SUCCESSFUL_RESULT)
  729. {
  730. return NULL;
  731. }
  732. NET_HANDLE handle = new char[128];
  733. memset(handle, 0, 128);
  734. strcpy(handle, stringUuid.c_str());
  735. return handle;
  736. }
  737. int NET_API EndPush(NET_HANDLE handle)
  738. {
  739. if(handle == NULL)
  740. {
  741. return COMMON_PARAMETER_NULL;
  742. }
  743. string stringUuid = handle;
  744. int nRet = PHMS_SUCCESSFUL_RESULT;
  745. nRet = CPushObjectManager::DeletePushObject(stringUuid);
  746. if(nRet == PHMS_SUCCESSFUL_RESULT)
  747. {
  748. CAllObjectManagerUtil::UnInitializeSSL();
  749. CAllObjectManagerUtil::UnInitializeLocale();
  750. delete handle;
  751. }
  752. CAllObjectManagerUtil::ReleasePhmsLogger();
  753. return nRet;
  754. }
  755. int ExecuteGWService(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLastPath, const char* stringJson, const char* stringUploadFilePath)
  756. {
  757. if(handle==NULL || stringLocalFilePath==NULL || stringLastPath==NULL || stringJson==NULL || stringUploadFilePath==NULL)
  758. {
  759. return COMMON_PARAMETER_NULL;
  760. }
  761. string stringUuid = handle;
  762. CExternalNetInterface* pNetInterface = NULL;
  763. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  764. if(pNetInterface == NULL)
  765. {
  766. //写日志
  767. return COMMON_INVALID_HANDLE;
  768. }
  769. return pNetInterface->ExecuteGWService(stringLocalFilePath, stringLastPath, stringJson, stringUploadFilePath);
  770. }
  771. int ExecuteCommonRESTful(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringIp, const char* stringPort, const char* stringUrl, const char* stringContentType, const char* stringPayload)
  772. {
  773. if(handle==NULL || stringLocalFilePath==NULL || stringIp==NULL || stringPort==NULL || stringUrl==NULL || stringContentType==NULL || stringPayload==NULL)
  774. {
  775. return COMMON_PARAMETER_NULL;
  776. }
  777. string stringUuid = handle;
  778. CExternalNetInterface* pNetInterface = NULL;
  779. pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
  780. if(pNetInterface == NULL)
  781. {
  782. //写日志
  783. return COMMON_INVALID_HANDLE;
  784. }
  785. return pNetInterface->ExecuteCommonRESTful(stringLocalFilePath, stringIp, stringPort, stringUrl, stringContentType, stringPayload);
  786. }