1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318 |
- // SATHTTP.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include "SATHTTP.h"
- #include <direct.h>
- CCurlClient g_curl;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- __if_not_exists(NotifyJobStart)
- {
- int NotifyJobStart(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp) throw()
- {
- return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
- }
- }
- __if_not_exists(ProcessJob)
- {
- int ProcessJob(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp) throw()
- {
- return SetResultList(url, stJobProcessReq, stJobProcessResp);
- }
- }
- #define SETLOG GLOBAL::WriteTextLog("<======请求失败======> \r接口名称:%s \r错误码值:%ld \r请求内容:%s \r返回内容:%s", __FUNCDNAME__, curlCode, post_data.c_str(), reponse.c_str())
- #ifdef __CONSOLE__
- // 唯一的应用程序对象
- CWinApp theApp;
- using namespace std;
- bool MKDIR(LPCTSTR dir);
- __if_not_exists(NotifyJobStart)
- {
- int NotifyJobStart(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp) throw()
- {
- return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
- }
- }
- __if_not_exists(ProcessJob)
- {
- int ProcessJob(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp) throw()
- {
- return SetResultList(url, stJobProcessReq, stJobProcessResp);
- }
- }
- int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
- {
- int nRetCode = 0;
- // 初始化 MFC 并在失败时显示错误
- if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
- {
- // TODO: 更改错误代码以符合您的需要
- _tprintf(_T("错误: MFC 初始化失败\n"));
- nRetCode = 1;
- }
- else
- {
- UrlPars ups;
- 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";
- CCurlClient::ParseURL(host, ups);
- for ( std::map<std::string,std::string>::iterator it = ups.pars.begin(); it != ups.pars.end(); it++ ) {
- it->second = CharEncoding::EnCode_UTF8URL(it->second.c_str());
- }
- printf("----\n");
- }
- system("pause");
- return nRetCode;
- }
- #endif //__CONSOLE__
- bool MKDIR(LPCTSTR dir)
- {
- //////////////////////////////////////////////////////////////////////////
- // 创建目录;
- int nleft = 0;
- int nIndex = -1;
- std::string strdir = dir;
- strdir = strdir.substr(0, strdir.find_last_of(_T("\\")));
- if (strdir.at(strdir.size() - 1) != _T('\\'))
- strdir.append(_T("\\"));
- // 共享路径和硬盘盘符;
- if (_tcscmp(strdir.substr(0, 2).c_str(), _T("\\\\")) == 0)
- nleft = strdir.find_first_of(_T("\\"), 2) + 1; // 去除共享主机名;
- else if (strdir.at(2) == _T('\\'))
- nleft = 3;
- do
- {
- nIndex = strdir.substr(nleft, -1).find_first_of(_T("\\"));
- if (nIndex != string::npos)
- {
- if (_mkdir(strdir.substr(0, nIndex + nleft).c_str()) == -1 && (errno != EEXIST))
- {
- return false;
- }
- nleft += nIndex + 1;
- }
- } while (nIndex != -1);
- return true;
- };
- SATHTTP_API int Login(std::string url, const SATHTTP::STLoginReq &stLoginReq, SATHTTP::STLoginResp &stLoginResp)
- {
- if ( !g_curl.IsInit() )
- g_curl.Initialize();
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "function", "aaaa");
- cJSON_AddStringToObject(pRoot, "sysCode", "EXECUTE");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- cJSON_AddStringToObject(pData, "userName", stLoginReq.strUserName.c_str());
- cJSON_AddStringToObject(pData, "status", stLoginReq.strStatus.c_str());
- cJSON_AddStringToObject(pData, "deleteStatus", stLoginReq.strDeleteStatus.c_str());
- cJSON_AddStringToObject(pData, "ip", stLoginReq.strIP.c_str());
- cJSON_AddStringToObject(pData, "memory", stLoginReq.strMemory.c_str());
- cJSON_AddStringToObject(pData, "storage", stLoginReq.strStorage.c_str());
- cJSON_AddStringToObject(pData, "connectTime", stLoginReq.strConnectTime.c_str());
- cJSON_AddStringToObject(pData, "executeName", stLoginReq.strExecuteName.c_str());
- cJSON_AddStringToObject(pData, "mac", stLoginReq.strMAC.c_str());
- cJSON_AddStringToObject(pData, "disconnectTime", stLoginReq.strDisconnectTime.c_str());
- cJSON_AddStringToObject(pData, "password", stLoginReq.strPassword.c_str());
- cJSON_AddStringToObject(pData, "cpu", stLoginReq.strCPU.c_str());
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stLoginResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stLoginResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stLoginResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- if ( stLoginResp.strCode == "00" )
- {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL)
- {
- stLoginResp.nPortCount = cJSON_GetObjectItem(pObj, "portCount") ? cJSON_GetObjectItem(pObj, "portCount")->valueint : -1;
- stLoginResp.nCompanyId = cJSON_GetObjectItem(pObj, "companyId") ? cJSON_GetObjectItem(pObj, "companyId")->valueint : -1;
- stLoginResp.strRunnerToken = cJSON_GetObjectItem(pObj, "runnerToken") ? cJSON_GetObjectItem(pObj, "runnerToken")->valuestring : "";
- }
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int UpdateDeviceMessage(std::string url, const SATHTTP::STUpdateDeviceReq &stUpdateDeviceReq, SATHTTP::STUpdateDeviceResp &stUpdateDeviceResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "status", stUpdateDeviceReq.strStatus.c_str());
- cJSON_AddStringToObject(pData, "userName", stUpdateDeviceReq.strUserName.c_str());
- cJSON_AddStringToObject(pData, "ip", stUpdateDeviceReq.strIP.c_str());
- cJSON_AddStringToObject(pData, "storage", stUpdateDeviceReq.strStorage.c_str());
- cJSON_AddStringToObject(pData, "runnerName", stUpdateDeviceReq.strRunnerName.c_str());
- cJSON_AddStringToObject(pData, "mac", stUpdateDeviceReq.strMAC.c_str());
- cJSON_AddStringToObject(pData, "reportType", stUpdateDeviceReq.strReportType.c_str());
- cJSON_AddStringToObject(pData, "startTime", stUpdateDeviceReq.strStartTime.c_str());
- cJSON_AddStringToObject(pData, "memory", stUpdateDeviceReq.strMemory.c_str());
- cJSON_AddStringToObject(pData, "endTime", stUpdateDeviceReq.strEndTime.c_str());
- cJSON_AddStringToObject(pData, "cpu", stUpdateDeviceReq.strCPU.c_str());
- cJSON *pDeviceList = cJSON_CreateArray();
- if ( pDeviceList )
- {
- cJSON_AddItemToObject(pData, "devicelist", pDeviceList);
- for ( std::vector<SATHTTP::STDevice>::const_iterator it = stUpdateDeviceReq.devicelist.begin(); it != stUpdateDeviceReq.devicelist.end(); it++ )
- {
- cJSON *pObj = cJSON_CreateObject();
- if ( pObj )
- {
- cJSON_AddStringToObject(pObj, "status", it->strStatus.c_str());
- cJSON_AddStringToObject(pObj, "deviceSerial", it->strDeviceSerial.c_str());
- cJSON_AddStringToObject(pObj, "hardwareVersion", it->strHardwareVersion.c_str());
- cJSON_AddStringToObject(pObj, "manu", it->strManu.c_str());
- cJSON_AddStringToObject(pObj, "deviceMac", it->strDeviceMac.c_str());
- cJSON_AddStringToObject(pObj, "lastJobStartTime", it->strLastJobStartTime.c_str());
- cJSON_AddStringToObject(pObj, "lastTimeBreak", it->strLastTimeBreak.c_str());
- cJSON_AddStringToObject(pObj, "comments", it->strComments.c_str());
- cJSON_AddStringToObject(pObj, "cpu", it->strCPU.c_str());
- cJSON_AddStringToObject(pObj, "softwareVersion", it->strSoftwareVersion.c_str());
- cJSON_AddStringToObject(pObj, "phoneNumber", it->strPhoneNumber.c_str());
- cJSON_AddStringToObject(pObj, "lastJobFinishTime", it->strLastJobFinishTime.c_str());
- cJSON_AddStringToObject(pObj, "memory", it->strMemory.c_str());
- cJSON_AddStringToObject(pObj, "model", it->strModel.c_str());
- cJSON_AddStringToObject(pObj, "lastJob", it->strLastJob.c_str());
- cJSON_AddStringToObject(pObj, "lastTimeConnected", it->strLastTimeConnected.c_str());
- cJSON_AddStringToObject(pObj, "electric", it->strElectric.c_str());
- cJSON_AddItemToObject(pDeviceList, "", pObj);
- }
- }
- }
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stUpdateDeviceResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stUpdateDeviceResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stUpdateDeviceResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- if ( stUpdateDeviceResp.strCode == "00" )
- {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL)
- {
-
- }
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int Heartbeat(std::string url, const SATHTTP::STHeartbeatReq &stHeartbeatReq, SATHTTP::STHeartbeatResp &stHeartbeatResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "EXECUTE");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "userName", stHeartbeatReq.strUserName.c_str());
- cJSON_AddStringToObject(pData, "runnerMac", stHeartbeatReq.strRunnerMac.c_str());
- cJSON *pDeviceList = cJSON_CreateArray();
- if ( pDeviceList )
- {
- cJSON_AddItemToObject(pData, "deviceList", pDeviceList);
- for ( std::vector<SATHTTP::STDevice>::const_iterator it = stHeartbeatReq.devicelist.begin(); it != stHeartbeatReq.devicelist.end(); it++ )
- {
- cJSON *pObj = cJSON_CreateObject();
- if ( pObj )
- {
- cJSON_AddStringToObject(pObj, "status", it->strStatus.c_str());
- cJSON_AddStringToObject(pObj, "deviceSerial", it->strDeviceSerial.c_str());
- cJSON_AddItemToObject(pDeviceList, "", pObj);
- }
- }
- }
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- #if 1
- std::string log = "查询参数:requestMsg=";
- log.append(pText);
- log.append(_T("\n"));
- OutputDebugString(log.c_str());
- #endif
- post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- #if 1
- std::string log = "结果参数:";
- log.append(reponse+_T("\n"));
- OutputDebugString(reponse.c_str());
- #endif
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stHeartbeatResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stHeartbeatResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stHeartbeatResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- if ( stHeartbeatResp.strCode == "00" )
- {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL)
- {
- GLOBAL::WriteTextLog("<======heartbeat json======> \r 请求内容:%s \r返回内容:%s", post_data.c_str(), reponse.c_str());
- int nSise = cJSON_GetArraySize(pObj);
- for ( int i = 0; i < nSise; i++ )
- {
- cJSON *pTask = cJSON_GetArrayItem(pObj, i);
- if ( pTask )
- {
- SATHTTP::STTask stTask;
- stTask.taskInfo.strInstanceName = cJSON_GetObjectItem(pTask, "instanceName") ? cJSON_GetObjectItem(pTask, "instanceName")->valuestring : "";
- stTask.taskInfo.strExecutionStatus = cJSON_GetObjectItem(pTask, "executionStatus") ? cJSON_GetObjectItem(pTask, "executionStatus")->valuestring : "";
- stTask.taskInfo.strInstanceType = cJSON_GetObjectItem(pTask, "instanceType") ? cJSON_GetObjectItem(pTask, "instanceType")->valuestring : "";
- stTask.taskInfo.nExecuteId = cJSON_GetObjectItem(pTask, "executeId") ? cJSON_GetObjectItem(pTask, "executeId")->valueint : -1;
- stTask.taskInfo.strRequestIP = cJSON_GetObjectItem(pTask, "requestIp") ? cJSON_GetObjectItem(pTask, "requestIp")->valuestring : "";
- stTask.taskInfo.strTaskUseType = cJSON_GetObjectItem(pTask, "taskUseType") ? cJSON_GetObjectItem(pTask, "taskUseType")->valuestring : "";
- stTask.taskInfo.nDeviceId = cJSON_GetObjectItem(pTask, "deviceId") ? cJSON_GetObjectItem(pTask, "deviceId")->valueint : -1;
- stTask.taskInfo.strDiffTaskInstanceFlag = cJSON_GetObjectItem(pTask, "diffTaskInstanceFlag") ? cJSON_GetObjectItem(pTask, "diffTaskInstanceFlag")->valuestring : "";
- stTask.taskInfo.strTaskType = cJSON_GetObjectItem(pTask, "taskType") ? cJSON_GetObjectItem(pTask, "taskType")->valuestring : "";
- stTask.taskInfo.nInstanceId = cJSON_GetObjectItem(pTask, "instanceId") ? cJSON_GetObjectItem(pTask, "instanceId")->valueint : -1;
- stTask.taskInfo.strProgress = cJSON_GetObjectItem(pTask, "progress") ? cJSON_GetObjectItem(pTask, "progress")->valuestring : "";
- stTask.taskInfo.strStartTime = cJSON_GetObjectItem(pTask, "startTime") ? cJSON_GetObjectItem(pTask, "startTime")->valuestring : "";
- stTask.taskInfo.strStopTime = cJSON_GetObjectItem(pTask, "stopTime") ? cJSON_GetObjectItem(pTask, "stopTime")->valuestring : "";
- stTask.taskInfo.strTaskName = cJSON_GetObjectItem(pTask, "taskName") ? cJSON_GetObjectItem(pTask, "taskName")->valuestring : "";
- stTask.taskInfo.Id = cJSON_GetObjectItem(pTask, "id") ? cJSON_GetObjectItem(pTask, "id")->valueint : -1;
- stTask.taskInfo.fd = cJSON_GetObjectItem(pTask, "fd") ? cJSON_GetObjectItem(pTask, "fd")->valueint : -1;
- stTask.taskInfo.nTaskId = cJSON_GetObjectItem(pTask, "taskId") ? cJSON_GetObjectItem(pTask, "taskId")->valueint : -1;
- //stTask.taskInfo.strTaskId = cJSON_GetObjectItem(pTask, "taskId") ? cJSON_GetObjectItem(pTask, "taskId")->valuestring : "0";
- // email其实可忽略;
- cJSON *pEmals = cJSON_GetObjectItem(pTask, "emails");
- if ( pEmals )
- {
- int nEmailSize = cJSON_GetArraySize(pEmals);
- for ( int ii = 0; ii < nEmailSize; ii++ )
- {
- cJSON *pEmail = cJSON_GetArrayItem(pEmals, ii);
- if ( pEmail )
- {
- std::string email = pEmail->valuestring;
- stTask.taskInfo.vtEmails.push_back(email);
- }
- }
- }
- cJSON *pSomkingCycle = cJSON_GetObjectItem(pTask, "SomkingCycle");
- if ( pSomkingCycle ) {
- // 冒烟任务周期;
- stTask.taskInfo.stSomkingCycle.nType = cJSON_GetObjectItem(pSomkingCycle, "type")->valueint;
- stTask.taskInfo.stSomkingCycle.nWeek = cJSON_GetObjectItem(pSomkingCycle, "week")->valueint;
- stTask.taskInfo.stSomkingCycle.nDay = cJSON_GetObjectItem(pSomkingCycle, "day")->valueint;
- stTask.taskInfo.stSomkingCycle.strTime = cJSON_GetObjectItem(pSomkingCycle, "time")->valuestring;
- }
- // Job内容;
- cJSON *pJob = cJSON_GetObjectItem(pTask, "taskJson");
- if ( pJob )
- {
- pJob = cJSON_GetObjectItem(pJob, "job");
- if ( pJob )
- {
- stTask.Job.strCloudPort = cJSON_GetObjectItem(pJob, "cloudPort") ? cJSON_GetObjectItem(pJob, "cloudPort")->valuestring : "";
- stTask.Job.strExecuteIP = cJSON_GetObjectItem(pJob, "executeIp") ? cJSON_GetObjectItem(pJob, "executeIp")->valuestring : "";
- stTask.Job.strMonkeyPctSysKeys = cJSON_GetObjectItem(pJob, "monkeyPctSyskeys") ? cJSON_GetObjectItem(pJob, "monkeyPctSyskeys")->valuestring : "";
- stTask.Job.strRedRatDeviceName = cJSON_GetObjectItem(pJob, "redRatDeviceName") ? cJSON_GetObjectItem(pJob, "redRatDeviceName")->valuestring : "";
- stTask.Job.strExecuteId = cJSON_GetObjectItem(pJob, "executeId") ? cJSON_GetObjectItem(pJob, "executeId")->valuestring : "";
- stTask.Job.strMonkeyPctAppSwitch = cJSON_GetObjectItem(pJob, "monkeyPctAppswitch") ? cJSON_GetObjectItem(pJob, "monkeyPctAppswitch")->valuestring : "";
- stTask.Job.strDeviceId = cJSON_GetObjectItem(pJob, "deviceId") ? cJSON_GetObjectItem(pJob, "deviceId")->valuestring : "";
- stTask.Job.strLoopNumber = cJSON_GetObjectItem(pJob, "loopNumber") ? cJSON_GetObjectItem(pJob, "loopNumber")->valuestring : "";
- stTask.Job.strTaskType = cJSON_GetObjectItem(pJob, "taskType") ? cJSON_GetObjectItem(pJob, "taskType")->valuestring : "";
- stTask.Job.strMonkeyFrequency = cJSON_GetObjectItem(pJob, "monkeyFrequency") ? cJSON_GetObjectItem(pJob, "monkeyFrequency")->valuestring : "";
- stTask.Job.strCloudVersion = cJSON_GetObjectItem(pJob, "cloudVersion") ? cJSON_GetObjectItem(pJob, "cloudVersion")->valuestring : "";
- stTask.Job.strTaskInstanceName = cJSON_GetObjectItem(pJob, "taskInstanceName") ? cJSON_GetObjectItem(pJob, "taskInstanceName")->valuestring : "";
- stTask.Job.strRepeatRunTime = cJSON_GetObjectItem(pJob, "repeatRunTime") ? cJSON_GetObjectItem(pJob, "repeatRunTime")->valuestring : "";
- stTask.Job.strMonkeyTime = cJSON_GetObjectItem(pJob, "monkeyTime") ? cJSON_GetObjectItem(pJob, "monkeyTime")->valuestring : "";
- stTask.Job.strOutEquipmentId = cJSON_GetObjectItem(pJob, "outEquipmentId") ? cJSON_GetObjectItem(pJob, "outEquipmentId")->valuestring : "";
- stTask.Job.strPoweroff = cJSON_GetObjectItem(pJob, "poweroff") ? cJSON_GetObjectItem(pJob, "poweroff")->valuestring : "";
- stTask.Job.strFilePath = cJSON_GetObjectItem(pJob, "filePath") ? cJSON_GetObjectItem(pJob, "filePath")->valuestring : "";
- stTask.Job.strScriptFailRepeart = cJSON_GetObjectItem(pJob, "scriptFailRepeat") ? cJSON_GetObjectItem(pJob, "scriptFailRepeat")->valuestring : "";
- stTask.Job.strTaskInstanceId = cJSON_GetObjectItem(pJob, "taskInstanceId") ? cJSON_GetObjectItem(pJob, "taskInstanceId")->valuestring : "";
- stTask.Job.strUserId = cJSON_GetObjectItem(pJob, "userId") ? cJSON_GetObjectItem(pJob, "userId")->valuestring : "";
- stTask.Job.strDiffTaskInstanceFlag = cJSON_GetObjectItem(pJob, "diffTaskInstanceFlag") ? cJSON_GetObjectItem(pJob, "diffTaskInstanceFlag")->valuestring : "";
- stTask.Job.strBusCode = cJSON_GetObjectItem(pJob, "busCode") ? cJSON_GetObjectItem(pJob, "busCode")->valuestring : "";
- stTask.Job.strRound = cJSON_GetObjectItem(pJob, "round") ? cJSON_GetObjectItem(pJob, "round")->valuestring : "";
- stTask.Job.strControlType = cJSON_GetObjectItem(pJob, "controlType") ? cJSON_GetObjectItem(pJob, "controlType")->valuestring : "";
- stTask.Job.strMonkeyPctMajornav = cJSON_GetObjectItem(pJob, "monkeyPctMajornav") ? cJSON_GetObjectItem(pJob, "monkeyPctMajornav")->valuestring : "";
- stTask.Job.strTaskName = cJSON_GetObjectItem(pJob, "taskName") ? cJSON_GetObjectItem(pJob, "taskName")->valuestring : "";
- stTask.Job.strMonkeyType = cJSON_GetObjectItem(pJob, "monkeyType") ? cJSON_GetObjectItem(pJob, "monkeyType")->valuestring : "";
- stTask.Job.strMonkeyDictate = cJSON_GetObjectItem(pJob, "monkeyDictate") ? cJSON_GetObjectItem(pJob, "monkeyDictate")->valuestring : "";
- stTask.Job.strDetectedDeviceName = cJSON_GetObjectItem(pJob, "detectedDeviceName") ? cJSON_GetObjectItem(pJob, "detectedDeviceName")->valuestring : "";
- stTask.Job.strExecuteName = cJSON_GetObjectItem(pJob, "executeName") ? cJSON_GetObjectItem(pJob, "executeName")->valuestring : "";
- stTask.Job.strProjectName = cJSON_GetObjectItem(pJob, "projectName") ? cJSON_GetObjectItem(pJob, "projectName")->valuestring : "";
- stTask.Job.strProjectId = cJSON_GetObjectItem(pJob, "projectId") ? cJSON_GetObjectItem(pJob, "projectId")->valuestring : "";
- stTask.Job.strUniqueId = cJSON_GetObjectItem(pJob, "uniqueId") ? cJSON_GetObjectItem(pJob, "uniqueId")->valuestring : "";
- stTask.Job.strTaskId = cJSON_GetObjectItem(pJob, "taskId") ? cJSON_GetObjectItem(pJob, "taskId")->valuestring : "";
- stTask.Job.strSoftwareVersion = cJSON_GetObjectItem(pJob, "softwareVersion") ? cJSON_GetObjectItem(pJob, "softwareVersion")->valuestring : "";
- stTask.Job.strMonkeyPctNav = cJSON_GetObjectItem(pJob, "monkeyPctNav") ? cJSON_GetObjectItem(pJob, "monkeyPctNav")->valuestring : "";
- // emails,已重复,忽略;
- // cJSON *pEmals = cJSON_GetObjectItem(pJob, "emails");
- // case list;
- cJSON *pCaseList = cJSON_GetObjectItem(pJob, "caseList");
- if ( pCaseList )
- {
- int nCaseSize = cJSON_GetArraySize(pCaseList);
- for ( int ii = 0; ii < nCaseSize; ii++ )
- {
- cJSON *pCase = cJSON_GetArrayItem(pCaseList, ii);
- if ( pCase )
- {
- SATHTTP::STCase stCase;
- stCase.strIndex = cJSON_GetObjectItem(pCase, "index") ? cJSON_GetObjectItem(pCase, "index")->valuestring : "";
- stCase.strCaseName = cJSON_GetObjectItem(pCase, "caseName") ? cJSON_GetObjectItem(pCase, "caseName")->valuestring : "";
- stCase.strMainFilePath = cJSON_GetObjectItem(pCase, "mainFilePath") ? cJSON_GetObjectItem(pCase, "mainFilePath")->valuestring : "";
- stCase.strId = cJSON_GetObjectItem(pCase, "id") ? cJSON_GetObjectItem(pCase, "id")->valuestring : "";
- stCase.strCaseType = cJSON_GetObjectItem(pCase, "caseType") ? cJSON_GetObjectItem(pCase, "caseType")->valuestring : "";
- // 压入Job;
- stTask.vtCases.push_back(stCase);
- }
- }
- }
- }
- }
- // 保存任务信息;
- stHeartbeatResp.vtTask.push_back(stTask);
- }
- }
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int SetResult(std::string url, const SATHTTP::STNotifyJobStartReq &stNotifyJobStartReq, SATHTTP::STNotifyJobStartResp &stNotifyJobStartResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "");
- cJSON_AddStringToObject(pRoot, "function", "");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "instanceId", stNotifyJobStartReq.strInstanceId.c_str());
- cJSON_AddStringToObject(pData, "signalImageUrl", stNotifyJobStartReq.strSignalImageUrl.c_str());
- cJSON_AddStringToObject(pData, "deviceId", stNotifyJobStartReq.strDeviceId.c_str());
- cJSON_AddStringToObject(pData, "taskId", stNotifyJobStartReq.strTaskId.c_str());
- cJSON_AddStringToObject(pData, "executeId", stNotifyJobStartReq.strExecuteId.c_str());
-
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- post_data.append(pText);
- //post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stNotifyJobStartResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stNotifyJobStartResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stNotifyJobStartResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- if ( stNotifyJobStartResp.strCode == "00" )
- {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL)
- {
-
- }
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int SetResultList(std::string url, const SATHTTP::STJobProcessReq &stJobProcessReq, SATHTTP::STJobProcessResp &stJobProcessResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
- cJSON_AddStringToObject(pRoot, "function", "setResultList");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "result_state", stJobProcessReq.strResultState.c_str());
- cJSON_AddStringToObject(pData, "case_scene", stJobProcessReq.strCaseScene.c_str());
- cJSON_AddStringToObject(pData, "case_step", stJobProcessReq.strCaseStep.c_str());
- cJSON_AddStringToObject(pData, "apkMd5", stJobProcessReq.strApkMD5.c_str());
- cJSON_AddStringToObject(pData, "crash_time", stJobProcessReq.strCrashTime.c_str());
- cJSON_AddStringToObject(pData, "runner_id", stJobProcessReq.strRunnerId.c_str());
- cJSON_AddStringToObject(pData, "cpu_info", stJobProcessReq.strCPUInfo.c_str());
- cJSON_AddStringToObject(pData, "runnedActionNameList", stJobProcessReq.strRunnedActionNameList.c_str());
- cJSON_AddStringToObject(pData, "artificial_result", stJobProcessReq.strArtificialResult.c_str());
- cJSON_AddStringToObject(pData, "artificial_modify", stJobProcessReq.strArtificialModify.c_str());
- cJSON_AddStringToObject(pData, "runner_name", stJobProcessReq.strRunnerName.c_str());
- cJSON_AddStringToObject(pData, "task_type", stJobProcessReq.strTaskType.c_str());
- cJSON_AddStringToObject(pData, "case_repeat", stJobProcessReq.strCaseRepeat.c_str());
- cJSON_AddStringToObject(pData, "application_group", stJobProcessReq.strApplicationGroup.c_str());
- cJSON_AddStringToObject(pData, "instanceId", stJobProcessReq.strInstanceId.c_str());
- cJSON_AddStringToObject(pData, "case_id", stJobProcessReq.strCaseId.c_str());
- cJSON_AddStringToObject(pData, "progress", stJobProcessReq.strProgress.c_str());
- cJSON_AddStringToObject(pData, "result_message", stJobProcessReq.strReusltMessage.c_str());
- cJSON_AddStringToObject(pData, "job_repeat", stJobProcessReq.strJobRepeat.c_str());
- cJSON_AddStringToObject(pData, "screenshot", stJobProcessReq.strScreenShot.c_str());
- cJSON_AddStringToObject(pData, "start_time", stJobProcessReq.strStartTime.c_str());
- cJSON_AddStringToObject(pData, "crash_number", stJobProcessReq.strCrashNumber.c_str());
- cJSON_AddStringToObject(pData, "case_name", stJobProcessReq.strCaseName.c_str());
- cJSON_AddStringToObject(pData, "failed_reason", stJobProcessReq.strFailedReason.c_str());
- cJSON_AddStringToObject(pData, "img_name", stJobProcessReq.strImgName.c_str());
- cJSON_AddStringToObject(pData, "case_index", stJobProcessReq.strCaseIndex.c_str());
- cJSON_AddStringToObject(pData, "device_id", stJobProcessReq.strDeviceId.c_str());
- cJSON_AddStringToObject(pData, "scene_index", stJobProcessReq.strSceneIndex.c_str());
- cJSON_AddStringToObject(pData, "task_id", stJobProcessReq.strTaskId.c_str());
- cJSON_AddStringToObject(pData, "analysis", stJobProcessReq.strAnalysis.c_str());
- cJSON_AddStringToObject(pData, "device_name", stJobProcessReq.strDevnceName.c_str());
- cJSON_AddStringToObject(pData, "info_type", stJobProcessReq.strInfoType.c_str());
- cJSON_AddStringToObject(pData, "memory_info", stJobProcessReq.strMemoryInfo.c_str());
- cJSON_AddStringToObject(pData, "end_time", stJobProcessReq.strEndTime.c_str());
- cJSON_AddStringToObject(pData, "round_number", stJobProcessReq.strRoundNumber.c_str());
- cJSON_AddStringToObject(pData, "result_type", stJobProcessReq.strResultType.c_str());
- cJSON_AddStringToObject(pData, "operation_step", stJobProcessReq.strOperationStep.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- post_data.append(CharEncoding::EnCode_GB2312URL(pText));
- //post_data.append(pText);
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stJobProcessResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stJobProcessResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stJobProcessResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- if ( stJobProcessResp.strCode == "00" )
- {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL)
- {
- stJobProcessResp.strIsDelete = cJSON_GetObjectItem(pObj, "isDelete") ? (cJSON_GetObjectItem(pObj, "isDelete")->valuestring ? cJSON_GetObjectItem(pObj, "isDelete")->valuestring : "") : "";
- }
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATHTTP::STScriptUrlResp &stScriptUrlResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
- cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
- stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
- if ( stScriptUrlResp.strCode == "00" )
- {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL)
- {
- if ( cJSON_GetArraySize(pObj) >= 1 )
- {
- cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
- if ( pScripURL )
- {
- stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
- // 同时下载脚本目录到指定目录中;
- }
- }
- }
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::string strSaveDir, SATHTTP::STScriptUrlResp &stScriptUrlResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "Execute");
- cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- GLOBAL::WriteTextLog("<======下载请求======> \r 请求内容:%s %s", url.c_str(), post_data.c_str());
- post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() ) {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK ) {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL) {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg ) {
- stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
- stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
- if ( stScriptUrlResp.strCode == "00" ) {
- cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
- if (pObj != NULL) {
- if ( cJSON_GetArraySize(pObj) >= 1 ) {
- cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
- if ( pScripURL ) {
- stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
- std::string strFileDir;
- std::string strFileName;
- int nPos1 = 0, nPos2 = 0;
- nPos1 = stScriptUrlResp.strURL.find("fileDir=");
- nPos2 = stScriptUrlResp.strURL.find("&fileName=");
- if ( nPos1 != std::string::npos && nPos2 != std::string::npos ) {
- strFileDir = stScriptUrlResp.strURL.substr(nPos1 + strlen("fileDir="), nPos2 - nPos1 - strlen("fileDir="));
- strFileName = stScriptUrlResp.strURL.substr(nPos2 + strlen("&fileName="));
- // 保存目录;
- stScriptUrlResp._strFileDir = strSaveDir;
- strSaveDir.append(strFileName);
- // 替换无效的目录字符;
- strSaveDir = GLOBAL::Replace(strSaveDir, "\\", "/");
- // 创建目录;
- if ( MKDIR(strSaveDir.c_str()) ) {
- // 同时下载脚本目录到指定目录中;// url地址可能包含中文,此处需要转码;
- stScriptUrlResp.strURL = CCurlClient::ParseURLAndEncode(stScriptUrlResp.strURL);
- GLOBAL::WriteTextLog("<======下载文件======> \r 文件地址:%s,保存路径:%s ", stScriptUrlResp.strURL.c_str(), strSaveDir.c_str());
- if ( g_curl.Download(stScriptUrlResp.strURL, strSaveDir, 20000) ) {
- stScriptUrlResp._strFileName = strFileName.substr(0, strFileName.find_last_of('.'));
- stScriptUrlResp._strScripFile = strSaveDir;
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- else
- {
- GLOBAL::WriteTextLog(_T("【Error】下载脚本失败:%s"), stScriptUrlResp.strURL.c_str());
- }
- }
- GLOBAL::WriteTextLog(_T("【Error】创建目录失败:%s"), strSaveDir.c_str());
- }
- }
- }
- }
- }
- else
- {
- GLOBAL::WriteTextLog(_T("【Error】文件不可下载:%s"), reponse.c_str());
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int StopTaskFromRunner(std::string url, std::string strInstnaceId, SATHTTP::STStopTaskResp &stStopTaskResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "");
- cJSON_AddStringToObject(pRoot, "function", "");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "instanceId", strInstnaceId.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- std::string post_data = "requestMsg=";
- post_data.append(CharEncoding::EnCode_UTF8URL(pText));
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.Post(url, post_data, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stStopTaskResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stStopTaskResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stStopTaskResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- stStopTaskResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- if ( stStopTaskResp.strCode == "00" )
- {
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATHTTP::STSaveLogReq &stSaveLogReq, SATHTTP::STSaveLogResp &stSaveLogResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "useId", stSaveLogReq.strUserId.c_str());
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "fileType", stSaveLogReq.strFileType.c_str());
- cJSON_AddStringToObject(pData, "caseId", stSaveLogReq.strCaseId.c_str());
- cJSON_AddStringToObject(pData, "taskId", stSaveLogReq.strTaskId.c_str());
- cJSON_AddStringToObject(pData, "executeId", stSaveLogReq.strExecuteId.c_str());
- cJSON_AddStringToObject(pData, "roundNum", stSaveLogReq.strRoundNum.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
- // POST表单提交,此处不需要转url格式,注意避坑!
- std::string post_data = pText;
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.PostFile(url, post_data, stSaveLogReq.strUploads, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stSaveLogResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stSaveLogResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stSaveLogResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- stSaveLogResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
- if ( stSaveLogResp.strCode == "00" )
- {
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int SaveResultFile(std::string url, const SATHTTP::STSaveFileReq &stSaveFileReq, SATHTTP::STSaveFileResp &stSaveFileResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "");
- cJSON_AddStringToObject(pRoot, "function", "");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "roundNum", stSaveFileReq.strRoundNum.c_str());
- cJSON_AddStringToObject(pData, "caseRepeat", stSaveFileReq.strCaseRepeat.c_str());
- cJSON_AddStringToObject(pData, "jobRepeat", stSaveFileReq.strJobRepeat.c_str());
- cJSON_AddStringToObject(pData, "instanceId", stSaveFileReq.strInstanceId.c_str());
- cJSON_AddStringToObject(pData, "deviceId", stSaveFileReq.strDeviceId.c_str());
- cJSON_AddStringToObject(pData, "executeId", stSaveFileReq.strExecuteId.c_str());
- cJSON_AddStringToObject(pData, "taskName", stSaveFileReq.strTaskName.c_str());
- cJSON_AddStringToObject(pData, "sceneIndex", stSaveFileReq.strSceneIndex.c_str());
- cJSON_AddStringToObject(pData, "taskId", stSaveFileReq.strTaskId.c_str());
- cJSON_AddStringToObject(pData, "caseId", stSaveFileReq.strCaseId.c_str());
- cJSON_AddStringToObject(pData, "deviceName", stSaveFileReq.strDeviceName.c_str());
- cJSON_AddStringToObject(pData, "runnerName", stSaveFileReq.strRunnerName.c_str());
- cJSON_AddStringToObject(pData, "runnerIP", stSaveFileReq.strRunnerIP.c_str());
- cJSON_AddStringToObject(pData, "runnerMac", stSaveFileReq.strRunnerMAC.c_str());
- cJSON_AddStringToObject(pData, "caseName", stSaveFileReq.strCaseName.c_str());
- cJSON_AddStringToObject(pData, "caseIndex", stSaveFileReq.strCaseIndex.c_str());
- cJSON_AddStringToObject(pData, "taskRepeat", stSaveFileReq.strTaskRepeat.c_str());
- cJSON_AddStringToObject(pData, "busCode", stSaveFileReq.strBusCode.c_str());
- cJSON_AddStringToObject(pData, "fileType", stSaveFileReq.strFileType.c_str());
- cJSON_AddStringToObject(pData, "caseStep", stSaveFileReq.strCaseStep.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
- // POST表单提交,此处不需要转url格式,注意避坑!
- std::string post_data = pText;
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.PostFile(url, post_data, stSaveFileReq.strUploads, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stSaveFileResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stSaveFileResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stSaveFileResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- stSaveFileResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
- if ( stSaveFileResp.strCode == "00" )
- {
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
- SATHTTP_API int SaveResultImg(std::string url, const SATHTTP::STSaveImgReq &stSaveImgReq, SATHTTP::STSaveImgResp &stSaveImgResp)
- {
- // 转化为Json;
- cJSON *pRoot = cJSON_CreateObject();
- if ( pRoot == NULL )
- {
- return -1;
- }
- cJSON_AddStringToObject(pRoot, "sysCode", "");
- cJSON_AddStringToObject(pRoot, "function", "");
- cJSON *pData = cJSON_CreateObject();
- if ( pData )
- {
- cJSON_AddStringToObject(pData, "instanceId", stSaveImgReq.strInstanceId.c_str());
- cJSON_AddStringToObject(pData, "deviceId", stSaveImgReq.strDeviceId.c_str());
- cJSON_AddStringToObject(pData, "roundNum", stSaveImgReq.strRoundNum.c_str());
- cJSON_AddStringToObject(pData, "caseId", stSaveImgReq.strCaseId.c_str());
- cJSON_AddStringToObject(pData, "step", stSaveImgReq.strCaseStep.c_str());
- cJSON_AddStringToObject(pData, "type", stSaveImgReq.strImgType.c_str());
- cJSON_AddStringToObject(pData, "executeId", stSaveImgReq.strExecuteId.c_str());
- cJSON_AddStringToObject(pData, "caseRepeat", stSaveImgReq.strCaseRepeat.c_str());
- cJSON_AddStringToObject(pData, "jobRepeat", stSaveImgReq.strJobRepeat.c_str());
- // 添加到根结点中;
- cJSON_AddItemToObject(pRoot, "data", pData);
- }
- char *pText = cJSON_Print(pRoot);
- //std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
- // POST表单提交,此处不需要转url格式,注意避坑!
- std::string post_data = pText;
- // 释放堆内存;
- if (pText)
- delete pText;
- pText = NULL;
- if ( pRoot )
- cJSON_Delete(pRoot);
- pRoot = NULL;
- std::string reponse;
- CURLcode curlCode = CURLE_OK;
- if ( g_curl.IsInit() )
- {
- if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
- curlCode = g_curl.Posts(url, post_data, reponse);
- else
- curlCode = g_curl.PostFile(url, post_data, stSaveImgReq.strUploads, reponse);
- if ( curlCode == CURLE_OK )
- {
- reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
- // 解析返回值;
- pRoot = cJSON_Parse(reponse.c_str());
- if (pRoot != NULL)
- {
- cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
- if ( pMsg )
- {
- stSaveImgResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
- stSaveImgResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
- stSaveImgResp.strStr = cJSON_GetObjectItem(pMsg, "str") ? (cJSON_GetObjectItem(pMsg, "str")->valuestring ? cJSON_GetObjectItem(pMsg, "str")->valuestring : "") : "";
- stSaveImgResp.strData = cJSON_GetObjectItem(pMsg, "data") ? (cJSON_GetObjectItem(pMsg, "data")->valuestring ? cJSON_GetObjectItem(pMsg, "data")->valuestring : "") : "";
- if ( stSaveImgResp.strCode == "00" )
- {
- // 释放内存;
- cJSON_Delete(pRoot);
- // 返回结果;
- return TRUE;
- }
- }
- // 错误产生,可输出msg方便查询;
- cJSON_Delete(pRoot);
- }
- }
- }
- SETLOG;
- return FALSE;
- }
|