SATHTTP.cpp 49 KB

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