SATHTTP.cpp 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. // SATHTTP.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include "SATHTTP.h"
  5. #include <direct.h>
  6. CCurlClient g_curl;
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. __if_not_exists(NotifyJobStart)
  11. {
  12. int NotifyJobStart(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp) throw()
  13. {
  14. return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
  15. }
  16. }
  17. __if_not_exists(ProcessJob)
  18. {
  19. int ProcessJob(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp) throw()
  20. {
  21. return SetResultList(url, stJobProcessReq, stJobProcessResp);
  22. }
  23. }
  24. #define SETLOG GLOBAL::WriteTextLog("<======请求失败======> \r接口名称:%s \r错误码值:%ld \r请求内容:%s \r返回内容:%s", __FUNCDNAME__, curlCode, post_data.c_str(), reponse.c_str())
  25. #ifdef __CONSOLE__
  26. // 唯一的应用程序对象
  27. CWinApp theApp;
  28. using namespace std;
  29. bool MKDIR(LPCTSTR dir);
  30. __if_not_exists(NotifyJobStart)
  31. {
  32. int NotifyJobStart(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp) throw()
  33. {
  34. return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
  35. }
  36. }
  37. __if_not_exists(ProcessJob)
  38. {
  39. int ProcessJob(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp) throw()
  40. {
  41. return SetResultList(url, stJobProcessReq, stJobProcessResp);
  42. }
  43. }
  44. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  45. {
  46. int nRetCode = 0;
  47. // 初始化 MFC 并在失败时显示错误
  48. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  49. {
  50. // TODO: 更改错误代码以符合您的需要
  51. _tprintf(_T("错误: MFC 初始化失败\n"));
  52. nRetCode = 1;
  53. }
  54. else
  55. {
  56. UrlPars ups;
  57. std::string host = "10.118.159.132:8580/btc_task_se/downLoadFile!downLoadFile.action?fileDir=/RT_2841/预抄写_RT2841/DVB&fileName=A5600007AAB_DVB_DTV_EPG.py";
  58. CCurlClient::ParseURL(host, ups);
  59. for ( std::map<std::string,std::string>::iterator it = ups.pars.begin(); it != ups.pars.end(); it++ ) {
  60. it->second = CharEncoding::EnCode_UTF8URL(it->second.c_str());
  61. }
  62. printf("----\n");
  63. }
  64. system("pause");
  65. return nRetCode;
  66. }
  67. #endif //__CONSOLE__
  68. bool MKDIR(LPCTSTR dir)
  69. {
  70. //////////////////////////////////////////////////////////////////////////
  71. // 创建目录;
  72. int nleft = 0;
  73. int nIndex = -1;
  74. std::string strdir = dir;
  75. strdir = strdir.substr(0, strdir.find_last_of(_T("\\")));
  76. if (strdir.at(strdir.size() - 1) != _T('\\'))
  77. strdir.append(_T("\\"));
  78. // 共享路径和硬盘盘符;
  79. if (_tcscmp(strdir.substr(0, 2).c_str(), _T("\\\\")) == 0)
  80. nleft = strdir.find_first_of(_T("\\"), 2) + 1; // 去除共享主机名;
  81. else if (strdir.at(2) == _T('\\'))
  82. nleft = 3;
  83. do
  84. {
  85. nIndex = strdir.substr(nleft, -1).find_first_of(_T("\\"));
  86. if (nIndex != string::npos)
  87. {
  88. if (_mkdir(strdir.substr(0, nIndex + nleft).c_str()) == -1 && (errno != EEXIST))
  89. {
  90. return false;
  91. }
  92. nleft += nIndex + 1;
  93. }
  94. } while (nIndex != -1);
  95. return true;
  96. };
  97. SATHTTP_API int Login(std::string url, const SATHTTP::STLoginReq &stLoginReq, SATHTTP::STLoginResp &stLoginResp)
  98. {
  99. if ( !g_curl.IsInit() )
  100. g_curl.Initialize();
  101. // 转化为Json;
  102. cJSON *pRoot = cJSON_CreateObject();
  103. if ( pRoot == NULL )
  104. {
  105. return -1;
  106. }
  107. cJSON_AddStringToObject(pRoot, "function", "aaaa");
  108. cJSON_AddStringToObject(pRoot, "sysCode", "EXECUTE");
  109. cJSON *pData = cJSON_CreateObject();
  110. if ( pData )
  111. {
  112. // 添加到根结点中;
  113. cJSON_AddItemToObject(pRoot, "data", pData);
  114. cJSON_AddStringToObject(pData, "userName", stLoginReq.strUserName.c_str());
  115. cJSON_AddStringToObject(pData, "status", stLoginReq.strStatus.c_str());
  116. cJSON_AddStringToObject(pData, "deleteStatus", stLoginReq.strDeleteStatus.c_str());
  117. cJSON_AddStringToObject(pData, "ip", stLoginReq.strIP.c_str());
  118. cJSON_AddStringToObject(pData, "memory", stLoginReq.strMemory.c_str());
  119. cJSON_AddStringToObject(pData, "storage", stLoginReq.strStorage.c_str());
  120. cJSON_AddStringToObject(pData, "connectTime", stLoginReq.strConnectTime.c_str());
  121. cJSON_AddStringToObject(pData, "executeName", stLoginReq.strExecuteName.c_str());
  122. cJSON_AddStringToObject(pData, "mac", stLoginReq.strMAC.c_str());
  123. cJSON_AddStringToObject(pData, "disconnectTime", stLoginReq.strDisconnectTime.c_str());
  124. cJSON_AddStringToObject(pData, "password", stLoginReq.strPassword.c_str());
  125. cJSON_AddStringToObject(pData, "cpu", stLoginReq.strCPU.c_str());
  126. }
  127. char *pText = cJSON_Print(pRoot);
  128. std::string post_data = "requestMsg=";
  129. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  130. // 释放堆内存;
  131. if (pText)
  132. delete pText;
  133. pText = NULL;
  134. if ( pRoot )
  135. cJSON_Delete(pRoot);
  136. pRoot = NULL;
  137. std::string reponse;
  138. CURLcode curlCode = CURLE_OK;
  139. if ( g_curl.IsInit() )
  140. {
  141. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  142. curlCode = g_curl.Posts(url, post_data, reponse);
  143. else
  144. curlCode = g_curl.Post(url, post_data, reponse);
  145. if ( curlCode == CURLE_OK )
  146. {
  147. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  148. // 解析返回值;
  149. pRoot = cJSON_Parse(reponse.c_str());
  150. if (pRoot != NULL)
  151. {
  152. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  153. if ( pMsg )
  154. {
  155. stLoginResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  156. stLoginResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  157. stLoginResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  158. if ( stLoginResp.strCode == "00" )
  159. {
  160. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  161. if (pObj != NULL)
  162. {
  163. stLoginResp.nPortCount = cJSON_GetObjectItem(pObj, "portCount") ? cJSON_GetObjectItem(pObj, "portCount")->valueint : -1;
  164. stLoginResp.nCompanyId = cJSON_GetObjectItem(pObj, "companyId") ? cJSON_GetObjectItem(pObj, "companyId")->valueint : -1;
  165. stLoginResp.strRunnerToken = cJSON_GetObjectItem(pObj, "runnerToken") ? cJSON_GetObjectItem(pObj, "runnerToken")->valuestring : "";
  166. }
  167. // 释放内存;
  168. cJSON_Delete(pRoot);
  169. // 返回结果;
  170. return TRUE;
  171. }
  172. }
  173. // 错误产生,可输出msg方便查询;
  174. cJSON_Delete(pRoot);
  175. }
  176. }
  177. }
  178. SETLOG;
  179. return FALSE;
  180. }
  181. SATHTTP_API int UpdateDeviceMessage(std::string url, const SATHTTP::STUpdateDeviceReq &stUpdateDeviceReq, SATHTTP::STUpdateDeviceResp &stUpdateDeviceResp)
  182. {
  183. // 转化为Json;
  184. cJSON *pRoot = cJSON_CreateObject();
  185. if ( pRoot == NULL )
  186. {
  187. return -1;
  188. }
  189. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  190. cJSON *pData = cJSON_CreateObject();
  191. if ( pData )
  192. {
  193. cJSON_AddStringToObject(pData, "status", stUpdateDeviceReq.strStatus.c_str());
  194. cJSON_AddStringToObject(pData, "userName", stUpdateDeviceReq.strUserName.c_str());
  195. cJSON_AddStringToObject(pData, "ip", stUpdateDeviceReq.strIP.c_str());
  196. cJSON_AddStringToObject(pData, "storage", stUpdateDeviceReq.strStorage.c_str());
  197. cJSON_AddStringToObject(pData, "runnerName", stUpdateDeviceReq.strRunnerName.c_str());
  198. cJSON_AddStringToObject(pData, "mac", stUpdateDeviceReq.strMAC.c_str());
  199. cJSON_AddStringToObject(pData, "reportType", stUpdateDeviceReq.strReportType.c_str());
  200. cJSON_AddStringToObject(pData, "startTime", stUpdateDeviceReq.strStartTime.c_str());
  201. cJSON_AddStringToObject(pData, "memory", stUpdateDeviceReq.strMemory.c_str());
  202. cJSON_AddStringToObject(pData, "endTime", stUpdateDeviceReq.strEndTime.c_str());
  203. cJSON_AddStringToObject(pData, "cpu", stUpdateDeviceReq.strCPU.c_str());
  204. cJSON *pDeviceList = cJSON_CreateArray();
  205. if ( pDeviceList )
  206. {
  207. cJSON_AddItemToObject(pData, "devicelist", pDeviceList);
  208. for ( std::vector<SATHTTP::STDevice>::const_iterator it = stUpdateDeviceReq.devicelist.begin(); it != stUpdateDeviceReq.devicelist.end(); it++ )
  209. {
  210. cJSON *pObj = cJSON_CreateObject();
  211. if ( pObj )
  212. {
  213. cJSON_AddStringToObject(pObj, "status", it->strStatus.c_str());
  214. cJSON_AddStringToObject(pObj, "deviceSerial", it->strDeviceSerial.c_str());
  215. cJSON_AddStringToObject(pObj, "hardwareVersion", it->strHardwareVersion.c_str());
  216. cJSON_AddStringToObject(pObj, "manu", it->strManu.c_str());
  217. cJSON_AddStringToObject(pObj, "deviceMac", it->strDeviceMac.c_str());
  218. cJSON_AddStringToObject(pObj, "lastJobStartTime", it->strLastJobStartTime.c_str());
  219. cJSON_AddStringToObject(pObj, "lastTimeBreak", it->strLastTimeBreak.c_str());
  220. cJSON_AddStringToObject(pObj, "comments", it->strComments.c_str());
  221. cJSON_AddStringToObject(pObj, "cpu", it->strCPU.c_str());
  222. cJSON_AddStringToObject(pObj, "softwareVersion", it->strSoftwareVersion.c_str());
  223. cJSON_AddStringToObject(pObj, "phoneNumber", it->strPhoneNumber.c_str());
  224. cJSON_AddStringToObject(pObj, "lastJobFinishTime", it->strLastJobFinishTime.c_str());
  225. cJSON_AddStringToObject(pObj, "memory", it->strMemory.c_str());
  226. cJSON_AddStringToObject(pObj, "model", it->strModel.c_str());
  227. cJSON_AddStringToObject(pObj, "lastJob", it->strLastJob.c_str());
  228. cJSON_AddStringToObject(pObj, "lastTimeConnected", it->strLastTimeConnected.c_str());
  229. cJSON_AddStringToObject(pObj, "electric", it->strElectric.c_str());
  230. cJSON_AddItemToObject(pDeviceList, "", pObj);
  231. }
  232. }
  233. }
  234. // 添加到根结点中;
  235. cJSON_AddItemToObject(pRoot, "data", pData);
  236. }
  237. char *pText = cJSON_Print(pRoot);
  238. std::string post_data = "requestMsg=";
  239. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  240. // 释放堆内存;
  241. if (pText)
  242. delete pText;
  243. pText = NULL;
  244. if ( pRoot )
  245. cJSON_Delete(pRoot);
  246. pRoot = NULL;
  247. std::string reponse;
  248. CURLcode curlCode = CURLE_OK;
  249. if ( g_curl.IsInit() )
  250. {
  251. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  252. curlCode = g_curl.Posts(url, post_data, reponse);
  253. else
  254. curlCode = g_curl.Post(url, post_data, reponse);
  255. if ( curlCode == CURLE_OK )
  256. {
  257. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  258. // 解析返回值;
  259. pRoot = cJSON_Parse(reponse.c_str());
  260. if (pRoot != NULL)
  261. {
  262. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  263. if ( pMsg )
  264. {
  265. stUpdateDeviceResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  266. stUpdateDeviceResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  267. stUpdateDeviceResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  268. if ( stUpdateDeviceResp.strCode == "00" )
  269. {
  270. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  271. if (pObj != NULL)
  272. {
  273. }
  274. // 释放内存;
  275. cJSON_Delete(pRoot);
  276. // 返回结果;
  277. return TRUE;
  278. }
  279. }
  280. // 错误产生,可输出msg方便查询;
  281. cJSON_Delete(pRoot);
  282. }
  283. }
  284. }
  285. SETLOG;
  286. return FALSE;
  287. }
  288. SATHTTP_API int Heartbeat(std::string url, const SATHTTP::STHeartbeatReq &stHeartbeatReq, SATHTTP::STHeartbeatResp &stHeartbeatResp)
  289. {
  290. // 转化为Json;
  291. cJSON *pRoot = cJSON_CreateObject();
  292. if ( pRoot == NULL )
  293. {
  294. return -1;
  295. }
  296. cJSON_AddStringToObject(pRoot, "sysCode", "EXECUTE");
  297. cJSON *pData = cJSON_CreateObject();
  298. if ( pData )
  299. {
  300. cJSON_AddStringToObject(pData, "userName", stHeartbeatReq.strUserName.c_str());
  301. cJSON_AddStringToObject(pData, "runnerMac", stHeartbeatReq.strRunnerMac.c_str());
  302. cJSON *pDeviceList = cJSON_CreateArray();
  303. if ( pDeviceList )
  304. {
  305. cJSON_AddItemToObject(pData, "deviceList", pDeviceList);
  306. for ( std::vector<SATHTTP::STDevice>::const_iterator it = stHeartbeatReq.devicelist.begin(); it != stHeartbeatReq.devicelist.end(); it++ )
  307. {
  308. cJSON *pObj = cJSON_CreateObject();
  309. if ( pObj )
  310. {
  311. cJSON_AddStringToObject(pObj, "status", it->strStatus.c_str());
  312. cJSON_AddStringToObject(pObj, "deviceSerial", it->strDeviceSerial.c_str());
  313. cJSON_AddItemToObject(pDeviceList, "", pObj);
  314. }
  315. }
  316. }
  317. // 添加到根结点中;
  318. cJSON_AddItemToObject(pRoot, "data", pData);
  319. }
  320. char *pText = cJSON_Print(pRoot);
  321. std::string post_data = "requestMsg=";
  322. #if 1
  323. std::string log = "查询参数:requestMsg=";
  324. log.append(pText);
  325. log.append(_T("\n"));
  326. OutputDebugString(log.c_str());
  327. #endif
  328. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  329. // 释放堆内存;
  330. if (pText)
  331. delete pText;
  332. pText = NULL;
  333. if ( pRoot )
  334. cJSON_Delete(pRoot);
  335. pRoot = NULL;
  336. std::string reponse;
  337. CURLcode curlCode = CURLE_OK;
  338. if ( g_curl.IsInit() )
  339. {
  340. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  341. curlCode = g_curl.Posts(url, post_data, reponse);
  342. else
  343. curlCode = g_curl.Post(url, post_data, reponse);
  344. if ( curlCode == CURLE_OK )
  345. {
  346. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  347. #if 1
  348. std::string log = "结果参数:";
  349. log.append(reponse+_T("\n"));
  350. OutputDebugString(reponse.c_str());
  351. #endif
  352. // 解析返回值;
  353. pRoot = cJSON_Parse(reponse.c_str());
  354. if (pRoot != NULL)
  355. {
  356. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  357. if ( pMsg )
  358. {
  359. stHeartbeatResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  360. stHeartbeatResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  361. stHeartbeatResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  362. if ( stHeartbeatResp.strCode == "00" )
  363. {
  364. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  365. if (pObj != NULL)
  366. {
  367. GLOBAL::WriteTextLog("<======heartbeat json======> \r 请求内容:%s \r返回内容:%s", post_data.c_str(), reponse.c_str());
  368. int nSise = cJSON_GetArraySize(pObj);
  369. for ( int i = 0; i < nSise; i++ )
  370. {
  371. cJSON *pTask = cJSON_GetArrayItem(pObj, i);
  372. if ( pTask )
  373. {
  374. SATHTTP::STTask stTask;
  375. stTask.taskInfo.strInstanceName = cJSON_GetObjectItem(pTask, "instanceName") ? cJSON_GetObjectItem(pTask, "instanceName")->valuestring : "";
  376. stTask.taskInfo.strExecutionStatus = cJSON_GetObjectItem(pTask, "executionStatus") ? cJSON_GetObjectItem(pTask, "executionStatus")->valuestring : "";
  377. stTask.taskInfo.strInstanceType = cJSON_GetObjectItem(pTask, "instanceType") ? cJSON_GetObjectItem(pTask, "instanceType")->valuestring : "";
  378. stTask.taskInfo.nExecuteId = cJSON_GetObjectItem(pTask, "executeId") ? cJSON_GetObjectItem(pTask, "executeId")->valueint : -1;
  379. stTask.taskInfo.strRequestIP = cJSON_GetObjectItem(pTask, "requestIp") ? cJSON_GetObjectItem(pTask, "requestIp")->valuestring : "";
  380. stTask.taskInfo.strTaskUseType = cJSON_GetObjectItem(pTask, "taskUseType") ? cJSON_GetObjectItem(pTask, "taskUseType")->valuestring : "";
  381. stTask.taskInfo.nDeviceId = cJSON_GetObjectItem(pTask, "deviceId") ? cJSON_GetObjectItem(pTask, "deviceId")->valueint : -1;
  382. stTask.taskInfo.strDiffTaskInstanceFlag = cJSON_GetObjectItem(pTask, "diffTaskInstanceFlag") ? cJSON_GetObjectItem(pTask, "diffTaskInstanceFlag")->valuestring : "";
  383. stTask.taskInfo.strTaskType = cJSON_GetObjectItem(pTask, "taskType") ? cJSON_GetObjectItem(pTask, "taskType")->valuestring : "";
  384. stTask.taskInfo.nInstanceId = cJSON_GetObjectItem(pTask, "instanceId") ? cJSON_GetObjectItem(pTask, "instanceId")->valueint : -1;
  385. stTask.taskInfo.strProgress = cJSON_GetObjectItem(pTask, "progress") ? cJSON_GetObjectItem(pTask, "progress")->valuestring : "";
  386. stTask.taskInfo.strStartTime = cJSON_GetObjectItem(pTask, "startTime") ? cJSON_GetObjectItem(pTask, "startTime")->valuestring : "";
  387. stTask.taskInfo.strStopTime = cJSON_GetObjectItem(pTask, "stopTime") ? cJSON_GetObjectItem(pTask, "stopTime")->valuestring : "";
  388. stTask.taskInfo.strTaskName = cJSON_GetObjectItem(pTask, "taskName") ? cJSON_GetObjectItem(pTask, "taskName")->valuestring : "";
  389. stTask.taskInfo.Id = cJSON_GetObjectItem(pTask, "id") ? cJSON_GetObjectItem(pTask, "id")->valueint : -1;
  390. stTask.taskInfo.fd = cJSON_GetObjectItem(pTask, "fd") ? cJSON_GetObjectItem(pTask, "fd")->valueint : -1;
  391. stTask.taskInfo.nTaskId = cJSON_GetObjectItem(pTask, "taskId") ? cJSON_GetObjectItem(pTask, "taskId")->valueint : -1;
  392. //stTask.taskInfo.strTaskId = cJSON_GetObjectItem(pTask, "taskId") ? cJSON_GetObjectItem(pTask, "taskId")->valuestring : "0";
  393. // email其实可忽略;
  394. cJSON *pEmals = cJSON_GetObjectItem(pTask, "emails");
  395. if ( pEmals )
  396. {
  397. int nEmailSize = cJSON_GetArraySize(pEmals);
  398. for ( int ii = 0; ii < nEmailSize; ii++ )
  399. {
  400. cJSON *pEmail = cJSON_GetArrayItem(pEmals, ii);
  401. if ( pEmail )
  402. {
  403. std::string email = pEmail->valuestring;
  404. stTask.taskInfo.vtEmails.push_back(email);
  405. }
  406. }
  407. }
  408. cJSON *pSomkingCycle = cJSON_GetObjectItem(pTask, "SomkingCycle");
  409. if ( pSomkingCycle ) {
  410. // 冒烟任务周期;
  411. stTask.taskInfo.stSomkingCycle.nType = cJSON_GetObjectItem(pSomkingCycle, "type")->valueint;
  412. stTask.taskInfo.stSomkingCycle.nWeek = cJSON_GetObjectItem(pSomkingCycle, "week")->valueint;
  413. stTask.taskInfo.stSomkingCycle.nDay = cJSON_GetObjectItem(pSomkingCycle, "day")->valueint;
  414. stTask.taskInfo.stSomkingCycle.strTime = cJSON_GetObjectItem(pSomkingCycle, "time")->valuestring;
  415. }
  416. // Job内容;
  417. cJSON *pJob = cJSON_GetObjectItem(pTask, "taskJson");
  418. if ( pJob )
  419. {
  420. pJob = cJSON_GetObjectItem(pJob, "job");
  421. if ( pJob )
  422. {
  423. stTask.Job.strCloudPort = cJSON_GetObjectItem(pJob, "cloudPort") ? cJSON_GetObjectItem(pJob, "cloudPort")->valuestring : "";
  424. stTask.Job.strExecuteIP = cJSON_GetObjectItem(pJob, "executeIp") ? cJSON_GetObjectItem(pJob, "executeIp")->valuestring : "";
  425. stTask.Job.strMonkeyPctSysKeys = cJSON_GetObjectItem(pJob, "monkeyPctSyskeys") ? cJSON_GetObjectItem(pJob, "monkeyPctSyskeys")->valuestring : "";
  426. stTask.Job.strRedRatDeviceName = cJSON_GetObjectItem(pJob, "redRatDeviceName") ? cJSON_GetObjectItem(pJob, "redRatDeviceName")->valuestring : "";
  427. stTask.Job.strExecuteId = cJSON_GetObjectItem(pJob, "executeId") ? cJSON_GetObjectItem(pJob, "executeId")->valuestring : "";
  428. stTask.Job.strMonkeyPctAppSwitch = cJSON_GetObjectItem(pJob, "monkeyPctAppswitch") ? cJSON_GetObjectItem(pJob, "monkeyPctAppswitch")->valuestring : "";
  429. stTask.Job.strDeviceId = cJSON_GetObjectItem(pJob, "deviceId") ? cJSON_GetObjectItem(pJob, "deviceId")->valuestring : "";
  430. stTask.Job.strLoopNumber = cJSON_GetObjectItem(pJob, "loopNumber") ? cJSON_GetObjectItem(pJob, "loopNumber")->valuestring : "";
  431. stTask.Job.strTaskType = cJSON_GetObjectItem(pJob, "taskType") ? cJSON_GetObjectItem(pJob, "taskType")->valuestring : "";
  432. stTask.Job.strMonkeyFrequency = cJSON_GetObjectItem(pJob, "monkeyFrequency") ? cJSON_GetObjectItem(pJob, "monkeyFrequency")->valuestring : "";
  433. stTask.Job.strCloudVersion = cJSON_GetObjectItem(pJob, "cloudVersion") ? cJSON_GetObjectItem(pJob, "cloudVersion")->valuestring : "";
  434. stTask.Job.strTaskInstanceName = cJSON_GetObjectItem(pJob, "taskInstanceName") ? cJSON_GetObjectItem(pJob, "taskInstanceName")->valuestring : "";
  435. stTask.Job.strRepeatRunTime = cJSON_GetObjectItem(pJob, "repeatRunTime") ? cJSON_GetObjectItem(pJob, "repeatRunTime")->valuestring : "";
  436. stTask.Job.strMonkeyTime = cJSON_GetObjectItem(pJob, "monkeyTime") ? cJSON_GetObjectItem(pJob, "monkeyTime")->valuestring : "";
  437. stTask.Job.strOutEquipmentId = cJSON_GetObjectItem(pJob, "outEquipmentId") ? cJSON_GetObjectItem(pJob, "outEquipmentId")->valuestring : "";
  438. stTask.Job.strPoweroff = cJSON_GetObjectItem(pJob, "poweroff") ? cJSON_GetObjectItem(pJob, "poweroff")->valuestring : "";
  439. stTask.Job.strFilePath = cJSON_GetObjectItem(pJob, "filePath") ? cJSON_GetObjectItem(pJob, "filePath")->valuestring : "";
  440. stTask.Job.strScriptFailRepeart = cJSON_GetObjectItem(pJob, "scriptFailRepeat") ? cJSON_GetObjectItem(pJob, "scriptFailRepeat")->valuestring : "";
  441. stTask.Job.strTaskInstanceId = cJSON_GetObjectItem(pJob, "taskInstanceId") ? cJSON_GetObjectItem(pJob, "taskInstanceId")->valuestring : "";
  442. stTask.Job.strUserId = cJSON_GetObjectItem(pJob, "userId") ? cJSON_GetObjectItem(pJob, "userId")->valuestring : "";
  443. stTask.Job.strDiffTaskInstanceFlag = cJSON_GetObjectItem(pJob, "diffTaskInstanceFlag") ? cJSON_GetObjectItem(pJob, "diffTaskInstanceFlag")->valuestring : "";
  444. stTask.Job.strBusCode = cJSON_GetObjectItem(pJob, "busCode") ? cJSON_GetObjectItem(pJob, "busCode")->valuestring : "";
  445. stTask.Job.strRound = cJSON_GetObjectItem(pJob, "round") ? cJSON_GetObjectItem(pJob, "round")->valuestring : "";
  446. stTask.Job.strControlType = cJSON_GetObjectItem(pJob, "controlType") ? cJSON_GetObjectItem(pJob, "controlType")->valuestring : "";
  447. stTask.Job.strMonkeyPctMajornav = cJSON_GetObjectItem(pJob, "monkeyPctMajornav") ? cJSON_GetObjectItem(pJob, "monkeyPctMajornav")->valuestring : "";
  448. stTask.Job.strTaskName = cJSON_GetObjectItem(pJob, "taskName") ? cJSON_GetObjectItem(pJob, "taskName")->valuestring : "";
  449. stTask.Job.strMonkeyType = cJSON_GetObjectItem(pJob, "monkeyType") ? cJSON_GetObjectItem(pJob, "monkeyType")->valuestring : "";
  450. stTask.Job.strMonkeyDictate = cJSON_GetObjectItem(pJob, "monkeyDictate") ? cJSON_GetObjectItem(pJob, "monkeyDictate")->valuestring : "";
  451. stTask.Job.strDetectedDeviceName = cJSON_GetObjectItem(pJob, "detectedDeviceName") ? cJSON_GetObjectItem(pJob, "detectedDeviceName")->valuestring : "";
  452. stTask.Job.strExecuteName = cJSON_GetObjectItem(pJob, "executeName") ? cJSON_GetObjectItem(pJob, "executeName")->valuestring : "";
  453. stTask.Job.strProjectName = cJSON_GetObjectItem(pJob, "projectName") ? cJSON_GetObjectItem(pJob, "projectName")->valuestring : "";
  454. stTask.Job.strProjectId = cJSON_GetObjectItem(pJob, "projectId") ? cJSON_GetObjectItem(pJob, "projectId")->valuestring : "";
  455. stTask.Job.strUniqueId = cJSON_GetObjectItem(pJob, "uniqueId") ? cJSON_GetObjectItem(pJob, "uniqueId")->valuestring : "";
  456. stTask.Job.strTaskId = cJSON_GetObjectItem(pJob, "taskId") ? cJSON_GetObjectItem(pJob, "taskId")->valuestring : "";
  457. stTask.Job.strSoftwareVersion = cJSON_GetObjectItem(pJob, "softwareVersion") ? cJSON_GetObjectItem(pJob, "softwareVersion")->valuestring : "";
  458. stTask.Job.strMonkeyPctNav = cJSON_GetObjectItem(pJob, "monkeyPctNav") ? cJSON_GetObjectItem(pJob, "monkeyPctNav")->valuestring : "";
  459. // emails,已重复,忽略;
  460. // cJSON *pEmals = cJSON_GetObjectItem(pJob, "emails");
  461. // case list;
  462. cJSON *pCaseList = cJSON_GetObjectItem(pJob, "caseList");
  463. if ( pCaseList )
  464. {
  465. int nCaseSize = cJSON_GetArraySize(pCaseList);
  466. for ( int ii = 0; ii < nCaseSize; ii++ )
  467. {
  468. cJSON *pCase = cJSON_GetArrayItem(pCaseList, ii);
  469. if ( pCase )
  470. {
  471. SATHTTP::STCase stCase;
  472. stCase.strIndex = cJSON_GetObjectItem(pCase, "index") ? cJSON_GetObjectItem(pCase, "index")->valuestring : "";
  473. stCase.strCaseName = cJSON_GetObjectItem(pCase, "caseName") ? cJSON_GetObjectItem(pCase, "caseName")->valuestring : "";
  474. stCase.strMainFilePath = cJSON_GetObjectItem(pCase, "mainFilePath") ? cJSON_GetObjectItem(pCase, "mainFilePath")->valuestring : "";
  475. stCase.strId = cJSON_GetObjectItem(pCase, "id") ? cJSON_GetObjectItem(pCase, "id")->valuestring : "";
  476. stCase.strCaseType = cJSON_GetObjectItem(pCase, "caseType") ? cJSON_GetObjectItem(pCase, "caseType")->valuestring : "";
  477. // 压入Job;
  478. stTask.vtCases.push_back(stCase);
  479. }
  480. }
  481. }
  482. }
  483. }
  484. // 保存任务信息;
  485. stHeartbeatResp.vtTask.push_back(stTask);
  486. }
  487. }
  488. // 释放内存;
  489. cJSON_Delete(pRoot);
  490. // 返回结果;
  491. return TRUE;
  492. }
  493. }
  494. }
  495. // 错误产生,可输出msg方便查询;
  496. cJSON_Delete(pRoot);
  497. }
  498. }
  499. }
  500. SETLOG;
  501. return FALSE;
  502. }
  503. SATHTTP_API int SetResult(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp)
  504. {
  505. // 转化为Json;
  506. cJSON *pRoot = cJSON_CreateObject();
  507. if ( pRoot == NULL )
  508. {
  509. return -1;
  510. }
  511. cJSON_AddStringToObject(pRoot, "sysCode", "");
  512. cJSON_AddStringToObject(pRoot, "function", "");
  513. cJSON *pData = cJSON_CreateObject();
  514. if ( pData )
  515. {
  516. cJSON_AddStringToObject(pData, "instanceId", stNotifyJobStartReq.strInstanceId.c_str());
  517. cJSON_AddStringToObject(pData, "signalImageUrl", stNotifyJobStartReq.strSignalImageUrl.c_str());
  518. cJSON_AddStringToObject(pData, "deviceId", stNotifyJobStartReq.strDeviceId.c_str());
  519. cJSON_AddStringToObject(pData, "taskId", stNotifyJobStartReq.strTaskId.c_str());
  520. cJSON_AddStringToObject(pData, "executeId", stNotifyJobStartReq.strExecuteId.c_str());
  521. // 添加到根结点中;
  522. cJSON_AddItemToObject(pRoot, "data", pData);
  523. }
  524. char *pText = cJSON_Print(pRoot);
  525. std::string post_data = "requestMsg=";
  526. post_data.append(pText);
  527. //post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  528. // 释放堆内存;
  529. if (pText)
  530. delete pText;
  531. pText = NULL;
  532. if ( pRoot )
  533. cJSON_Delete(pRoot);
  534. pRoot = NULL;
  535. std::string reponse;
  536. CURLcode curlCode = CURLE_OK;
  537. if ( g_curl.IsInit() )
  538. {
  539. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  540. curlCode = g_curl.Posts(url, post_data, reponse);
  541. else
  542. curlCode = g_curl.Post(url, post_data, reponse);
  543. if ( curlCode == CURLE_OK )
  544. {
  545. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  546. // 解析返回值;
  547. pRoot = cJSON_Parse(reponse.c_str());
  548. if (pRoot != NULL)
  549. {
  550. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  551. if ( pMsg )
  552. {
  553. stNotifyJobStartResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  554. stNotifyJobStartResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  555. stNotifyJobStartResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  556. if ( stNotifyJobStartResp.strCode == "00" )
  557. {
  558. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  559. if (pObj != NULL)
  560. {
  561. }
  562. // 释放内存;
  563. cJSON_Delete(pRoot);
  564. // 返回结果;
  565. return TRUE;
  566. }
  567. }
  568. // 错误产生,可输出msg方便查询;
  569. cJSON_Delete(pRoot);
  570. }
  571. }
  572. }
  573. SETLOG;
  574. return FALSE;
  575. }
  576. SATHTTP_API int SetResultList(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp)
  577. {
  578. // 转化为Json;
  579. cJSON *pRoot = cJSON_CreateObject();
  580. if ( pRoot == NULL )
  581. {
  582. return -1;
  583. }
  584. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  585. cJSON_AddStringToObject(pRoot, "function", "setResultList");
  586. cJSON *pData = cJSON_CreateObject();
  587. if ( pData )
  588. {
  589. cJSON_AddStringToObject(pData, "result_state", stJobProcessReq.strResultState.c_str());
  590. cJSON_AddStringToObject(pData, "case_scene", stJobProcessReq.strCaseScene.c_str());
  591. cJSON_AddStringToObject(pData, "case_step", stJobProcessReq.strCaseStep.c_str());
  592. cJSON_AddStringToObject(pData, "apkMd5", stJobProcessReq.strApkMD5.c_str());
  593. cJSON_AddStringToObject(pData, "crash_time", stJobProcessReq.strCrashTime.c_str());
  594. cJSON_AddStringToObject(pData, "runner_id", stJobProcessReq.strRunnerId.c_str());
  595. cJSON_AddStringToObject(pData, "cpu_info", stJobProcessReq.strCPUInfo.c_str());
  596. cJSON_AddStringToObject(pData, "runnedActionNameList", stJobProcessReq.strRunnedActionNameList.c_str());
  597. cJSON_AddStringToObject(pData, "artificial_result", stJobProcessReq.strArtificialResult.c_str());
  598. cJSON_AddStringToObject(pData, "artificial_modify", stJobProcessReq.strArtificialModify.c_str());
  599. cJSON_AddStringToObject(pData, "runner_name", stJobProcessReq.strRunnerName.c_str());
  600. cJSON_AddStringToObject(pData, "task_type", stJobProcessReq.strTaskType.c_str());
  601. cJSON_AddStringToObject(pData, "case_repeat", stJobProcessReq.strCaseRepeat.c_str());
  602. cJSON_AddStringToObject(pData, "application_group", stJobProcessReq.strApplicationGroup.c_str());
  603. cJSON_AddStringToObject(pData, "instanceId", stJobProcessReq.strInstanceId.c_str());
  604. cJSON_AddStringToObject(pData, "case_id", stJobProcessReq.strCaseId.c_str());
  605. cJSON_AddStringToObject(pData, "progress", stJobProcessReq.strProgress.c_str());
  606. cJSON_AddStringToObject(pData, "result_message", stJobProcessReq.strReusltMessage.c_str());
  607. cJSON_AddStringToObject(pData, "job_repeat", stJobProcessReq.strJobRepeat.c_str());
  608. cJSON_AddStringToObject(pData, "screenshot", stJobProcessReq.strScreenShot.c_str());
  609. cJSON_AddStringToObject(pData, "start_time", stJobProcessReq.strStartTime.c_str());
  610. cJSON_AddStringToObject(pData, "crash_number", stJobProcessReq.strCrashNumber.c_str());
  611. cJSON_AddStringToObject(pData, "case_name", stJobProcessReq.strCaseName.c_str());
  612. cJSON_AddStringToObject(pData, "failed_reason", stJobProcessReq.strFailedReason.c_str());
  613. cJSON_AddStringToObject(pData, "img_name", stJobProcessReq.strImgName.c_str());
  614. cJSON_AddStringToObject(pData, "case_index", stJobProcessReq.strCaseIndex.c_str());
  615. cJSON_AddStringToObject(pData, "device_id", stJobProcessReq.strDeviceId.c_str());
  616. cJSON_AddStringToObject(pData, "scene_index", stJobProcessReq.strSceneIndex.c_str());
  617. cJSON_AddStringToObject(pData, "task_id", stJobProcessReq.strTaskId.c_str());
  618. cJSON_AddStringToObject(pData, "analysis", stJobProcessReq.strAnalysis.c_str());
  619. cJSON_AddStringToObject(pData, "device_name", stJobProcessReq.strDevnceName.c_str());
  620. cJSON_AddStringToObject(pData, "info_type", stJobProcessReq.strInfoType.c_str());
  621. cJSON_AddStringToObject(pData, "memory_info", stJobProcessReq.strMemoryInfo.c_str());
  622. cJSON_AddStringToObject(pData, "end_time", stJobProcessReq.strEndTime.c_str());
  623. cJSON_AddStringToObject(pData, "round_number", stJobProcessReq.strRoundNumber.c_str());
  624. cJSON_AddStringToObject(pData, "result_type", stJobProcessReq.strResultType.c_str());
  625. cJSON_AddStringToObject(pData, "operation_step", stJobProcessReq.strOperationStep.c_str());
  626. // 添加到根结点中;
  627. cJSON_AddItemToObject(pRoot, "data", pData);
  628. }
  629. char *pText = cJSON_Print(pRoot);
  630. std::string post_data = "requestMsg=";
  631. post_data.append(CharEncoding::EnCode_GB2312URL(pText));
  632. //post_data.append(pText);
  633. // 释放堆内存;
  634. if (pText)
  635. delete pText;
  636. pText = NULL;
  637. if ( pRoot )
  638. cJSON_Delete(pRoot);
  639. pRoot = NULL;
  640. std::string reponse;
  641. CURLcode curlCode = CURLE_OK;
  642. if ( g_curl.IsInit() )
  643. {
  644. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  645. curlCode = g_curl.Posts(url, post_data, reponse);
  646. else
  647. curlCode = g_curl.Post(url, post_data, reponse);
  648. if ( curlCode == CURLE_OK )
  649. {
  650. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  651. // 解析返回值;
  652. pRoot = cJSON_Parse(reponse.c_str());
  653. if (pRoot != NULL)
  654. {
  655. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  656. if ( pMsg )
  657. {
  658. stJobProcessResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  659. stJobProcessResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  660. stJobProcessResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  661. if ( stJobProcessResp.strCode == "00" )
  662. {
  663. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  664. if (pObj != NULL)
  665. {
  666. stJobProcessResp.strIsDelete = cJSON_GetObjectItem(pObj, "isDelete") ? (cJSON_GetObjectItem(pObj, "isDelete")->valuestring ? cJSON_GetObjectItem(pObj, "isDelete")->valuestring : "") : "";
  667. }
  668. // 释放内存;
  669. cJSON_Delete(pRoot);
  670. // 返回结果;
  671. return TRUE;
  672. }
  673. }
  674. // 错误产生,可输出msg方便查询;
  675. cJSON_Delete(pRoot);
  676. }
  677. }
  678. }
  679. SETLOG;
  680. return FALSE;
  681. }
  682. SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATHTTP::STScriptUrlResp &stScriptUrlResp)
  683. {
  684. // 转化为Json;
  685. cJSON *pRoot = cJSON_CreateObject();
  686. if ( pRoot == NULL )
  687. {
  688. return -1;
  689. }
  690. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  691. cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl");
  692. cJSON *pData = cJSON_CreateObject();
  693. if ( pData )
  694. {
  695. cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str());
  696. // 添加到根结点中;
  697. cJSON_AddItemToObject(pRoot, "data", pData);
  698. }
  699. char *pText = cJSON_Print(pRoot);
  700. std::string post_data = "requestMsg=";
  701. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  702. // 释放堆内存;
  703. if (pText)
  704. delete pText;
  705. pText = NULL;
  706. if ( pRoot )
  707. cJSON_Delete(pRoot);
  708. pRoot = NULL;
  709. std::string reponse;
  710. CURLcode curlCode = CURLE_OK;
  711. if ( g_curl.IsInit() )
  712. {
  713. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  714. curlCode = g_curl.Posts(url, post_data, reponse);
  715. else
  716. curlCode = g_curl.Post(url, post_data, reponse);
  717. if ( curlCode == CURLE_OK )
  718. {
  719. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  720. // 解析返回值;
  721. pRoot = cJSON_Parse(reponse.c_str());
  722. if (pRoot != NULL)
  723. {
  724. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  725. if ( pMsg )
  726. {
  727. stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  728. stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  729. stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
  730. stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
  731. if ( stScriptUrlResp.strCode == "00" )
  732. {
  733. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  734. if (pObj != NULL)
  735. {
  736. if ( cJSON_GetArraySize(pObj) >= 1 )
  737. {
  738. cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
  739. if ( pScripURL )
  740. {
  741. stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
  742. // 同时下载脚本目录到指定目录中;
  743. }
  744. }
  745. }
  746. // 释放内存;
  747. cJSON_Delete(pRoot);
  748. // 返回结果;
  749. return TRUE;
  750. }
  751. }
  752. // 错误产生,可输出msg方便查询;
  753. cJSON_Delete(pRoot);
  754. }
  755. }
  756. }
  757. SETLOG;
  758. return FALSE;
  759. }
  760. SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::string strSaveDir, SATHTTP::STScriptUrlResp &stScriptUrlResp)
  761. {
  762. // 转化为Json;
  763. cJSON *pRoot = cJSON_CreateObject();
  764. if ( pRoot == NULL )
  765. {
  766. return -1;
  767. }
  768. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  769. cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl");
  770. cJSON *pData = cJSON_CreateObject();
  771. if ( pData )
  772. {
  773. cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str());
  774. // 添加到根结点中;
  775. cJSON_AddItemToObject(pRoot, "data", pData);
  776. }
  777. char *pText = cJSON_Print(pRoot);
  778. std::string post_data = "requestMsg=";
  779. GLOBAL::WriteTextLog("<======下载请求======> \r 请求内容:%s %s", url.c_str(), post_data.c_str());
  780. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  781. // 释放堆内存;
  782. if (pText)
  783. delete pText;
  784. pText = NULL;
  785. if ( pRoot )
  786. cJSON_Delete(pRoot);
  787. pRoot = NULL;
  788. std::string reponse;
  789. CURLcode curlCode = CURLE_OK;
  790. if ( g_curl.IsInit() ) {
  791. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  792. curlCode = g_curl.Posts(url, post_data, reponse);
  793. else
  794. curlCode = g_curl.Post(url, post_data, reponse);
  795. if ( curlCode == CURLE_OK ) {
  796. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  797. // 解析返回值;
  798. pRoot = cJSON_Parse(reponse.c_str());
  799. if (pRoot != NULL) {
  800. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  801. if ( pMsg ) {
  802. stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  803. stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  804. stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
  805. stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
  806. if ( stScriptUrlResp.strCode == "00" ) {
  807. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  808. if (pObj != NULL) {
  809. if ( cJSON_GetArraySize(pObj) >= 1 ) {
  810. cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
  811. if ( pScripURL ) {
  812. stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
  813. std::string strFileDir;
  814. std::string strFileName;
  815. int nPos1 = 0, nPos2 = 0;
  816. nPos1 = stScriptUrlResp.strURL.find("fileDir=");
  817. nPos2 = stScriptUrlResp.strURL.find("&fileName=");
  818. if ( nPos1 != std::string::npos && nPos2 != std::string::npos ) {
  819. strFileDir = stScriptUrlResp.strURL.substr(nPos1 + strlen("fileDir="), nPos2 - nPos1 - strlen("fileDir="));
  820. strFileName = stScriptUrlResp.strURL.substr(nPos2 + strlen("&fileName="));
  821. // 保存目录;
  822. stScriptUrlResp._strFileDir = strSaveDir;
  823. strSaveDir.append(strFileName);
  824. // 替换无效的目录字符;
  825. strSaveDir = GLOBAL::Replace(strSaveDir, "\\", "/");
  826. // 创建目录;
  827. if ( MKDIR(strSaveDir.c_str()) ) {
  828. // 同时下载脚本目录到指定目录中;// url地址可能包含中文,此处需要转码;
  829. stScriptUrlResp.strURL = CCurlClient::ParseURLAndEncode(stScriptUrlResp.strURL);
  830. GLOBAL::WriteTextLog("<======下载文件======> \r 文件地址:%s,保存路径:%s ", stScriptUrlResp.strURL.c_str(), strSaveDir.c_str());
  831. if ( g_curl.Download(stScriptUrlResp.strURL, strSaveDir, 20000) ) {
  832. stScriptUrlResp._strFileName = strFileName.substr(0, strFileName.find_last_of('.'));
  833. stScriptUrlResp._strScripFile = strSaveDir;
  834. // 释放内存;
  835. cJSON_Delete(pRoot);
  836. // 返回结果;
  837. return TRUE;
  838. }
  839. else
  840. {
  841. GLOBAL::WriteTextLog(_T("【Error】下载脚本失败:%s"), stScriptUrlResp.strURL.c_str());
  842. }
  843. }
  844. GLOBAL::WriteTextLog(_T("【Error】创建目录失败:%s"), strSaveDir.c_str());
  845. }
  846. }
  847. }
  848. }
  849. }
  850. else
  851. {
  852. GLOBAL::WriteTextLog(_T("【Error】文件不可下载:%s"), reponse.c_str());
  853. }
  854. }
  855. // 错误产生,可输出msg方便查询;
  856. cJSON_Delete(pRoot);
  857. }
  858. }
  859. }
  860. SETLOG;
  861. return FALSE;
  862. }
  863. SATHTTP_API int StopTaskFromRunner(std::string url, std::string strInstnaceId, SATHTTP::STStopTaskResp &stStopTaskResp)
  864. {
  865. // 转化为Json;
  866. cJSON *pRoot = cJSON_CreateObject();
  867. if ( pRoot == NULL )
  868. {
  869. return -1;
  870. }
  871. cJSON_AddStringToObject(pRoot, "sysCode", "");
  872. cJSON_AddStringToObject(pRoot, "function", "");
  873. cJSON *pData = cJSON_CreateObject();
  874. if ( pData )
  875. {
  876. cJSON_AddStringToObject(pData, "instanceId", strInstnaceId.c_str());
  877. // 添加到根结点中;
  878. cJSON_AddItemToObject(pRoot, "data", pData);
  879. }
  880. char *pText = cJSON_Print(pRoot);
  881. std::string post_data = "requestMsg=";
  882. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  883. // 释放堆内存;
  884. if (pText)
  885. delete pText;
  886. pText = NULL;
  887. if ( pRoot )
  888. cJSON_Delete(pRoot);
  889. pRoot = NULL;
  890. std::string reponse;
  891. CURLcode curlCode = CURLE_OK;
  892. if ( g_curl.IsInit() )
  893. {
  894. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  895. curlCode = g_curl.Posts(url, post_data, reponse);
  896. else
  897. curlCode = g_curl.Post(url, post_data, reponse);
  898. if ( curlCode == CURLE_OK )
  899. {
  900. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  901. // 解析返回值;
  902. pRoot = cJSON_Parse(reponse.c_str());
  903. if (pRoot != NULL)
  904. {
  905. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  906. if ( pMsg )
  907. {
  908. stStopTaskResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  909. stStopTaskResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  910. stStopTaskResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  911. stStopTaskResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  912. if ( stStopTaskResp.strCode == "00" )
  913. {
  914. // 释放内存;
  915. cJSON_Delete(pRoot);
  916. // 返回结果;
  917. return TRUE;
  918. }
  919. }
  920. // 错误产生,可输出msg方便查询;
  921. cJSON_Delete(pRoot);
  922. }
  923. }
  924. }
  925. SETLOG;
  926. return FALSE;
  927. }
  928. SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATHTTP::STSaveLogReq &stSaveLogReq, SATHTTP::STSaveLogResp &stSaveLogResp)
  929. {
  930. // 转化为Json;
  931. cJSON *pRoot = cJSON_CreateObject();
  932. if ( pRoot == NULL )
  933. {
  934. return -1;
  935. }
  936. cJSON_AddStringToObject(pRoot, "useId", stSaveLogReq.strUserId.c_str());
  937. cJSON *pData = cJSON_CreateObject();
  938. if ( pData )
  939. {
  940. cJSON_AddStringToObject(pData, "fileType", stSaveLogReq.strFileType.c_str());
  941. cJSON_AddStringToObject(pData, "caseId", stSaveLogReq.strCaseId.c_str());
  942. cJSON_AddStringToObject(pData, "taskId", stSaveLogReq.strTaskId.c_str());
  943. cJSON_AddStringToObject(pData, "executeId", stSaveLogReq.strExecuteId.c_str());
  944. cJSON_AddStringToObject(pData, "roundNum", stSaveLogReq.strRoundNum.c_str());
  945. // 添加到根结点中;
  946. cJSON_AddItemToObject(pRoot, "data", pData);
  947. }
  948. char *pText = cJSON_Print(pRoot);
  949. //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
  950. // POST表单提交,此处不需要转url格式,注意避坑!
  951. std::string post_data = pText;
  952. // 释放堆内存;
  953. if (pText)
  954. delete pText;
  955. pText = NULL;
  956. if ( pRoot )
  957. cJSON_Delete(pRoot);
  958. pRoot = NULL;
  959. std::string reponse;
  960. CURLcode curlCode = CURLE_OK;
  961. if ( g_curl.IsInit() )
  962. {
  963. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  964. curlCode = g_curl.Posts(url, post_data, reponse);
  965. else
  966. curlCode = g_curl.PostFile(url, post_data, stSaveLogReq.strUploads, reponse);
  967. if ( curlCode == CURLE_OK )
  968. {
  969. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  970. // 解析返回值;
  971. pRoot = cJSON_Parse(reponse.c_str());
  972. if (pRoot != NULL)
  973. {
  974. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  975. if ( pMsg )
  976. {
  977. stSaveLogResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  978. stSaveLogResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  979. stSaveLogResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  980. stSaveLogResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
  981. if ( stSaveLogResp.strCode == "00" )
  982. {
  983. // 释放内存;
  984. cJSON_Delete(pRoot);
  985. // 返回结果;
  986. return TRUE;
  987. }
  988. }
  989. // 错误产生,可输出msg方便查询;
  990. cJSON_Delete(pRoot);
  991. }
  992. }
  993. }
  994. SETLOG;
  995. return FALSE;
  996. }
  997. SATHTTP_API int SaveResultFile(std::string url, const SATHTTP::STSaveFileReq &stSaveFileReq, SATHTTP::STSaveFileResp &stSaveFileResp)
  998. {
  999. // 转化为Json;
  1000. cJSON *pRoot = cJSON_CreateObject();
  1001. if ( pRoot == NULL )
  1002. {
  1003. return -1;
  1004. }
  1005. cJSON_AddStringToObject(pRoot, "sysCode", "");
  1006. cJSON_AddStringToObject(pRoot, "function", "");
  1007. cJSON *pData = cJSON_CreateObject();
  1008. if ( pData )
  1009. {
  1010. cJSON_AddStringToObject(pData, "roundNum", stSaveFileReq.strRoundNum.c_str());
  1011. cJSON_AddStringToObject(pData, "caseRepeat", stSaveFileReq.strCaseRepeat.c_str());
  1012. cJSON_AddStringToObject(pData, "jobRepeat", stSaveFileReq.strJobRepeat.c_str());
  1013. cJSON_AddStringToObject(pData, "instanceId", stSaveFileReq.strInstanceId.c_str());
  1014. cJSON_AddStringToObject(pData, "deviceId", stSaveFileReq.strDeviceId.c_str());
  1015. cJSON_AddStringToObject(pData, "executeId", stSaveFileReq.strExecuteId.c_str());
  1016. cJSON_AddStringToObject(pData, "taskName", stSaveFileReq.strTaskName.c_str());
  1017. cJSON_AddStringToObject(pData, "sceneIndex", stSaveFileReq.strSceneIndex.c_str());
  1018. cJSON_AddStringToObject(pData, "taskId", stSaveFileReq.strTaskId.c_str());
  1019. cJSON_AddStringToObject(pData, "caseId", stSaveFileReq.strCaseId.c_str());
  1020. cJSON_AddStringToObject(pData, "deviceName", stSaveFileReq.strDeviceName.c_str());
  1021. cJSON_AddStringToObject(pData, "runnerName", stSaveFileReq.strRunnerName.c_str());
  1022. cJSON_AddStringToObject(pData, "runnerIP", stSaveFileReq.strRunnerIP.c_str());
  1023. cJSON_AddStringToObject(pData, "runnerMac", stSaveFileReq.strRunnerMAC.c_str());
  1024. cJSON_AddStringToObject(pData, "caseName", stSaveFileReq.strCaseName.c_str());
  1025. cJSON_AddStringToObject(pData, "caseIndex", stSaveFileReq.strCaseIndex.c_str());
  1026. cJSON_AddStringToObject(pData, "taskRepeat", stSaveFileReq.strTaskRepeat.c_str());
  1027. cJSON_AddStringToObject(pData, "busCode", stSaveFileReq.strBusCode.c_str());
  1028. cJSON_AddStringToObject(pData, "fileType", stSaveFileReq.strFileType.c_str());
  1029. cJSON_AddStringToObject(pData, "caseStep", stSaveFileReq.strCaseStep.c_str());
  1030. // 添加到根结点中;
  1031. cJSON_AddItemToObject(pRoot, "data", pData);
  1032. }
  1033. char *pText = cJSON_Print(pRoot);
  1034. //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
  1035. // POST表单提交,此处不需要转url格式,注意避坑!
  1036. std::string post_data = pText;
  1037. // 释放堆内存;
  1038. if (pText)
  1039. delete pText;
  1040. pText = NULL;
  1041. if ( pRoot )
  1042. cJSON_Delete(pRoot);
  1043. pRoot = NULL;
  1044. std::string reponse;
  1045. CURLcode curlCode = CURLE_OK;
  1046. if ( g_curl.IsInit() )
  1047. {
  1048. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  1049. curlCode = g_curl.Posts(url, post_data, reponse);
  1050. else
  1051. curlCode = g_curl.PostFile(url, post_data, stSaveFileReq.strUploads, reponse);
  1052. if ( curlCode == CURLE_OK )
  1053. {
  1054. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  1055. // 解析返回值;
  1056. pRoot = cJSON_Parse(reponse.c_str());
  1057. if (pRoot != NULL)
  1058. {
  1059. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  1060. if ( pMsg )
  1061. {
  1062. stSaveFileResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  1063. stSaveFileResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  1064. stSaveFileResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  1065. stSaveFileResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
  1066. if ( stSaveFileResp.strCode == "00" )
  1067. {
  1068. // 释放内存;
  1069. cJSON_Delete(pRoot);
  1070. // 返回结果;
  1071. return TRUE;
  1072. }
  1073. }
  1074. // 错误产生,可输出msg方便查询;
  1075. cJSON_Delete(pRoot);
  1076. }
  1077. }
  1078. }
  1079. SETLOG;
  1080. return FALSE;
  1081. }
  1082. SATHTTP_API int SaveResultImg(std::string url, const SATHTTP::STSaveImgReq &stSaveImgReq, SATHTTP::STSaveImgResp &stSaveImgResp)
  1083. {
  1084. // 转化为Json;
  1085. cJSON *pRoot = cJSON_CreateObject();
  1086. if ( pRoot == NULL )
  1087. {
  1088. return -1;
  1089. }
  1090. cJSON_AddStringToObject(pRoot, "sysCode", "");
  1091. cJSON_AddStringToObject(pRoot, "function", "");
  1092. cJSON *pData = cJSON_CreateObject();
  1093. if ( pData )
  1094. {
  1095. cJSON_AddStringToObject(pData, "instanceId", stSaveImgReq.strInstanceId.c_str());
  1096. cJSON_AddStringToObject(pData, "deviceId", stSaveImgReq.strDeviceId.c_str());
  1097. cJSON_AddStringToObject(pData, "roundNum", stSaveImgReq.strRoundNum.c_str());
  1098. cJSON_AddStringToObject(pData, "caseId", stSaveImgReq.strCaseId.c_str());
  1099. cJSON_AddStringToObject(pData, "step", stSaveImgReq.strCaseStep.c_str());
  1100. cJSON_AddStringToObject(pData, "type", stSaveImgReq.strImgType.c_str());
  1101. cJSON_AddStringToObject(pData, "executeId", stSaveImgReq.strExecuteId.c_str());
  1102. cJSON_AddStringToObject(pData, "caseRepeat", stSaveImgReq.strCaseRepeat.c_str());
  1103. cJSON_AddStringToObject(pData, "jobRepeat", stSaveImgReq.strJobRepeat.c_str());
  1104. // 添加到根结点中;
  1105. cJSON_AddItemToObject(pRoot, "data", pData);
  1106. }
  1107. char *pText = cJSON_Print(pRoot);
  1108. //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
  1109. // POST表单提交,此处不需要转url格式,注意避坑!
  1110. std::string post_data = pText;
  1111. // 释放堆内存;
  1112. if (pText)
  1113. delete pText;
  1114. pText = NULL;
  1115. if ( pRoot )
  1116. cJSON_Delete(pRoot);
  1117. pRoot = NULL;
  1118. std::string reponse;
  1119. CURLcode curlCode = CURLE_OK;
  1120. if ( g_curl.IsInit() )
  1121. {
  1122. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  1123. curlCode = g_curl.Posts(url, post_data, reponse);
  1124. else
  1125. curlCode = g_curl.PostFile(url, post_data, stSaveImgReq.strUploads, reponse);
  1126. if ( curlCode == CURLE_OK )
  1127. {
  1128. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  1129. // 解析返回值;
  1130. pRoot = cJSON_Parse(reponse.c_str());
  1131. if (pRoot != NULL)
  1132. {
  1133. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  1134. if ( pMsg )
  1135. {
  1136. stSaveImgResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  1137. stSaveImgResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  1138. stSaveImgResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  1139. stSaveImgResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
  1140. if ( stSaveImgResp.strCode == "00" )
  1141. {
  1142. // 释放内存;
  1143. cJSON_Delete(pRoot);
  1144. // 返回结果;
  1145. return TRUE;
  1146. }
  1147. }
  1148. // 错误产生,可输出msg方便查询;
  1149. cJSON_Delete(pRoot);
  1150. }
  1151. }
  1152. }
  1153. SETLOG;
  1154. return FALSE;
  1155. }