Browse Source

Z991239-5094 #comment fix token err

陈良瑜80374463 1 year ago
parent
commit
a8dae993f1

+ 1 - 1
CMakeLists.txt

@@ -284,7 +284,7 @@ if(CONAN_CACHE_CLEAR)
 	conan_local_remove()
 endif(CONAN_CACHE_CLEAR)
 
-conan_cmake_run(REQUIRES RvcFramework/1.2.0.91@LR04.02_FrameworkLib/dev
+conan_cmake_run(REQUIRES RvcFramework/1.2.0.94@LR04.02_FrameworkLib/dev
 	Audio/2023.0509.01@LR04.02_MediaRes/testing
 BASIC_SETUP CMAKE_TARGETS)
 

+ 2 - 2
Module/mod_CenterSetting/CenterSettingConn.cpp

@@ -514,7 +514,7 @@ void CenterSettingsMicroServiceHelper::UpdateVersion()
     m_pCenterConfig->ReadConfigValue("CenterSetting", "UpdateVersionUrl", url);
 
     HttpClientResponseResult result;
-    HttpClientRequestConfig config(HttpRequestMethod::POST, url.GetData());
+    HttpClientRequestConfig config(HttpRequestMethod::POST, url.GetData(), &SpGetToken);
 
     updateVersionReq.terminal_no = m_terminalInfo.strTerminalID.GetData();
     updateVersionReq.version_no = m_strVersion;
@@ -698,7 +698,7 @@ int CenterSettingsMicroServiceHelper::GetCenterSettingsFromHttp(CenterSettingReq
     }getCenterSettingAns;
 
     HttpClientResponseResult result;
-    HttpClientRequestConfig config(HttpRequestMethod::POST, req.m_url);
+    HttpClientRequestConfig config(HttpRequestMethod::POST, req.m_url, &SpGetToken);
     if (req.m_timeOut > 0) config.SetTimeout(req.m_timeOut);
 
     getCenterSettingReq.m_terminal_no = req.m_terminal_no;

+ 3 - 3
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -196,7 +196,7 @@ struct TimeSynTask : ITaskSp
 		timeSyncReq.curTime = CSmallDateTime::GetNow().GetTime64();
 
 		HttpClientResponseResult result;
-		HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData());
+		HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData(), &SpGetToken);
 		config.SetChildUri("/api/v3/sessionkey");
 		SP::Module::Restful::FulfillRequestJsonBody(&config, timeSyncReq);
 		RestfulClient client = RestfulClient::getInstance();
@@ -436,7 +436,7 @@ struct UpdateWKTask : ITaskSp
 		}
 
 		HttpClientResponseResult result;
-		HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData());
+		HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData(), &SpGetToken);
 		config.SetChildUri("/api/v5/wkupdate");
 
 		SP::Module::Restful::FulfillRequestJsonBody(&config, updateWKReq);
@@ -622,7 +622,7 @@ struct GetTokenTask : ITaskSp
 		} getTokenAns;
 
 		HttpClientResponseResult result;
-		HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData());
+		HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->GetmAccessAuthHost().GetData(), &SpGetToken);
 		config.SetChildUri("/api/v3/access");
 
 		getTokenReqJson.installVersion = getTokenReq.installVersion;

+ 1 - 1
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -191,7 +191,7 @@ struct InitializerInitMKTask : ITaskSp
 		} instanceAns;
 
 		HttpClientResponseResult result;
-		HttpClientRequestConfig config(HttpRequestMethod::POST, m_entity->GetInitUrl().GetData());
+		HttpClientRequestConfig config(HttpRequestMethod::POST, m_entity->GetInitUrl().GetData(), &SpGetToken);
 		config.SetChildUri("/api/v5/initmk");
 		SP::Module::Restful::FulfillRequestJsonBody(&config, instanceReq);
 

+ 1 - 1
Module/mod_alarm/AlarmFSM.cpp

@@ -135,7 +135,7 @@ namespace Task
 #else
 		bool SendAlarmTaskImpl() {
 			HttpClientResponseResult result;
-			HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->m_sendUrl.GetData());
+			HttpClientRequestConfig config(HttpRequestMethod::POST, m_fsm->m_sendUrl.GetData(), &SpGetToken);
 
 			string reqStr = "";
 			if(m_fsm->m_unSendAlarm.IsNullOrEmpty()){

+ 1 - 1
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -2345,7 +2345,7 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
 			CSimpleStringA matchInfo(true);
 
             //走总行服务
-            HttpClientRequestConfig config(serverIP.GetData());
+            HttpClientRequestConfig config(serverIP.GetData(), &SpGetToken);
             HttpClientResponseResult result;
             config.SetChildUri(URLPATH_REGISTER_FULL_LIST);
             config.AppendQuery("terminalNo", terminalNo.GetData());

+ 15 - 5
Module/mod_vtmloader/VtmLoaderFSM.cpp

@@ -3,10 +3,11 @@
 #include "VtmLoaderFSM.h"
 #include "VtmLoader_UserCode.h"
 #include "EventCode.h"
-#include "..\RvcVer.h"
+
 
 #if defined(RVC_OS_WIN)
 #include <io.h>
+#include "..\RvcVer.h"
 #else
 #include <unistd.h>
 #include <fcntl.h>
@@ -122,8 +123,14 @@ DWORD checkUrlActive(LPVOID param)
 				, t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc,
 				t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err).GetData());
 	}
+	return 0;
+}
 
-
+DWORD AlarmVersionErr(LPVOID param)
+{
+	CVtmLoaderFSM* cur = (CVtmLoaderFSM*)param;
+	Sleep(5000);//wait mod_alarm start
+	LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, cur->m_verShowMsg.GetData());
 	return 0;
 }
 
@@ -147,7 +154,7 @@ CVtmLoaderFSM::CVtmLoaderFSM()
 	m_iCanIgnoreAddrDetect = 0;
 	m_ullMaxAddrDetectTime = 10*60*1000;//10 minutes
 	m_iDetectInterval = 5000;
-	m_terminalNoFromWeb = "";
+	m_terminalNoFromWeb = m_verShowMsg = "";
 }
 
 CVtmLoaderFSM::~CVtmLoaderFSM()
@@ -1477,6 +1484,7 @@ bool CVtmLoaderFSM::VerifyVer()
 #endif
 	if (curVer == activeVer.GetData())
 		isVerEqual = true;
+	
 	if (!isVerEqual)
 	{
 		CSimpleString showMsg = CSimpleString::Format("version not equal, file version:%s, acitve verion:%s", curVer.c_str(), activeVer.GetData());
@@ -1486,10 +1494,12 @@ bool CVtmLoaderFSM::VerifyVer()
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(showMsg.GetData());
 			break;
 		case 1:
-			LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, showMsg.GetData());
+			m_verShowMsg = showMsg;
+			CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
 			break;
 		case 2:
-			LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, showMsg.GetData());
+			m_verShowMsg = showMsg;
+			CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
 			return false;
 			break;
 		default:

+ 1 - 0
Module/mod_vtmloader/VtmLoaderFSM.h

@@ -108,6 +108,7 @@ private:
 	END_FSM_RULE()
 public:
 	int m_refreshWaitSec, m_uploadLogInfo_waitSec;
+	CSimpleString m_verShowMsg;
 	int NetWorkCheckAndGetSetting();
 	bool GetConfig();
 	bool VerifyVer();

+ 41 - 9
Other/libRestfulFunc/RestfulFunc.h

@@ -32,6 +32,9 @@
 * -2:超时
 * -3:地址不符合规范
 */
+
+typedef void (*restFul_GetTokenCallBack)(char *, char *);
+
 RESTFULFUNC_API int HttpProbe(const std::string& url, std::string& out_msg, uint32_t wait_max_secs = (uint32_t)-1);
 
 /*!
@@ -118,20 +121,23 @@ struct HttpClientRequestConfig
      * @param[out] 
      * @return : 
      */
-    HttpClientRequestConfig(const std::string& uri) 
+    HttpClientRequestConfig(const std::string& uri, restFul_GetTokenCallBack t_getToken)
         :mMethod(HttpRequestMethod::GET), mUri(uri), mToValidCert(false)
-        , mBodyContent(""), mContentType(""), mHeaderAcceptType("application/json"), mTimeoutSecs(0)
+        , mBodyContent(""), mContentType(""), mHeaderAcceptType("application/json"), mTimeoutSecs(0), m_withToken(true)
     {
+        InitGetToken(t_getToken);
     }
-    HttpClientRequestConfig(HttpRequestMethod method)
-        : mMethod(method), mToValidCert(false), mBodyContent(""), mHeaderAcceptType("application/json")
+    HttpClientRequestConfig(HttpRequestMethod method, restFul_GetTokenCallBack t_getToken)
+        : mMethod(method), mToValidCert(false), mBodyContent(""), mHeaderAcceptType("application/json"), m_withToken(true)
         , mContentType(""), mTimeoutSecs(0)
     {
+        InitGetToken(t_getToken);
     }
-    HttpClientRequestConfig(HttpRequestMethod method, const std::string& uri) 
-        :mMethod(method), mUri(uri), mToValidCert(false), mBodyContent("")
+    HttpClientRequestConfig(HttpRequestMethod method, const std::string& uri, restFul_GetTokenCallBack t_getToken)
+        :mMethod(method), mUri(uri), mToValidCert(false), mBodyContent(""), m_withToken(true)
         , mContentType(""), mHeaderAcceptType("application/json"), mTimeoutSecs(0)
     {
+        InitGetToken(t_getToken);
     }
 
     void SetRequestType(HttpRequestMethod method) { mMethod = method; }
@@ -175,6 +181,22 @@ struct HttpClientRequestConfig
     virtual void PreDo() {}
     virtual void PostDo() {}
 
+    bool getToken(std::string & t_channelId, std::string &t_token) const {
+        char channelId[256] = "";
+        char token[256] = "";
+        if (m_withToken && g_tokenCall != NULL)
+        {
+            g_tokenCall(channelId, token);
+            if (std::string(channelId).length() > 0 && std::string(token).length() > 0)
+            {
+                t_channelId = channelId;
+                t_token = token;
+                return true;
+            }
+        }
+        return false;
+    }
+
 private:
 
     HttpRequestMethod mMethod;
@@ -186,20 +208,30 @@ private:
 
     std::map<std::string, std::string> mQueryPairs;
 
+    bool m_withToken;
     bool mToValidCert;
     uint32_t mTimeoutSecs;
+    restFul_GetTokenCallBack g_tokenCall;
+    void InitGetToken(restFul_GetTokenCallBack t_getToken) {
+        if (t_getToken)
+            g_tokenCall = t_getToken;
+        else
+            g_tokenCall = nullptr;
+
+        
+    };
 };
 
 struct HttpClientPostTypeRequest : public HttpClientRequestConfig
 {
     HttpClientPostTypeRequest(const std::string& uri)
-        :HttpClientRequestConfig(HttpRequestMethod::POST, uri) {}
+        :HttpClientRequestConfig(HttpRequestMethod::POST, uri, nullptr) {}
 };
 
 struct HttpClientUploadRequest : public HttpClientRequestConfig
 {
     HttpClientUploadRequest(const std::string& uri)
-        :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri)
+        :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri, nullptr)
     {
     }
 
@@ -236,7 +268,7 @@ private:
 struct HttpClientDownloadRequest : public HttpClientRequestConfig
 {
     HttpClientDownloadRequest(const std::string& uri) 
-        :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri) {
+        :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri, nullptr) {
         SetAcceptType("*/*");
     }
 };

+ 7 - 0
Other/libRestfulFunc/RestfulFuncImpl.cpp

@@ -181,6 +181,13 @@ void RestfulClient::Do(const HttpClientRequestConfig* const pRequestConfig, Http
 	request.set_request_uri(urib.to_string());
 	request.headers().add(header_names::accept, STRW(pRequestConfig->GetAcceptType()));
 
+	std::string token, channelId;
+	if (pRequestConfig->getToken(channelId, token))
+	{
+		request.headers().add("channelId", channelId);
+		request.headers().add("token", token);
+	}
+
 	if (pRequestConfig->GetRequestType() != HttpRequestMethod::GET) {
 		request.set_body(STRW(pRequestConfig->GetBodyContent()), STRW(pRequestConfig->GetContentType()));
 	}

+ 3 - 3
Other/libRestfulFunc/test/testNormlReqAns.cpp

@@ -4,7 +4,7 @@
 
 TEST_CASE("test api manage", "[restful]")
 {
-    HttpClientRequestConfig config("https://rvcgateway.paasst.cmbchina.cn/terminal");
+    HttpClientRequestConfig config("https://rvcgateway.paasst.cmbchina.cn/terminal", NULL);
     HttpClientResponseResult result;
     config.SetChildUri("/api/manage/regist/7555980103");
     RestfulClient client = RestfulClient::getInstance();
@@ -15,7 +15,7 @@ TEST_CASE("test api manage", "[restful]")
 
 TEST_CASE("test  api stage get api", "[restful]")
 {
-    HttpClientRequestConfig config("https://rvcterminal.paasst.cmbchina.cn");
+    HttpClientRequestConfig config("https://rvcterminal.paasst.cmbchina.cn", NULL);
     HttpClientResponseResult result;
     config.SetChildUri("/api/stage");
     config.AppendQuery("terminalNo", "7555980001");
@@ -27,7 +27,7 @@ TEST_CASE("test  api stage get api", "[restful]")
 
 TEST_CASE("test  api stage post api", "[restful]")
 {
-    HttpClientRequestConfig config("https://rvcterminal.paasst.cmbchina.cn");
+    HttpClientRequestConfig config("https://rvcterminal.paasst.cmbchina.cn", NULL);
     config.SetRequestType(HttpRequestMethod::POST);
     config.SetChildUri("/api/stage");
     config.SetJsonBody("{\"terminalNo\":\"7555980001\", \"errEntityList\":\"566666\"}");