|
@@ -14,6 +14,7 @@
|
|
|
#ifdef WITH_CPPRESTSDK
|
|
|
#include "RestfulFunc.h"
|
|
|
#include "JsonConvertHelper.hpp"
|
|
|
+#include "microservices/api_comm.h"
|
|
|
#endif
|
|
|
|
|
|
#define SAFE_DELETE_HTTPCLIENT(obj) \
|
|
@@ -240,58 +241,112 @@ struct TimeSynTask : ITaskSp {
|
|
|
m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
|
|
|
|
|
|
#ifdef WITH_CPPRESTSDK
|
|
|
- HttpClientRequestConfig config(m_fsm->GetmAccessAuthHost().GetData());
|
|
|
+ struct TimeSynReqStructJson
|
|
|
+ {
|
|
|
+ std::string terminalNo;
|
|
|
+ int curTime;
|
|
|
+ std::string reserved;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(terminalNo, curTime, reserved)
|
|
|
+ } timeSyncReq;
|
|
|
+ struct TimeSyncAnsStructJson
|
|
|
+ {
|
|
|
+ int timeDiff;
|
|
|
+ int authVersion;
|
|
|
+ std::string sessionKey;
|
|
|
+ std::string reserved;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(timeDiff, authVersion, sessionKey, reserved)
|
|
|
+ }timeSyncAns;
|
|
|
+
|
|
|
+
|
|
|
+ timeSyncReq.terminalNo = si.strTerminalID.GetData();
|
|
|
+ timeSyncReq.curTime = CSmallDateTime::GetNow().GetTime64();
|
|
|
+ timeSyncReq.reserved = "";
|
|
|
+
|
|
|
+ HttpClientResponseResult result;
|
|
|
+ HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData());
|
|
|
config.SetChildUri("/api/sessionkey");
|
|
|
+ std::string jsonValue;
|
|
|
+ Object2Json(jsonValue, timeSyncReq);
|
|
|
+ config.SetJsonBody(jsonValue);
|
|
|
+ RestfulClient client = RestfulClient::getInstance();
|
|
|
+ config.PreDo();
|
|
|
+ client.Do(&config, &result);
|
|
|
+ if (result.ConsiderAsSucc()) {
|
|
|
+ struct CommResponseJson : public MicroServices::API::CommResponse
|
|
|
+ {
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, errorCode, returnCode, errorMsg, message)
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("success", "code", "return_code", "error_msg", "message")
|
|
|
+ } responseStatus ;
|
|
|
+
|
|
|
+ Json::Value rawRoot;
|
|
|
+ GetJsonRootObject(rawRoot, result.content);
|
|
|
+ Json2Object(responseStatus, rawRoot);
|
|
|
+ Json2Object(timeSyncAns, rawRoot["data"]);
|
|
|
+
|
|
|
+ if (!responseStatus.IsReqBusinessSucc()) {
|
|
|
+ m_fsm->doWarnMsg(ERR_ACCESSAUTH_REPORT_STATE,
|
|
|
+ GetOutPutStr("%s%s%s%s", "StageReportTask", responseStatus.errorCode.c_str(), "message", responseStatus.errorMsg.c_str()).c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auto printFunc = [&timeSyncAns]() {
|
|
|
+ Dbg("timeDiff: %d", timeSyncAns.timeDiff);
|
|
|
+ Dbg("authVersion: %d", timeSyncAns.authVersion);
|
|
|
+ Dbg("sessionKey: %s", timeSyncAns.sessionKey.c_str());
|
|
|
+ Dbg("reserved: %s", timeSyncAns.reserved.c_str());
|
|
|
+ };
|
|
|
|
|
|
+ printFunc();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Dbg("StageReport Connect Failed(%d).", result.statusCode);
|
|
|
+ m_fsm->doWarnMsg(ERROR_ACCESSAUTH_CONNECT_ACS, GetOutPutStr("%s%d", "连接总行ACS准入服务失败(StageReport).", result.statusCode).c_str());
|
|
|
+ }
|
|
|
#else
|
|
|
+ IHttpFunc* client;
|
|
|
+ client = create_http(m_fsm->HttpsLogCallBack);
|
|
|
+ CAccessAuthTimeSynReq timeSynReq(si.strTerminalID.GetData(), CSmallDateTime::GetNow().GetTime64());
|
|
|
+ CAccessAuthTimeSynRet timeSynRet;
|
|
|
+ timeSynReq.m_url = m_fsm->GetmAccessAuthHost();
|
|
|
+ timeSynReq.m_url += "/api/sessionkey";
|
|
|
+
|
|
|
+ bool ret = client->Post(timeSynReq, timeSynRet);
|
|
|
+
|
|
|
+ Dbg("code=%d", timeSynRet.m_sysCode);
|
|
|
+ if (ret) {
|
|
|
+ Dbg("TimeSynTask Connect Success.");
|
|
|
+ if (timeSynRet.m_userCode.compare(ACS_SUCCESS)) {
|
|
|
+ std::string errStr = SP::Utility::GBK2UTF8(timeSynRet.m_errMsg);
|
|
|
+ m_fsm->doWarnMsg(ERR_ACCESSAUTH_SYNC_TIME,
|
|
|
+ GetOutPutStr("%s%s%s%s", "TimeSynTask", timeSynRet.m_userCode.c_str(), "message", errStr.c_str()).c_str(), true);
|
|
|
+ SAFE_DELETE_HTTPCLIENT(client);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Dbg("sessionKey = %s", timeSynRet.data.sessionKey.c_str());
|
|
|
+ int decodedSessionKeyLen = 0;
|
|
|
+ char* decodedSessionKey = Hex2Str(timeSynRet.data.sessionKey.c_str(), decodedSessionKeyLen);
|
|
|
+ Dbg("decodedSessionKey=%s,%d", decodedSessionKey, decodedSessionKeyLen);
|
|
|
+ DWORD rc = Error_InvalidState;
|
|
|
+ if (m_fsm->m_pConnection != NULL) {
|
|
|
+ rc = m_fsm->m_pConnection->HandleTimeSyn(timeSynRet.data.timeDiff, timeSynRet.data.authVersion, (BYTE*)decodedSessionKey);
|
|
|
+ }
|
|
|
+ delete decodedSessionKey;
|
|
|
+ if (rc == Error_Succeed) {
|
|
|
+ Dbg("TimeSynTask HandleTimeSyn Success");
|
|
|
+ auto pEvent = new FSMEvent(CAccessAuthFSM::Event_EndSyncTime);
|
|
|
+ m_fsm->PostEventFIFO(pEvent);
|
|
|
+ } else {
|
|
|
+ Dbg("TimeSynTask HandleTimeSyn error = %08X", rc);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ m_fsm->doWarnMsg(ERROR_ACCESSAUTH_CONNECT_ACS,
|
|
|
+ GetOutPutStr("%s%d", "连接总行ACS准入服务失败(TimeSynTask).", timeSynRet.m_sysCode).c_str(), true);
|
|
|
+ Dbg("TimeSynTask Connect Failed.");
|
|
|
+ }
|
|
|
+ SAFE_DELETE_HTTPCLIENT(client);
|
|
|
#endif
|
|
|
|
|
|
- IHttpFunc* client;
|
|
|
- client = create_http(m_fsm->HttpsLogCallBack);
|
|
|
- CAccessAuthTimeSynReq timeSynReq(si.strTerminalID.GetData(), CSmallDateTime::GetNow().GetTime64());
|
|
|
- CAccessAuthTimeSynRet timeSynRet;
|
|
|
- timeSynReq.m_url = m_fsm->GetmAccessAuthHost();
|
|
|
- timeSynReq.m_url +="/api/sessionkey";
|
|
|
|
|
|
- bool ret = client->Post(timeSynReq, timeSynRet);
|
|
|
-
|
|
|
- Dbg("code=%d",timeSynRet.m_sysCode);
|
|
|
- if (ret)
|
|
|
- {
|
|
|
- Dbg("TimeSynTask Connect Success.");
|
|
|
- if (timeSynRet.m_userCode.compare(ACS_SUCCESS)) {
|
|
|
- std::string errStr = SP::Utility::GBK2UTF8(timeSynRet.m_errMsg);
|
|
|
- m_fsm->doWarnMsg(ERR_ACCESSAUTH_SYNC_TIME,
|
|
|
- GetOutPutStr("%s%s%s%s", "TimeSynTask", timeSynRet.m_userCode.c_str(), "message", errStr.c_str()).c_str(),true);
|
|
|
- SAFE_DELETE_HTTPCLIENT(client);
|
|
|
- return;
|
|
|
- }
|
|
|
- Dbg("sessionKey = %s", timeSynRet.data.sessionKey.c_str());
|
|
|
- int decodedSessionKeyLen = 0;
|
|
|
- char* decodedSessionKey = Hex2Str(timeSynRet.data.sessionKey.c_str(),decodedSessionKeyLen);
|
|
|
- Dbg("decodedSessionKey=%s,%d", decodedSessionKey, decodedSessionKeyLen);
|
|
|
- DWORD rc = Error_InvalidState;
|
|
|
- if (m_fsm->m_pConnection != NULL) {
|
|
|
- rc = m_fsm->m_pConnection->HandleTimeSyn(timeSynRet.data.timeDiff, timeSynRet.data.authVersion, (BYTE*)decodedSessionKey);
|
|
|
- }
|
|
|
- delete decodedSessionKey;
|
|
|
- if (rc == Error_Succeed) {
|
|
|
- Dbg("TimeSynTask HandleTimeSyn Success");
|
|
|
- auto pEvent = new FSMEvent(CAccessAuthFSM::Event_EndSyncTime);
|
|
|
- m_fsm->PostEventFIFO(pEvent);
|
|
|
- }
|
|
|
- else {
|
|
|
- Dbg("TimeSynTask HandleTimeSyn error = %08X", rc);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- m_fsm->doWarnMsg(ERROR_ACCESSAUTH_CONNECT_ACS,
|
|
|
- GetOutPutStr("%s%d", "连接总行ACS准入服务失败(TimeSynTask).", timeSynRet.m_sysCode).c_str(),true);
|
|
|
- Dbg("TimeSynTask Connect Failed.");
|
|
|
- }
|
|
|
- //oiltest@20211117 temp comment the following line
|
|
|
- /** revert it [Gifur@2021128]*/
|
|
|
- SAFE_DELETE_HTTPCLIENT(client);
|
|
|
}
|
|
|
};
|
|
|
|