SATHTTP.cpp 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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, "cycle");
  409. if ( pSomkingCycle ) {
  410. // 冒烟任务周期;
  411. stTask.taskInfo.stSomkingCycle.nType = cJSON_GetObjectItem(pSomkingCycle, "type") ? _tstoi(cJSON_GetObjectItem(pSomkingCycle, "type")->valuestring) : 1;
  412. stTask.taskInfo.stSomkingCycle.nWeek = cJSON_GetObjectItem(pSomkingCycle, "week") ? _tstoi(cJSON_GetObjectItem(pSomkingCycle, "week")->valuestring) : 0;
  413. stTask.taskInfo.stSomkingCycle.nDay = cJSON_GetObjectItem(pSomkingCycle, "day") ? _tstoi(cJSON_GetObjectItem(pSomkingCycle, "day")->valuestring) : 0;
  414. stTask.taskInfo.stSomkingCycle.strTime = cJSON_GetObjectItem(pSomkingCycle, "time") ? cJSON_GetObjectItem(pSomkingCycle, "time")->valuestring : "05:00";
  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. if (cJSON_GetObjectItem(pJob, "taskInstanceId") && !cJSON_IsNull(cJSON_GetObjectItem(pJob, "taskInstanceId")))
  442. stTask.Job.strTaskInstanceId = cJSON_GetObjectItem(pJob, "taskInstanceId") ? cJSON_GetObjectItem(pJob, "taskInstanceId")->valuestring : "";
  443. stTask.Job.strUserId = cJSON_GetObjectItem(pJob, "userId") ? cJSON_GetObjectItem(pJob, "userId")->valuestring : "";
  444. stTask.Job.strDiffTaskInstanceFlag = cJSON_GetObjectItem(pJob, "diffTaskInstanceFlag") ? cJSON_GetObjectItem(pJob, "diffTaskInstanceFlag")->valuestring : "";
  445. stTask.Job.strBusCode = cJSON_GetObjectItem(pJob, "busCode") ? cJSON_GetObjectItem(pJob, "busCode")->valuestring : "";
  446. stTask.Job.strRound = cJSON_GetObjectItem(pJob, "round") ? cJSON_GetObjectItem(pJob, "round")->valuestring : "";
  447. stTask.Job.strControlType = cJSON_GetObjectItem(pJob, "controlType") ? cJSON_GetObjectItem(pJob, "controlType")->valuestring : "";
  448. stTask.Job.strMonkeyPctMajornav = cJSON_GetObjectItem(pJob, "monkeyPctMajornav") ? cJSON_GetObjectItem(pJob, "monkeyPctMajornav")->valuestring : "";
  449. stTask.Job.strTaskName = cJSON_GetObjectItem(pJob, "taskName") ? cJSON_GetObjectItem(pJob, "taskName")->valuestring : "";
  450. stTask.Job.strMonkeyType = cJSON_GetObjectItem(pJob, "monkeyType") ? cJSON_GetObjectItem(pJob, "monkeyType")->valuestring : "";
  451. stTask.Job.strMonkeyDictate = cJSON_GetObjectItem(pJob, "monkeyDictate") ? cJSON_GetObjectItem(pJob, "monkeyDictate")->valuestring : "";
  452. stTask.Job.strDetectedDeviceName = cJSON_GetObjectItem(pJob, "detectedDeviceName") ? cJSON_GetObjectItem(pJob, "detectedDeviceName")->valuestring : "";
  453. stTask.Job.strExecuteName = cJSON_GetObjectItem(pJob, "executeName") ? cJSON_GetObjectItem(pJob, "executeName")->valuestring : "";
  454. stTask.Job.strProjectName = cJSON_GetObjectItem(pJob, "projectName") ? cJSON_GetObjectItem(pJob, "projectName")->valuestring : "";
  455. stTask.Job.strProjectId = cJSON_GetObjectItem(pJob, "projectId") ? cJSON_GetObjectItem(pJob, "projectId")->valuestring : "";
  456. stTask.Job.strUniqueId = cJSON_GetObjectItem(pJob, "uniqueId") ? cJSON_GetObjectItem(pJob, "uniqueId")->valuestring : "";
  457. stTask.Job.strTaskId = cJSON_GetObjectItem(pJob, "taskId") ? cJSON_GetObjectItem(pJob, "taskId")->valuestring : "";
  458. stTask.Job.strSoftwareVersion = cJSON_GetObjectItem(pJob, "softwareVersion") ? cJSON_GetObjectItem(pJob, "softwareVersion")->valuestring : "";
  459. stTask.Job.strMonkeyPctNav = cJSON_GetObjectItem(pJob, "monkeyPctNav") ? cJSON_GetObjectItem(pJob, "monkeyPctNav")->valuestring : "";
  460. // emails,已重复,忽略;
  461. // cJSON *pEmals = cJSON_GetObjectItem(pJob, "emails");
  462. // case list;
  463. cJSON *pCaseList = cJSON_GetObjectItem(pJob, "caseList");
  464. if ( pCaseList )
  465. {
  466. int nCaseSize = cJSON_GetArraySize(pCaseList);
  467. for ( int ii = 0; ii < nCaseSize; ii++ )
  468. {
  469. cJSON *pCase = cJSON_GetArrayItem(pCaseList, ii);
  470. if ( pCase )
  471. {
  472. SATHTTP::STCase stCase;
  473. stCase.strIndex = cJSON_GetObjectItem(pCase, "index") ? cJSON_GetObjectItem(pCase, "index")->valuestring : "";
  474. stCase.strCaseName = cJSON_GetObjectItem(pCase, "caseName") ? cJSON_GetObjectItem(pCase, "caseName")->valuestring : "";
  475. stCase.strMainFilePath = cJSON_GetObjectItem(pCase, "mainFilePath") ? cJSON_GetObjectItem(pCase, "mainFilePath")->valuestring : "";
  476. stCase.strId = cJSON_GetObjectItem(pCase, "id") ? cJSON_GetObjectItem(pCase, "id")->valuestring : "";
  477. stCase.strCaseType = cJSON_GetObjectItem(pCase, "caseType") ? cJSON_GetObjectItem(pCase, "caseType")->valuestring : "";
  478. // 压入Job;
  479. stTask.vtCases.push_back(stCase);
  480. }
  481. }
  482. }
  483. }
  484. }
  485. // 保存任务信息;
  486. stHeartbeatResp.vtTask.push_back(stTask);
  487. }
  488. }
  489. // 释放内存;
  490. cJSON_Delete(pRoot);
  491. // 返回结果;
  492. return TRUE;
  493. }
  494. }
  495. }
  496. // 错误产生,可输出msg方便查询;
  497. cJSON_Delete(pRoot);
  498. }
  499. }
  500. }
  501. SETLOG;
  502. return FALSE;
  503. }
  504. SATHTTP_API int SetResult(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp)
  505. {
  506. // 转化为Json;
  507. cJSON *pRoot = cJSON_CreateObject();
  508. if ( pRoot == NULL )
  509. {
  510. return -1;
  511. }
  512. cJSON_AddStringToObject(pRoot, "sysCode", "");
  513. cJSON_AddStringToObject(pRoot, "function", "");
  514. cJSON *pData = cJSON_CreateObject();
  515. if ( pData )
  516. {
  517. cJSON_AddStringToObject(pData, "instanceId", stNotifyJobStartReq.strInstanceId.c_str());
  518. cJSON_AddStringToObject(pData, "signalImageUrl", stNotifyJobStartReq.strSignalImageUrl.c_str());
  519. cJSON_AddStringToObject(pData, "deviceId", stNotifyJobStartReq.strDeviceId.c_str());
  520. cJSON_AddStringToObject(pData, "taskId", stNotifyJobStartReq.strTaskId.c_str());
  521. cJSON_AddStringToObject(pData, "executeId", stNotifyJobStartReq.strExecuteId.c_str());
  522. cJSON_AddStringToObject(pData, "taskType", stNotifyJobStartReq.strTaskType.c_str());
  523. // 添加到根结点中;
  524. cJSON_AddItemToObject(pRoot, "data", pData);
  525. }
  526. char *pText = cJSON_Print(pRoot);
  527. std::string post_data = "requestMsg=";
  528. post_data.append(pText);
  529. //post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  530. // 释放堆内存;
  531. if (pText)
  532. delete pText;
  533. pText = NULL;
  534. if ( pRoot )
  535. cJSON_Delete(pRoot);
  536. pRoot = NULL;
  537. std::string reponse;
  538. CURLcode curlCode = CURLE_OK;
  539. if ( g_curl.IsInit() )
  540. {
  541. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  542. curlCode = g_curl.Posts(url, post_data, reponse);
  543. else
  544. curlCode = g_curl.Post(url, post_data, reponse);
  545. if ( curlCode == CURLE_OK )
  546. {
  547. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  548. // 解析返回值;
  549. pRoot = cJSON_Parse(reponse.c_str());
  550. if (pRoot != NULL)
  551. {
  552. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  553. if ( pMsg )
  554. {
  555. stNotifyJobStartResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  556. if ( cJSON_GetObjectItem(pMsg, "message") && !cJSON_IsNull(cJSON_GetObjectItem(pMsg, "message")) )
  557. stNotifyJobStartResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  558. if ( cJSON_GetObjectItem(pMsg, "message") && !cJSON_IsNull(cJSON_GetObjectItem(pMsg, "message")) )
  559. stNotifyJobStartResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  560. if ( stNotifyJobStartResp.strCode == "00" )
  561. {
  562. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  563. if (pObj != NULL)
  564. {
  565. }
  566. // 释放内存;
  567. cJSON_Delete(pRoot);
  568. // 返回结果;
  569. return TRUE;
  570. }
  571. }
  572. // 错误产生,可输出msg方便查询;
  573. cJSON_Delete(pRoot);
  574. }
  575. }
  576. }
  577. SETLOG;
  578. return FALSE;
  579. }
  580. SATHTTP_API int SetResultList(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp)
  581. {
  582. // 转化为Json;
  583. cJSON *pRoot = cJSON_CreateObject();
  584. if ( pRoot == NULL )
  585. {
  586. return -1;
  587. }
  588. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  589. cJSON_AddStringToObject(pRoot, "function", "setResultList");
  590. cJSON *pData = cJSON_CreateObject();
  591. if ( pData )
  592. {
  593. cJSON_AddStringToObject(pData, "result_state", stJobProcessReq.strResultState.c_str());
  594. cJSON_AddStringToObject(pData, "case_scene", stJobProcessReq.strCaseScene.c_str());
  595. cJSON_AddStringToObject(pData, "case_step", stJobProcessReq.strCaseStep.c_str());
  596. cJSON_AddStringToObject(pData, "apkMd5", stJobProcessReq.strApkMD5.c_str());
  597. cJSON_AddStringToObject(pData, "crash_time", stJobProcessReq.strCrashTime.c_str());
  598. cJSON_AddStringToObject(pData, "runner_id", stJobProcessReq.strRunnerId.c_str());
  599. cJSON_AddStringToObject(pData, "cpu_info", stJobProcessReq.strCPUInfo.c_str());
  600. cJSON_AddStringToObject(pData, "runnedActionNameList", stJobProcessReq.strRunnedActionNameList.c_str());
  601. cJSON_AddStringToObject(pData, "artificial_result", stJobProcessReq.strArtificialResult.c_str());
  602. cJSON_AddStringToObject(pData, "artificial_modify", stJobProcessReq.strArtificialModify.c_str());
  603. cJSON_AddStringToObject(pData, "runner_name", stJobProcessReq.strRunnerName.c_str());
  604. cJSON_AddStringToObject(pData, "task_type", stJobProcessReq.strTaskType.c_str());
  605. cJSON_AddStringToObject(pData, "case_repeat", stJobProcessReq.strCaseRepeat.c_str());
  606. cJSON_AddStringToObject(pData, "application_group", stJobProcessReq.strApplicationGroup.c_str());
  607. cJSON_AddStringToObject(pData, "instanceId", stJobProcessReq.strInstanceId.c_str());
  608. cJSON_AddStringToObject(pData, "case_id", stJobProcessReq.strCaseId.c_str());
  609. cJSON_AddStringToObject(pData, "progress", stJobProcessReq.strProgress.c_str());
  610. cJSON_AddStringToObject(pData, "result_message", stJobProcessReq.strReusltMessage.c_str());
  611. cJSON_AddStringToObject(pData, "job_repeat", stJobProcessReq.strJobRepeat.c_str());
  612. cJSON_AddStringToObject(pData, "screenshot", stJobProcessReq.strScreenShot.c_str());
  613. cJSON_AddStringToObject(pData, "start_time", stJobProcessReq.strStartTime.c_str());
  614. cJSON_AddStringToObject(pData, "crash_number", stJobProcessReq.strCrashNumber.c_str());
  615. cJSON_AddStringToObject(pData, "case_name", stJobProcessReq.strCaseName.c_str());
  616. cJSON_AddStringToObject(pData, "failed_reason", stJobProcessReq.strFailedReason.c_str());
  617. cJSON_AddStringToObject(pData, "img_name", stJobProcessReq.strImgName.c_str());
  618. cJSON_AddStringToObject(pData, "case_index", stJobProcessReq.strCaseIndex.c_str());
  619. cJSON_AddStringToObject(pData, "device_id", stJobProcessReq.strDeviceId.c_str());
  620. cJSON_AddStringToObject(pData, "scene_index", stJobProcessReq.strSceneIndex.c_str());
  621. cJSON_AddStringToObject(pData, "task_id", stJobProcessReq.strTaskId.c_str());
  622. cJSON_AddStringToObject(pData, "analysis", stJobProcessReq.strAnalysis.c_str());
  623. cJSON_AddStringToObject(pData, "device_name", stJobProcessReq.strDevnceName.c_str());
  624. cJSON_AddStringToObject(pData, "info_type", stJobProcessReq.strInfoType.c_str());
  625. cJSON_AddStringToObject(pData, "memory_info", stJobProcessReq.strMemoryInfo.c_str());
  626. cJSON_AddStringToObject(pData, "end_time", stJobProcessReq.strEndTime.c_str());
  627. cJSON_AddStringToObject(pData, "round_number", stJobProcessReq.strRoundNumber.c_str());
  628. cJSON_AddStringToObject(pData, "result_type", stJobProcessReq.strResultType.c_str());
  629. cJSON_AddStringToObject(pData, "operation_step", stJobProcessReq.strOperationStep.c_str());
  630. cJSON_AddStringToObject(pData, "instance_type", stJobProcessReq.strInstanceType.c_str());
  631. // 添加到根结点中;
  632. cJSON_AddItemToObject(pRoot, "data", pData);
  633. }
  634. char *pText = cJSON_Print(pRoot);
  635. std::string post_data = "requestMsg=";
  636. post_data.append(CharEncoding::EnCode_GB2312URL(pText));
  637. //post_data.append(pText);
  638. // 释放堆内存;
  639. if (pText)
  640. delete pText;
  641. pText = NULL;
  642. if ( pRoot )
  643. cJSON_Delete(pRoot);
  644. pRoot = NULL;
  645. std::string reponse;
  646. CURLcode curlCode = CURLE_OK;
  647. if ( g_curl.IsInit() )
  648. {
  649. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  650. curlCode = g_curl.Posts(url, post_data, reponse);
  651. else
  652. curlCode = g_curl.Post(url, post_data, reponse);
  653. if ( curlCode == CURLE_OK )
  654. {
  655. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  656. // 解析返回值;
  657. pRoot = cJSON_Parse(reponse.c_str());
  658. if (pRoot != NULL)
  659. {
  660. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  661. if ( pMsg )
  662. {
  663. stJobProcessResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  664. if ( cJSON_GetObjectItem(pMsg, "message") && !cJSON_IsNull(cJSON_GetObjectItem(pMsg, "message")) )
  665. stJobProcessResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  666. if ( cJSON_GetObjectItem(pMsg, "str") && !cJSON_IsNull(cJSON_GetObjectItem(pMsg, "str")) )
  667. stJobProcessResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  668. if ( stJobProcessResp.strCode == "00" )
  669. {
  670. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  671. if (pObj != NULL)
  672. {
  673. stJobProcessResp.strIsDelete = cJSON_GetObjectItem(pObj, "isDelete") ? (cJSON_GetObjectItem(pObj, "isDelete")->valuestring ? cJSON_GetObjectItem(pObj, "isDelete")->valuestring : "") : "";
  674. }
  675. // 释放内存;
  676. cJSON_Delete(pRoot);
  677. // 返回结果;
  678. return TRUE;
  679. }
  680. }
  681. // 错误产生,可输出msg方便查询;
  682. cJSON_Delete(pRoot);
  683. }
  684. }
  685. }
  686. SETLOG;
  687. return FALSE;
  688. }
  689. SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATHTTP::STScriptUrlResp &stScriptUrlResp)
  690. {
  691. // 转化为Json;
  692. cJSON *pRoot = cJSON_CreateObject();
  693. if ( pRoot == NULL )
  694. {
  695. return -1;
  696. }
  697. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  698. cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl");
  699. cJSON *pData = cJSON_CreateObject();
  700. if ( pData )
  701. {
  702. cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str());
  703. // 添加到根结点中;
  704. cJSON_AddItemToObject(pRoot, "data", pData);
  705. }
  706. char *pText = cJSON_Print(pRoot);
  707. std::string post_data = "requestMsg=";
  708. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  709. // 释放堆内存;
  710. if (pText)
  711. delete pText;
  712. pText = NULL;
  713. if ( pRoot )
  714. cJSON_Delete(pRoot);
  715. pRoot = NULL;
  716. std::string reponse;
  717. CURLcode curlCode = CURLE_OK;
  718. if ( g_curl.IsInit() )
  719. {
  720. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  721. curlCode = g_curl.Posts(url, post_data, reponse);
  722. else
  723. curlCode = g_curl.Post(url, post_data, reponse);
  724. if ( curlCode == CURLE_OK )
  725. {
  726. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  727. // 解析返回值;
  728. pRoot = cJSON_Parse(reponse.c_str());
  729. if (pRoot != NULL)
  730. {
  731. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  732. if ( pMsg )
  733. {
  734. stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  735. stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  736. stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
  737. stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
  738. if ( stScriptUrlResp.strCode == "00" )
  739. {
  740. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  741. if (pObj != NULL)
  742. {
  743. if ( cJSON_GetArraySize(pObj) >= 1 )
  744. {
  745. cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
  746. if ( pScripURL )
  747. {
  748. stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
  749. // 同时下载脚本目录到指定目录中;
  750. }
  751. }
  752. }
  753. // 释放内存;
  754. cJSON_Delete(pRoot);
  755. // 返回结果;
  756. return TRUE;
  757. }
  758. }
  759. // 错误产生,可输出msg方便查询;
  760. cJSON_Delete(pRoot);
  761. }
  762. }
  763. }
  764. SETLOG;
  765. return FALSE;
  766. }
  767. SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::string strSaveDir, SATHTTP::STScriptUrlResp &stScriptUrlResp)
  768. {
  769. // 转化为Json;
  770. cJSON *pRoot = cJSON_CreateObject();
  771. if ( pRoot == NULL )
  772. {
  773. return -1;
  774. }
  775. cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
  776. cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl");
  777. cJSON *pData = cJSON_CreateObject();
  778. if ( pData )
  779. {
  780. cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str());
  781. // 添加到根结点中;
  782. cJSON_AddItemToObject(pRoot, "data", pData);
  783. }
  784. char *pText = cJSON_Print(pRoot);
  785. std::string post_data = "requestMsg=";
  786. GLOBAL::WriteTextLog("<======下载请求======> \r 请求内容:%s %s", url.c_str(), post_data.c_str());
  787. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  788. // 释放堆内存;
  789. if (pText)
  790. delete pText;
  791. pText = NULL;
  792. if ( pRoot )
  793. cJSON_Delete(pRoot);
  794. pRoot = NULL;
  795. std::string reponse;
  796. CURLcode curlCode = CURLE_OK;
  797. if ( g_curl.IsInit() ) {
  798. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  799. curlCode = g_curl.Posts(url, post_data, reponse);
  800. else
  801. curlCode = g_curl.Post(url, post_data, reponse);
  802. if ( curlCode == CURLE_OK ) {
  803. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  804. // 解析返回值;
  805. pRoot = cJSON_Parse(reponse.c_str());
  806. if (pRoot != NULL) {
  807. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  808. if ( pMsg ) {
  809. stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  810. stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  811. stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
  812. stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
  813. if ( stScriptUrlResp.strCode == "00" ) {
  814. cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
  815. if (pObj != NULL) {
  816. if ( cJSON_GetArraySize(pObj) >= 1 ) {
  817. cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
  818. if ( pScripURL ) {
  819. stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
  820. std::string strFileDir;
  821. std::string strFileName;
  822. int nPos1 = 0, nPos2 = 0;
  823. nPos1 = stScriptUrlResp.strURL.find("fileDir=");
  824. nPos2 = stScriptUrlResp.strURL.find("&fileName=");
  825. if ( nPos1 != std::string::npos && nPos2 != std::string::npos ) {
  826. strFileDir = stScriptUrlResp.strURL.substr(nPos1 + strlen("fileDir="), nPos2 - nPos1 - strlen("fileDir="));
  827. strFileName = stScriptUrlResp.strURL.substr(nPos2 + strlen("&fileName="));
  828. // 保存目录;
  829. stScriptUrlResp._strFileDir = strSaveDir;
  830. strSaveDir.append(strFileName);
  831. // 替换无效的目录字符;
  832. strSaveDir = GLOBAL::Replace(strSaveDir, "\\", "/");
  833. // 创建目录;
  834. if ( MKDIR(strSaveDir.c_str()) ) {
  835. // 同时下载脚本目录到指定目录中;// url地址可能包含中文,此处需要转码;
  836. stScriptUrlResp.strURL = CCurlClient::ParseURLAndEncode(stScriptUrlResp.strURL);
  837. GLOBAL::WriteTextLog("<======下载文件======> \r 文件地址:%s,保存路径:%s ", stScriptUrlResp.strURL.c_str(), strSaveDir.c_str());
  838. if ( g_curl.Download(stScriptUrlResp.strURL, strSaveDir, 20000) ) {
  839. stScriptUrlResp._strFileName = strFileName.substr(0, strFileName.find_last_of('.'));
  840. stScriptUrlResp._strScripFile = strSaveDir;
  841. // 释放内存;
  842. cJSON_Delete(pRoot);
  843. // 返回结果;
  844. return TRUE;
  845. }
  846. else
  847. {
  848. GLOBAL::WriteTextLog(_T("【Error】下载脚本失败:%s"), stScriptUrlResp.strURL.c_str());
  849. }
  850. }
  851. GLOBAL::WriteTextLog(_T("【Error】创建目录失败:%s"), strSaveDir.c_str());
  852. }
  853. }
  854. }
  855. }
  856. }
  857. else
  858. {
  859. GLOBAL::WriteTextLog(_T("【Error】文件不可下载:%s"), reponse.c_str());
  860. }
  861. }
  862. // 错误产生,可输出msg方便查询;
  863. cJSON_Delete(pRoot);
  864. }
  865. }
  866. }
  867. SETLOG;
  868. return FALSE;
  869. }
  870. SATHTTP_API int StopTaskFromRunner(std::string url, std::string strInstnaceId, SATHTTP::STStopTaskResp &stStopTaskResp)
  871. {
  872. // 转化为Json;
  873. cJSON *pRoot = cJSON_CreateObject();
  874. if ( pRoot == NULL )
  875. {
  876. return -1;
  877. }
  878. cJSON_AddStringToObject(pRoot, "sysCode", "");
  879. cJSON_AddStringToObject(pRoot, "function", "");
  880. cJSON *pData = cJSON_CreateObject();
  881. if ( pData )
  882. {
  883. cJSON_AddStringToObject(pData, "instanceId", strInstnaceId.c_str());
  884. // 添加到根结点中;
  885. cJSON_AddItemToObject(pRoot, "data", pData);
  886. }
  887. char *pText = cJSON_Print(pRoot);
  888. std::string post_data = "requestMsg=";
  889. post_data.append(CharEncoding::EnCode_UTF8URL(pText));
  890. // 释放堆内存;
  891. if (pText)
  892. delete pText;
  893. pText = NULL;
  894. if ( pRoot )
  895. cJSON_Delete(pRoot);
  896. pRoot = NULL;
  897. std::string reponse;
  898. CURLcode curlCode = CURLE_OK;
  899. if ( g_curl.IsInit() )
  900. {
  901. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  902. curlCode = g_curl.Posts(url, post_data, reponse);
  903. else
  904. curlCode = g_curl.Post(url, post_data, reponse);
  905. if ( curlCode == CURLE_OK )
  906. {
  907. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  908. // 解析返回值;
  909. pRoot = cJSON_Parse(reponse.c_str());
  910. if (pRoot != NULL)
  911. {
  912. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  913. if ( pMsg )
  914. {
  915. stStopTaskResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  916. stStopTaskResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  917. stStopTaskResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  918. stStopTaskResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  919. if ( stStopTaskResp.strCode == "00" )
  920. {
  921. // 释放内存;
  922. cJSON_Delete(pRoot);
  923. // 返回结果;
  924. return TRUE;
  925. }
  926. }
  927. // 错误产生,可输出msg方便查询;
  928. cJSON_Delete(pRoot);
  929. }
  930. }
  931. }
  932. SETLOG;
  933. return FALSE;
  934. }
  935. SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATHTTP::STSaveLogReq &stSaveLogReq, SATHTTP::STSaveLogResp &stSaveLogResp)
  936. {
  937. // 转化为Json;
  938. cJSON *pRoot = cJSON_CreateObject();
  939. if ( pRoot == NULL )
  940. {
  941. return -1;
  942. }
  943. cJSON_AddStringToObject(pRoot, "useId", stSaveLogReq.strUserId.c_str());
  944. cJSON *pData = cJSON_CreateObject();
  945. if ( pData )
  946. {
  947. cJSON_AddStringToObject(pData, "fileType", stSaveLogReq.strFileType.c_str());
  948. cJSON_AddStringToObject(pData, "caseId", stSaveLogReq.strCaseId.c_str());
  949. cJSON_AddStringToObject(pData, "taskId", stSaveLogReq.strTaskId.c_str());
  950. cJSON_AddStringToObject(pData, "executeId", stSaveLogReq.strExecuteId.c_str());
  951. cJSON_AddStringToObject(pData, "roundNum", stSaveLogReq.strRoundNum.c_str());
  952. // 添加到根结点中;
  953. cJSON_AddItemToObject(pRoot, "data", pData);
  954. }
  955. char *pText = cJSON_Print(pRoot);
  956. //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
  957. // POST表单提交,此处不需要转url格式,注意避坑!
  958. std::string post_data = pText;
  959. // 释放堆内存;
  960. if (pText)
  961. delete pText;
  962. pText = NULL;
  963. if ( pRoot )
  964. cJSON_Delete(pRoot);
  965. pRoot = NULL;
  966. std::string reponse;
  967. CURLcode curlCode = CURLE_OK;
  968. if ( g_curl.IsInit() )
  969. {
  970. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  971. curlCode = g_curl.Posts(url, post_data, reponse);
  972. else
  973. curlCode = g_curl.PostFile(url, post_data, stSaveLogReq.strUploads, reponse);
  974. if ( curlCode == CURLE_OK )
  975. {
  976. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  977. // 解析返回值;
  978. pRoot = cJSON_Parse(reponse.c_str());
  979. if (pRoot != NULL)
  980. {
  981. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  982. if ( pMsg )
  983. {
  984. stSaveLogResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  985. stSaveLogResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  986. stSaveLogResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  987. stSaveLogResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
  988. if ( stSaveLogResp.strCode == "00" )
  989. {
  990. // 释放内存;
  991. cJSON_Delete(pRoot);
  992. // 返回结果;
  993. return TRUE;
  994. }
  995. }
  996. // 错误产生,可输出msg方便查询;
  997. cJSON_Delete(pRoot);
  998. }
  999. }
  1000. }
  1001. SETLOG;
  1002. return FALSE;
  1003. }
  1004. SATHTTP_API int SaveResultFile(std::string url, const SATHTTP::STSaveFileReq &stSaveFileReq, SATHTTP::STSaveFileResp &stSaveFileResp)
  1005. {
  1006. // 转化为Json;
  1007. cJSON *pRoot = cJSON_CreateObject();
  1008. if ( pRoot == NULL )
  1009. {
  1010. return -1;
  1011. }
  1012. cJSON_AddStringToObject(pRoot, "sysCode", "");
  1013. cJSON_AddStringToObject(pRoot, "function", "");
  1014. cJSON *pData = cJSON_CreateObject();
  1015. if ( pData )
  1016. {
  1017. cJSON_AddStringToObject(pData, "roundNum", stSaveFileReq.strRoundNum.c_str());
  1018. cJSON_AddStringToObject(pData, "caseRepeat", stSaveFileReq.strCaseRepeat.c_str());
  1019. cJSON_AddStringToObject(pData, "jobRepeat", stSaveFileReq.strJobRepeat.c_str());
  1020. cJSON_AddStringToObject(pData, "instanceId", stSaveFileReq.strInstanceId.c_str());
  1021. cJSON_AddStringToObject(pData, "deviceId", stSaveFileReq.strDeviceId.c_str());
  1022. cJSON_AddStringToObject(pData, "executeId", stSaveFileReq.strExecuteId.c_str());
  1023. cJSON_AddStringToObject(pData, "taskName", stSaveFileReq.strTaskName.c_str());
  1024. cJSON_AddStringToObject(pData, "sceneIndex", stSaveFileReq.strSceneIndex.c_str());
  1025. cJSON_AddStringToObject(pData, "taskId", stSaveFileReq.strTaskId.c_str());
  1026. cJSON_AddStringToObject(pData, "caseId", stSaveFileReq.strCaseId.c_str());
  1027. cJSON_AddStringToObject(pData, "deviceName", stSaveFileReq.strDeviceName.c_str());
  1028. cJSON_AddStringToObject(pData, "runnerName", stSaveFileReq.strRunnerName.c_str());
  1029. cJSON_AddStringToObject(pData, "runnerIP", stSaveFileReq.strRunnerIP.c_str());
  1030. cJSON_AddStringToObject(pData, "runnerMac", stSaveFileReq.strRunnerMAC.c_str());
  1031. cJSON_AddStringToObject(pData, "caseName", stSaveFileReq.strCaseName.c_str());
  1032. cJSON_AddStringToObject(pData, "caseIndex", stSaveFileReq.strCaseIndex.c_str());
  1033. cJSON_AddStringToObject(pData, "taskRepeat", stSaveFileReq.strTaskRepeat.c_str());
  1034. cJSON_AddStringToObject(pData, "busCode", stSaveFileReq.strBusCode.c_str());
  1035. cJSON_AddStringToObject(pData, "fileType", stSaveFileReq.strFileType.c_str());
  1036. cJSON_AddStringToObject(pData, "caseStep", stSaveFileReq.strCaseStep.c_str());
  1037. // 添加到根结点中;
  1038. cJSON_AddItemToObject(pRoot, "data", pData);
  1039. }
  1040. char *pText = cJSON_Print(pRoot);
  1041. //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
  1042. // POST表单提交,此处不需要转url格式,注意避坑!
  1043. std::string post_data = pText;
  1044. // 释放堆内存;
  1045. if (pText)
  1046. delete pText;
  1047. pText = NULL;
  1048. if ( pRoot )
  1049. cJSON_Delete(pRoot);
  1050. pRoot = NULL;
  1051. std::string reponse;
  1052. CURLcode curlCode = CURLE_OK;
  1053. if ( g_curl.IsInit() )
  1054. {
  1055. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  1056. curlCode = g_curl.Posts(url, post_data, reponse);
  1057. else
  1058. curlCode = g_curl.PostFile(url, post_data, stSaveFileReq.strUploads, reponse);
  1059. if ( curlCode == CURLE_OK )
  1060. {
  1061. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  1062. // 解析返回值;
  1063. pRoot = cJSON_Parse(reponse.c_str());
  1064. if (pRoot != NULL)
  1065. {
  1066. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  1067. if ( pMsg )
  1068. {
  1069. stSaveFileResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  1070. stSaveFileResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  1071. stSaveFileResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  1072. stSaveFileResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
  1073. if ( stSaveFileResp.strCode == "00" )
  1074. {
  1075. // 释放内存;
  1076. cJSON_Delete(pRoot);
  1077. // 返回结果;
  1078. return TRUE;
  1079. }
  1080. }
  1081. // 错误产生,可输出msg方便查询;
  1082. cJSON_Delete(pRoot);
  1083. }
  1084. }
  1085. }
  1086. SETLOG;
  1087. return FALSE;
  1088. }
  1089. SATHTTP_API int SaveResultImg(std::string url, const SATHTTP::STSaveImgReq &stSaveImgReq, SATHTTP::STSaveImgResp &stSaveImgResp)
  1090. {
  1091. // 转化为Json;
  1092. cJSON *pRoot = cJSON_CreateObject();
  1093. if ( pRoot == NULL )
  1094. {
  1095. return -1;
  1096. }
  1097. cJSON_AddStringToObject(pRoot, "sysCode", "");
  1098. cJSON_AddStringToObject(pRoot, "function", "");
  1099. cJSON *pData = cJSON_CreateObject();
  1100. if ( pData )
  1101. {
  1102. cJSON_AddStringToObject(pData, "instanceId", stSaveImgReq.strInstanceId.c_str());
  1103. cJSON_AddStringToObject(pData, "deviceId", stSaveImgReq.strDeviceId.c_str());
  1104. cJSON_AddStringToObject(pData, "roundNum", stSaveImgReq.strRoundNum.c_str());
  1105. cJSON_AddStringToObject(pData, "caseId", stSaveImgReq.strCaseId.c_str());
  1106. cJSON_AddStringToObject(pData, "step", stSaveImgReq.strCaseStep.c_str());
  1107. cJSON_AddStringToObject(pData, "type", stSaveImgReq.strImgType.c_str());
  1108. cJSON_AddStringToObject(pData, "executeId", stSaveImgReq.strExecuteId.c_str());
  1109. cJSON_AddStringToObject(pData, "caseRepeat", stSaveImgReq.strCaseRepeat.c_str());
  1110. cJSON_AddStringToObject(pData, "jobRepeat", stSaveImgReq.strJobRepeat.c_str());
  1111. // 添加到根结点中;
  1112. cJSON_AddItemToObject(pRoot, "data", pData);
  1113. }
  1114. char *pText = cJSON_Print(pRoot);
  1115. //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
  1116. // POST表单提交,此处不需要转url格式,注意避坑!
  1117. std::string post_data = pText;
  1118. // 释放堆内存;
  1119. if (pText)
  1120. delete pText;
  1121. pText = NULL;
  1122. if ( pRoot )
  1123. cJSON_Delete(pRoot);
  1124. pRoot = NULL;
  1125. std::string reponse;
  1126. CURLcode curlCode = CURLE_OK;
  1127. if ( g_curl.IsInit() )
  1128. {
  1129. if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
  1130. curlCode = g_curl.Posts(url, post_data, reponse);
  1131. else
  1132. curlCode = g_curl.PostFile(url, post_data, stSaveImgReq.strUploads, reponse);
  1133. if ( curlCode == CURLE_OK )
  1134. {
  1135. reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
  1136. // 解析返回值;
  1137. pRoot = cJSON_Parse(reponse.c_str());
  1138. if (pRoot != NULL)
  1139. {
  1140. cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
  1141. if ( pMsg )
  1142. {
  1143. stSaveImgResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
  1144. stSaveImgResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
  1145. stSaveImgResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
  1146. stSaveImgResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
  1147. if ( stSaveImgResp.strCode == "00" )
  1148. {
  1149. // 释放内存;
  1150. cJSON_Delete(pRoot);
  1151. // 返回结果;
  1152. return TRUE;
  1153. }
  1154. }
  1155. // 错误产生,可输出msg方便查询;
  1156. cJSON_Delete(pRoot);
  1157. }
  1158. }
  1159. }
  1160. SETLOG;
  1161. return FALSE;
  1162. }