浏览代码

Z991239-4870 #comment 调用框架的接口去refreshToken

陈良瑜80374463 2 年之前
父节点
当前提交
236a465fa4
共有 2 个文件被更改,包括 10 次插入118 次删除
  1. 0 1
      Module/mod_guiconsole/mod_GuiConsole.h
  2. 10 117
      Module/mod_guiconsole/mod_guiconsole.cpp

+ 0 - 1
Module/mod_guiconsole/mod_GuiConsole.h

@@ -46,7 +46,6 @@ public:
 	ErrorCodeEnum SubscribeEntitysEvents();
 	ErrorCodeEnum SubscribeEntitysEvents();
 	ErrorCodeEnum UnsubscribeEntitysEvents();
 	ErrorCodeEnum UnsubscribeEntitysEvents();
 	CSimpleStringA GetCurMaintainer(){ return m_strUserID;}
 	CSimpleStringA GetCurMaintainer(){ return m_strUserID;}
-	bool refreshToken();
 	ErrorCodeEnum GetCurrentMaintainer(CSimpleStringA &strUserID,	CSimpleStringA &strUserName, CSimpleStringA &strCurRight,
 	ErrorCodeEnum GetCurrentMaintainer(CSimpleStringA &strUserID,	CSimpleStringA &strUserName, CSimpleStringA &strCurRight,
 		CSimpleStringA &strAuthorizer, unsigned int &dwBeginTime);
 		CSimpleStringA &strAuthorizer, unsigned int &dwBeginTime);
 	ErrorCodeEnum Empower(const char *pszUserID);
 	ErrorCodeEnum Empower(const char *pszUserID);

+ 10 - 117
Module/mod_guiconsole/mod_guiconsole.cpp

@@ -22,12 +22,21 @@ static void HTTPLogCallback(const char* msg) {
 DWORD tokenUpdate(void* param)
 DWORD tokenUpdate(void* param)
 {
 {
 	CGUIConsoleEntity* t_entity = (CGUIConsoleEntity*)param;
 	CGUIConsoleEntity* t_entity = (CGUIConsoleEntity*)param;
+	CSimpleString token;
+	if (t_entity->GetFunction()->GetPrivilegeFunction()->GetToken(token) == ErrorCodeEnum::Error_Succeed)
+		Sleep(t_entity->m_refreshWaitSec / 4 * 1000);
 	while (true)
 	while (true)
 	{
 	{
-		if (t_entity->refreshToken())
+		CSimpleString oldToken, newToken;
+		auto ret = t_entity->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken);
+		if (ret == Error_Succeed)
 			Sleep(t_entity->m_refreshWaitSec * 1000);
 			Sleep(t_entity->m_refreshWaitSec * 1000);
 		else
 		else
+		{
+			LogWarn(Severity_Middle, ret, ret == Error_NotConfig ? TOKEN_GETURL_ERR : GET_TOKEN_ERR,
+				ret == Error_NotConfig ? "can not get CommonLaunchUrl from shell" : "total getToken failed");
 			Sleep(20 * 1000);
 			Sleep(20 * 1000);
+		}
 	}
 	}
 	return 0;
 	return 0;
 }
 }
@@ -159,122 +168,6 @@ void CGUIConsoleEntity::printCfg()
 	}
 	}
 }
 }
 
 
-bool CGUIConsoleEntity::refreshToken()
-{
-	static std::string commonUrl = "";
-	if (commonUrl.length() == 0)
-	{
-		CSmartPointer<IConfigInfo> shellConfig;
-		GetFunction()->OpenConfig(Config_Shell, shellConfig);
-		CSimpleStringA strMicroServiceURLSection = "MicroServiceURL";
-
-#ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
-		strMicroServiceURLSection = "MicroServiceURL-ST";
-		m_channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
-		m_tokenSecret = "eca829c78067c686561bd844129321c8a78af3";
-#elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
-		strMicroServiceURLSection = "MicroServiceURL-UAT";
-		m_channelId = "7eb748cb71744c87b5c126e05af8cce7";
-		m_tokenSecret = "eca529c78967c640561bd844229391c8a78af3";
-#elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
-		//strMicroServiceURLSection = "MicroServiceURL-PRD";
-		m_channelId = "572f7577fa9f425c8475a8d77db4ae31";
-		m_tokenSecret = "eca129c78767c670561bd844629361c8a78af3";
-#elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
-		strMicroServiceURLSection = "MicroServiceURL-Dev";
-		m_channelId = "572f7577fa9f425c8475a8d77db4ae31";
-		m_tokenSecret = "eca129c78767c670561bd844629361c8a78af3";
-#else/*本地编译等非DevOps环境编译的版本*/
-		strMicroServiceURLSection = "MicroServiceURL-Dev";
-		m_channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
-		m_tokenSecret = "eca829c78067c686561bd844129321c8a78af3";
-#endif
-
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Section name:%s", strMicroServiceURLSection.GetData());
-		CAutoArray<CSimpleStringA> m_arrKeys;
-		shellConfig->ReadAllKeys(strMicroServiceURLSection, m_arrKeys);
-
-		CSimpleStringA strUrl;
-		for (int i = 0; i < m_arrKeys.GetCount(); i++)
-		{
-			if (m_arrKeys[i].IsStartWith("CommonLaunchUrl"))
-			{
-				shellConfig->ReadConfigValue(strMicroServiceURLSection, m_arrKeys[i].GetData(), strUrl);
-				break;
-			}
-
-		}
-
-		if (strUrl.IsNullOrEmpty())
-		{
-			LogWarn(Severity_Middle, Error_Bug, TOKEN_GETURL_ERR, "can not get CommonLaunchUrl from shell.ini");
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI("refreshToken").setLogCode("QLR0402Z10A00001")("can not get CommonLaunchUrl from shell.ini");
-			return false;
-		}
-		else
-			commonUrl = strUrl.GetData();
-	}
-
-	static std::string terminalNo;
-	if (terminalNo.length() == 0)
-	{
-		CSystemStaticInfo info;
-		GetFunction()->GetSystemStaticInfo(info);
-		terminalNo = info.strTerminalID;
-	}
-
-	//只要调用这个借口,就会获取新的token
-	//判断是否应该刷新,在其他逻辑中判断
-	CSimpleString tmpUrl = commonUrl.c_str();
-	auto urlArr = tmpUrl.Split('|');
-	static std::vector<QueryTokenHTTPReq> reqArr;//避免函数结束被析构
-	reqArr.clear();
-	for (int i = 0; i < urlArr.GetCount(); i++)
-	{
-		auto curUrl = urlArr[i];
-		if (curUrl.GetLength() == 0)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("QueryToken error, pos:%d, %s", i, tmpUrl.GetData());
-			continue;
-		}
-		QueryTokenHTTPReq req;
-		req.channelId = m_channelId;
-		req.tokenSecret = m_tokenSecret;
-		req.businessId = terminalNo;
-		req.m_url = curUrl.GetData();
-		req.m_url.append("/api/auth/v2/token");
-		req.m_headers.emplace(std::make_pair("Content-Type", "application/json"));
-		reqArr.emplace_back(req);
-	}
-	std::vector<HANDLE> threadArr;//创建多个线程获取token
-	for (int i = 0; i < reqArr.size(); i++)
-		threadArr.push_back(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&getTokenThread, &(reqArr[i]), 0, NULL));
-
-	bool t_isGetTokenSuccess = false;
-	auto tokenRet = WaitForMultipleObjects(threadArr.size(), threadArr.data(), false, 10000);
-	if (tokenRet >= WAIT_OBJECT_0 && tokenRet <= WAIT_OBJECT_0 + threadArr.size())
-	{
-		DWORD exitCode = INT_MAX;
-		GetExitCodeThread(threadArr[tokenRet - WAIT_OBJECT_0], &exitCode);
-		if (exitCode == 0)
-		{
-			t_isGetTokenSuccess = true;
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("total getToken success from url %s", reqArr[tokenRet - WAIT_OBJECT_0].m_url.c_str());
-			CSimpleString t_channelId = m_channelId.c_str();
-			CSimpleString t_token = m_httpToken.c_str();
-			GetFunction()->SetSysVar("shell_channelId", t_channelId);
-			GetFunction()->SetSysVar("shell_token", t_token);
-			//GetFunction()->GetPrivilegeFunction()->SetHttpToken(m_channelId.c_str(), m_httpToken.c_str());
-			return true;
-		}
-	}
-	LogWarn(Severity_Low, Error_Bug, GET_TOKEN_ERR, "total getToken failed");
-	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("refreshToken").setLogCode("QLR0402Z10A00003")("total getToken failed");
-	return false;
-}
-
-
-
 
 
 void CGUIConsoleEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
 void CGUIConsoleEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
 {
 {