Browse Source

#IQRV #comment [AccessAuth] 准入实体TimeSync同步操作

gifur 3 years ago
parent
commit
b328c8946f
2 changed files with 108 additions and 48 deletions
  1. 7 2
      Module/CMakeLists.txt
  2. 101 46
      Module/mod_accessauth/AccessAuthFSM.cpp

+ 7 - 2
Module/CMakeLists.txt

@@ -105,8 +105,13 @@ macro(add_module_libraries _module_prefix _module_name _module_version)
 
     if(REPLACE_HTTPCLIENT_WITH_CPPRESTSDK)
         target_compile_definitions(${_module_name} PRIVATE "WITH_CPPRESTSDK")
-	    target_include_directories(${_module_name} PRIVATE ${RVC_OTHER_DEPENDENIES_DIR}/libRestfulFunc)
-        target_link_libraries(${_module_name} RestfulFunc)
+	    target_include_directories(${_module_name} PRIVATE 
+            ${CONAN_INCLUDE_DIRS_JSONCPP}
+            ${RVC_OTHER_DEPENDENIES_DIR}/libRestfulFunc)
+        target_link_directories(${MODULE_NAME} PRIVATE
+        	${CONAN_LIB_DIRS_JSONCPP}
+        )
+        target_link_libraries(${_module_name} RestfulFunc ${CONAN_PKG_LIBS_JSONCPP})
     endif(REPLACE_HTTPCLIENT_WITH_CPPRESTSDK)
 
     configure_file("${MODULE_BASE_DIR}/include/modVer.h.in" "${CMAKE_CURRENT_BINARY_DIR}/modVer.h")

+ 101 - 46
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -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);
 	}
 };