|
@@ -0,0 +1,795 @@
|
|
|
+#include "stdafx.h"
|
|
|
+#include "CenterSettingConn.h"
|
|
|
+#include "Event.h"
|
|
|
+#include <map>
|
|
|
+#include <regex>
|
|
|
+using namespace std;
|
|
|
+using std::regex;
|
|
|
+#include "mod_centersetting.h"
|
|
|
+#include <iostream>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+#include <fstream>
|
|
|
+#include "fileutil.h"
|
|
|
+#pragma comment(lib, "crypt32.lib")
|
|
|
+
|
|
|
+#ifdef RVC_OS_LINUX
|
|
|
+#include "CommEntityUtil.hpp"
|
|
|
+#include "iniutil.h"
|
|
|
+#include "json/json.h"
|
|
|
+#include "CommEntityRestful.hpp"
|
|
|
+#include "SpUtility.h"
|
|
|
+#include "RVCComm.h"
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+char* ConvertUtf8ToGBK(const char* strUtf8)
|
|
|
+{
|
|
|
+ int len = MultiByteToWideChar(CP_UTF8, 0, strUtf8, -1, NULL, 0);
|
|
|
+ WCHAR* wszGBK = new WCHAR[len + 1];
|
|
|
+ memset(wszGBK, 0, len * 2 + 2);
|
|
|
+ MultiByteToWideChar(CP_UTF8, 0, strUtf8, -1, wszGBK, len);
|
|
|
+
|
|
|
+ len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
|
|
|
+ char* szGBK = new char[len + 1];
|
|
|
+ memset(szGBK, 0, len + 1);
|
|
|
+ WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL);
|
|
|
+ delete[] wszGBK;
|
|
|
+
|
|
|
+ return szGBK;
|
|
|
+}
|
|
|
+
|
|
|
+void ConvertUtf8ToGBK(std::string& str)
|
|
|
+{
|
|
|
+ char* dst = ConvertUtf8ToGBK(str.c_str());
|
|
|
+ str = dst;
|
|
|
+ delete[] dst;
|
|
|
+}
|
|
|
+
|
|
|
+char* ConvertGBKToUtf8(const char* gbk, int* n)
|
|
|
+{
|
|
|
+ int len = MultiByteToWideChar(CP_ACP, 0, gbk, -1, NULL, 0);
|
|
|
+ WCHAR* wszGBK = new WCHAR[len + 1];
|
|
|
+ memset(wszGBK, 0, len * 2 + 2);
|
|
|
+ MultiByteToWideChar(CP_ACP, 0, gbk, -1, wszGBK, len);
|
|
|
+
|
|
|
+ len = WideCharToMultiByte(CP_UTF8, 0, wszGBK, -1, NULL, 0, NULL, NULL);
|
|
|
+ char* szUtf8 = new char[len + 1];
|
|
|
+ memset(szUtf8, 0, len + 1);
|
|
|
+ WideCharToMultiByte(CP_UTF8, 0, wszGBK, -1, szUtf8, len, NULL, NULL);
|
|
|
+
|
|
|
+ delete[] wszGBK;
|
|
|
+ *n = len - 1;
|
|
|
+ return szUtf8;
|
|
|
+}
|
|
|
+
|
|
|
+void ConvertGBKToUtf8(std::string& str)
|
|
|
+{
|
|
|
+ //char *src = new char[str.length() + 1];
|
|
|
+ //strncpy(src, str.c_str(), str.length() + 1);
|
|
|
+ int len = 0;
|
|
|
+ char* dst = ConvertGBKToUtf8(str.c_str(), &len);
|
|
|
+
|
|
|
+ str = dst;
|
|
|
+ //delete[] src;
|
|
|
+ delete[] dst;
|
|
|
+}
|
|
|
+
|
|
|
+static char* ConvertBytesToHexStr(BYTE *pBuf, int nLen)
|
|
|
+{
|
|
|
+ char *pRet = (char*)malloc(nLen * 2 + 1);
|
|
|
+ memset(pRet, 0, nLen * 2 + 1);
|
|
|
+ char *p = pRet;
|
|
|
+ for (int i = 0; i < nLen; i++)
|
|
|
+ {
|
|
|
+ BYTE b = pBuf[i];
|
|
|
+ BYTE l = (b >> 4) & 0x0F;
|
|
|
+ if (l >= 10)
|
|
|
+ *p = l - 10 + 'a';
|
|
|
+ else
|
|
|
+ *p = l + '0';
|
|
|
+
|
|
|
+ p++;
|
|
|
+ BYTE r = b & 0x0F;
|
|
|
+ if (r >= 10)
|
|
|
+ *p = r - 10 + 'a';
|
|
|
+ else
|
|
|
+ *p = r + '0';
|
|
|
+ p++;
|
|
|
+ }
|
|
|
+
|
|
|
+ return pRet;
|
|
|
+}
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+
|
|
|
+void convert(string& str)
|
|
|
+{
|
|
|
+ //将单斜杠转为双斜杠
|
|
|
+ for (size_t i = 0; i < str.size(); i++) {
|
|
|
+ if (str[i] == '\\') {
|
|
|
+ str.insert(i, string("\\"));
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void transferblank(string& str)
|
|
|
+{
|
|
|
+ int oldLen = str.length();
|
|
|
+ int cnt = 0;
|
|
|
+ for(int idx = 0; idx < oldLen; idx++)
|
|
|
+ {
|
|
|
+ if(str[idx] == ' ')
|
|
|
+ cnt++;
|
|
|
+ }
|
|
|
+
|
|
|
+ str.resize(oldLen + cnt * 2);
|
|
|
+ int j = oldLen - 1;
|
|
|
+ int i = str.length() - 1;
|
|
|
+ while( i >= 0 )
|
|
|
+ {
|
|
|
+ if(str[j] == ' ')
|
|
|
+ {
|
|
|
+ str[i--] = '0';
|
|
|
+ str[i--] = '2';
|
|
|
+ str[i--] = '%';
|
|
|
+ j--;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ str[i--] = str[j--];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#ifndef WITH_CPPRESTSDK_IN_CENTER
|
|
|
+bool CenterSettingResponse::Parse(string strData)
|
|
|
+{
|
|
|
+ Json::Value root;
|
|
|
+ Json::Reader reader;
|
|
|
+ Json::Value arrConfig;
|
|
|
+
|
|
|
+ reader.parse(strData, root, false);
|
|
|
+
|
|
|
+ m_success = root["success"].asBool();
|
|
|
+
|
|
|
+ if(m_success)
|
|
|
+ {
|
|
|
+ m_message = root["message"].asString();
|
|
|
+ m_is_update = root["data"]["is_update"].asBool();
|
|
|
+ m_is_reset = root["data"]["is_reset"].asBool();
|
|
|
+ m_version_no = root["data"]["version_no"].asString();
|
|
|
+ transferblank(m_version_no);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_version_no:%s", m_version_no.c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_is_reset:%d", m_is_reset ? 1 : 0);
|
|
|
+ m_sm3 = root["data"]["sm3"].asString();
|
|
|
+ m_strConfig = root["data"]["config"].asString();
|
|
|
+
|
|
|
+ if(m_is_update)
|
|
|
+ {
|
|
|
+ reader.parse(m_strConfig, arrConfig, false);
|
|
|
+ if(arrConfig.isArray())
|
|
|
+ {
|
|
|
+ for(int j = 0; j < arrConfig.size(); j++)
|
|
|
+ {
|
|
|
+ ConfigItem configItem;
|
|
|
+
|
|
|
+ configItem.m_moudle = arrConfig[j]["moudle"].asString();
|
|
|
+ configItem.m_name = arrConfig[j]["name"].asString();
|
|
|
+ configItem.m_value = arrConfig[j]["value"].asString();
|
|
|
+
|
|
|
+ m_config.push_back(configItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+bool AddVersionResponse::Parse(string strData)
|
|
|
+{
|
|
|
+ Json::Value root;
|
|
|
+ Json::Reader reader;
|
|
|
+ reader.parse(strData, root, false);
|
|
|
+ m_success = root["success"].asBool();
|
|
|
+ return m_success;
|
|
|
+}
|
|
|
+
|
|
|
+CenterSettingsMicroServiceHelper::CenterSettingsMicroServiceHelper(CEntityBase* pEntity)
|
|
|
+ :m_pEntity(pEntity), m_strLastTime(true), m_strCurSite(true), m_arrKeys(NULL), m_arrURLs(NULL), m_isFirst(true)
|
|
|
+{
|
|
|
+ m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, m_pCenterConfig);
|
|
|
+ m_pEntity->GetFunction()->OpenConfig(Config_Run, m_pRunConfig);
|
|
|
+
|
|
|
+ m_pEntity->GetFunction()->GetSystemStaticInfo(m_terminalInfo);
|
|
|
+ m_pHttpFunc = create_http(HTTPLogCallback);
|
|
|
+
|
|
|
+ InitCenterSettingInfo();
|
|
|
+}
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+int CenterSettingsMicroServiceHelper::GetCenterSetting()
|
|
|
+{
|
|
|
+#else
|
|
|
+int CenterSettingsMicroServiceHelper::GetCenterSetting(bool byHand)
|
|
|
+{
|
|
|
+#endif
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
+ if(m_strUrl.IsNullOrEmpty() && m_urlsFromShell.size() <= 0)
|
|
|
+ {
|
|
|
+ m_strErrMsg = "集中配置服务地址不存在";
|
|
|
+ return AllAddressNull;
|
|
|
+ }
|
|
|
+
|
|
|
+ CenterSettingReq req;
|
|
|
+ CenterSettingResponse res;
|
|
|
+ req.m_terminal_no = m_terminalInfo.strTerminalID.GetData();
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_strFilePath:%s", m_strFilePath.GetData());
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ if(!ExistsFile(m_strFilePath))
|
|
|
+ {
|
|
|
+ Dbg("!ExistsFile(m_strFilePath)");
|
|
|
+#else
|
|
|
+if ((byHand && !m_isFirst) || !ExistsFile(m_strFilePath))
|
|
|
+ {
|
|
|
+ if (byHand && !m_isFirst && ExistsFileA(m_strFilePath)) {
|
|
|
+ LogWarn(Severity_Low, Error_Debug, EVENT_MOD_CENTERSETTING_UPDATE_CENTER_FORCE, "尝试强制重新下载集中配置");
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ req.m_version = "";
|
|
|
+ req.m_config = "";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+#ifdef RVC_OS_LINUX
|
|
|
+if (m_isFirst) //如果是第一次更新则强制下载集中配置
|
|
|
+ {
|
|
|
+ req.m_version = "";
|
|
|
+ req.m_config = "";
|
|
|
+ }
|
|
|
+ else
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ req.m_version = m_strVersion.GetData();
|
|
|
+ req.m_config = GetLocalConfig();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(m_isFirst) m_isFirst = false;
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_strVersion:%s", req.m_version.c_str());
|
|
|
+ req.m_update_time = GetUpdateTime();
|
|
|
+ GetTimeoutValue(req.m_timeOut);
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")(CSimpleStringA::Format("timeout:%d", req.m_timeOut));
|
|
|
+
|
|
|
+ int ret1 = MANUAL, ret2 = MANUAL;
|
|
|
+ if(!m_strUrl.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ req.m_url = m_strUrl;
|
|
|
+ m_strCurUrl = req.m_url;
|
|
|
+ req.m_url += "?update_time=" + req.m_update_time + "&terminal_no=" + req.m_terminal_no + "&version=" + req.m_version;
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ ret1 = OnRequest(req, res, m_strErrMsg);
|
|
|
+#else
|
|
|
+ ret1 = GetCenterSettingsFromHttp(req, m_strErrMsg);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("集中配置文件中地址为空,使用默认地址");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(SUCC != ret1 && ret1 != EXIST)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(m_urlsFromShell.size() <= 0)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("shell.ini中找不到集中配置地址");
|
|
|
+ return ret1;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i = 0; i < m_urlsFromShell.size(); i++)
|
|
|
+ {
|
|
|
+ req.m_url = m_urlsFromShell[i].GetData();
|
|
|
+ m_strCurUrl = m_urlsFromShell[i].GetData();
|
|
|
+ req.m_url += "?update_time=" + req.m_update_time + "&terminal_no=" + req.m_terminal_no + "&version=" + req.m_version;
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ ret2 = OnRequest(req, res);
|
|
|
+ if(ret2 == SUCC)
|
|
|
+ break;
|
|
|
+#else
|
|
|
+ ret1 = GetCenterSettingsFromHttp(req, m_strErrMsg);
|
|
|
+ if (ret1 == SUCC || ret1 == EXIST)
|
|
|
+ break;
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ if(SUCC == ret1 || SUCC == ret2)
|
|
|
+ {
|
|
|
+ if(!res.m_is_update)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("Centersetting not changed.");
|
|
|
+ m_strErrMsg = "集中配置已是最新版本";
|
|
|
+ return EXIST;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(WriteToConfig(res))
|
|
|
+ {
|
|
|
+ m_strVersion = res.m_version_no.c_str();
|
|
|
+ Dbg("WriteToConfig m_strVersion:%s", m_strVersion.GetData());
|
|
|
+ m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, m_pCenterConfig, true);
|
|
|
+ m_pRunConfig->WriteConfigValue("CenterSetting", "version", m_strVersion);
|
|
|
+ UpdateVersion();
|
|
|
+ if(res.m_is_reset)
|
|
|
+ LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "Update centersetting with critical items.");
|
|
|
+
|
|
|
+ return SUCC;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ return ret1;
|
|
|
+}
|
|
|
+
|
|
|
+void CenterSettingsMicroServiceHelper::InitCenterSettingInfo()
|
|
|
+{
|
|
|
+ CSmartPointer<IConfigInfo> shellConfig;
|
|
|
+ m_pEntity->GetFunction()->OpenConfig(Config_Shell, shellConfig);
|
|
|
+
|
|
|
+ m_pCenterConfig->ReadConfigValue("CenterSetting", "LastUpdateTime", m_strLastTime);
|
|
|
+ m_pRunConfig->ReadConfigValue("CenterSetting", "version", m_strVersion);
|
|
|
+#ifdef RVC_OS_LINUX
|
|
|
+ if (!m_strVersion.IsNullOrEmpty()) {
|
|
|
+ std::string tmp = m_strVersion.GetData();
|
|
|
+ transferblank(tmp);
|
|
|
+ m_strVersion = tmp.c_str();
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ //从集中配置和shell.ini获取url
|
|
|
+ m_pCenterConfig->ReadConfigValue("CenterSetting", "CenterConfigUrlNew", m_strUrl);
|
|
|
+ if(m_strUrl.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitCenterSettingInfo")("集中配置中的服务链接为空,使用默认链接");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterConfigUrlNew:%s", m_strUrl.GetData());
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA strMicroServiceURLSection = "MicroServiceURL";
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN /** UOS配置后置后没这堆玩意,至少现在的配置中没有 但是windows还有[Gifur@202397]*/
|
|
|
+#ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-ST";
|
|
|
+#elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-UAT";
|
|
|
+#elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
|
|
|
+ //strMicroServiceURLSection = "MicroServiceURL-PRD";
|
|
|
+#elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-Dev";
|
|
|
+#else/*本地编译等非DevOps环境编译的版本*/
|
|
|
+ strMicroServiceURLSection = "MicroServiceURL-Dev";
|
|
|
+#endif
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitCenterSettingInfo")("获取集中配置服务地址 Section name:%s", strMicroServiceURLSection.GetData());
|
|
|
+
|
|
|
+ shellConfig->ReadAllKeys(strMicroServiceURLSection, m_arrKeys);
|
|
|
+
|
|
|
+ CSimpleStringA strUrl;
|
|
|
+ for(int i = 0; i < m_arrKeys.GetCount() && m_arrKeys[i].IsStartWith("CenterConfigUrl", true); i++)
|
|
|
+ {
|
|
|
+ shellConfig->ReadConfigValue(strMicroServiceURLSection, m_arrKeys[i].GetData(), strUrl);
|
|
|
+ if(!strUrl.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("add CenterURL:%s", strUrl.GetData());
|
|
|
+ m_urlsFromShell.push_back(strUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取集中配置路径、文件名、场所
|
|
|
+ m_pEntity->GetFunction()->GetPath("CenterSetting", m_strFilePath);
|
|
|
+ m_pEntity->GetFunction()->GetPath("RunInfo", m_strBakPath);
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ m_strBakPath += "\\runcfg\\CenterSetting.ini";
|
|
|
+#else
|
|
|
+ m_strBakPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "CenterSetting.ini";
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+bool CenterSettingsMicroServiceHelper::WriteToConfig(const CenterSettingResponse& sResponse)
|
|
|
+{
|
|
|
+ CSimpleStringA newPath = m_strBakPath + ".new";
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config size: %d", sResponse.m_config.size());
|
|
|
+ for(int i = 0; i < sResponse.m_config.size(); i++)
|
|
|
+ {
|
|
|
+ string module = sResponse.m_config[i].m_moudle;
|
|
|
+ string name = sResponse.m_config[i].m_name;
|
|
|
+ string value = sResponse.m_config[i].m_value;
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ if(!WritePrivateProfileStringA(module.c_str(), name.c_str(), value.c_str(), newPath))
|
|
|
+ {
|
|
|
+#else
|
|
|
+ if (inifile_write_str(newPath.GetData(), module.c_str(), name.c_str(), value.c_str()) == -1)
|
|
|
+ {
|
|
|
+#endif
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("WriteToConfig")
|
|
|
+ ("write %s:%s:%s fail", module.c_str(), name.c_str(), value.c_str());
|
|
|
+ m_strErrMsg = "集中配置写入失败";
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_MOD_CENTERSETTING_WRITE_FAILED,
|
|
|
+ CSimpleStringA::Format("集中配置写入失败:%s:%s:%s", module.c_str(), name.c_str(), value.c_str()));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("WriteToConfig")("集中配置写入成功");
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ CopyFileA(newPath, m_strFilePath, FALSE);
|
|
|
+ DeleteFileA(newPath);
|
|
|
+#else
|
|
|
+ fileutil_copy_file(m_strFilePath, newPath);
|
|
|
+ fileutil_delete_file(newPath);
|
|
|
+#endif
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+string CenterSettingsMicroServiceHelper::GetLocalConfig()
|
|
|
+{
|
|
|
+ CAutoArray<CSimpleStringA> arrSections, arrKeys;
|
|
|
+ CSimpleStringA strItem;
|
|
|
+
|
|
|
+ if(Error_Succeed != m_pCenterConfig->ReadAllSections(arrSections))
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetLocalConfig")("Read all sections failed.");
|
|
|
+
|
|
|
+ if(arrSections.GetCount() == 0)
|
|
|
+ return "";
|
|
|
+
|
|
|
+ for(int i = 0; i < arrSections.GetCount(); ++i)
|
|
|
+ {
|
|
|
+ m_pCenterConfig->ReadAllKeys(arrSections[i].GetData(), arrKeys);
|
|
|
+ for(int j = 0; j < arrKeys.GetCount(); ++j)
|
|
|
+ {
|
|
|
+ CSimpleStringA value, tmp;
|
|
|
+ m_pCenterConfig->ReadConfigValue(arrSections[i].GetData(), arrKeys[j].GetData(), value);
|
|
|
+
|
|
|
+ tmp = CSimpleStringA::Format("{\"moudle\":\"%s\", \"name\":\"%s\", \"value\":\"%s\"}",
|
|
|
+ arrSections[i].GetData(), arrKeys[j].GetData(), value.GetData());
|
|
|
+
|
|
|
+ strItem += tmp + ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ string strConfig = strItem.SubString(0, strItem.GetLength() - 1).GetData();
|
|
|
+ convert(strConfig);
|
|
|
+ return strConfig;
|
|
|
+}
|
|
|
+
|
|
|
+void CenterSettingsMicroServiceHelper::UpdateVersion()
|
|
|
+{
|
|
|
+ AddVersionReq sReq;
|
|
|
+ AddVersionResponse sResponse;
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ CSimpleStringA url;
|
|
|
+ m_pCenterConfig->ReadConfigValue("CenterSetting", "UpdateVersionUrl", url);
|
|
|
+ sReq.m_url = url.GetData();
|
|
|
+ sReq.m_terminal_no = m_terminalInfo.strTerminalID.GetData();
|
|
|
+ sReq.m_version = m_strVersion;
|
|
|
+ sReq.m_update_time = GetUpdateTime();
|
|
|
+ GetTimeoutValue(sReq.m_timeOut);
|
|
|
+
|
|
|
+ //IHttpFunc* m_pHttpFunc = create_http(HTTPLogCallback);
|
|
|
+ PROCESS_LINK_CONTEXT("LR0402101UploadVersion")
|
|
|
+ bool ret = m_pHttpFunc->Post(sReq, sResponse, &nextLink);
|
|
|
+
|
|
|
+ if(ret && sResponse.m_success)
|
|
|
+ {
|
|
|
+ CSimpleStringA msg = CSimpleStringA::Format("上传版本号成功:{version : %s, update_time : %s}",
|
|
|
+ sReq.m_version.c_str(), sReq.m_update_time.c_str());
|
|
|
+ LogWarn(Severity_Low, Error_Succeed, EVENT_MOD_CENTERSETTING_UPDATE_VERSION_SUCC, msg.GetData());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CSimpleStringA msg = CSimpleStringA::Format("上传版本号失败:%s", sResponse.m_errMsg.c_str());
|
|
|
+ LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_UPDATE_VERSION_FAILED, msg.GetData());
|
|
|
+
|
|
|
+ }
|
|
|
+#else
|
|
|
+ struct UpdateVersionReq //Req和Ans的变量名必须和服务端json要求的一致,切记!
|
|
|
+ {
|
|
|
+ string terminal_no;
|
|
|
+ string version_no;
|
|
|
+ string terminal_update_time;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(terminal_no, version_no, terminal_update_time)
|
|
|
+ } updateVersionReq;
|
|
|
+
|
|
|
+ CSimpleStringA url;
|
|
|
+ m_pCenterConfig->ReadConfigValue("CenterSetting", "UpdateVersionUrl", url);
|
|
|
+
|
|
|
+ HttpClientResponseResult result;
|
|
|
+ HttpClientRequestConfig config(HttpRequestMethod::POST, url.GetData(), &SpGetToken);
|
|
|
+
|
|
|
+ updateVersionReq.terminal_no = m_terminalInfo.strTerminalID.GetData();
|
|
|
+ updateVersionReq.version_no = m_strVersion;
|
|
|
+ updateVersionReq.terminal_update_time = GetUpdateTime();
|
|
|
+
|
|
|
+ SP::Module::Restful::FulfillRequestJsonBody(&config, updateVersionReq);
|
|
|
+
|
|
|
+ RestfulClient client = RestfulClient::getInstance();
|
|
|
+ PROCESS_LINK_CONTEXT("LR0402101UpdateVersion");
|
|
|
+ config.PreDo();
|
|
|
+ client.Do(&config, &result, &nextLink);
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("返回内容为 %s", result.content.length() > 1000 ? result.content.substr(0, 1000).c_str() : result.content.c_str());
|
|
|
+
|
|
|
+ if (!result.ResponseOK()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Do failed: %s", result.WhatError().c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SP::Module::Restful::CommResponseJson responseStatus;
|
|
|
+ SP::Module::Restful::GetStatusFromDebranchResponse(result.content, responseStatus);
|
|
|
+
|
|
|
+ if (responseStatus.success) {
|
|
|
+ CSimpleStringA msg = CSimpleStringA::Format("上传版本号成功:{version : %s, update_time : %s}",
|
|
|
+ updateVersionReq.version_no.c_str(), updateVersionReq.terminal_update_time.c_str());
|
|
|
+ LogWarn(Severity_Low, Error_Succeed, EVENT_MOD_CENTERSETTING_UPDATE_VERSION_SUCC, msg.GetData());
|
|
|
+ } else {
|
|
|
+ CSimpleStringA msg = CSimpleStringA::Format("上传版本号失败:%s", result.content.c_str());
|
|
|
+ LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_UPDATE_VERSION_FAILED, msg.GetData());
|
|
|
+
|
|
|
+ }
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+SYSTEMTIME GetModifyTime(const string& strFilename)
|
|
|
+{
|
|
|
+#if defined(_MSC_VER)
|
|
|
+ struct _stat64i32 statbuf;
|
|
|
+ _stat64i32(strFilename.c_str(), &statbuf);
|
|
|
+ struct tm* temptm = _localtime64(&statbuf.st_mtime);
|
|
|
+#else
|
|
|
+ struct stat statbuf;
|
|
|
+ ZeroMemory(&statbuf, sizeof(statbuf));
|
|
|
+ stat(strFilename.c_str(), &statbuf);
|
|
|
+ struct tm* temptm = localtime(&statbuf.st_mtime);
|
|
|
+#endif //_MSC_VER
|
|
|
+
|
|
|
+ SYSTEMTIME st = { 1900 + temptm->tm_year,
|
|
|
+ 1 + temptm->tm_mon,
|
|
|
+ temptm->tm_wday,
|
|
|
+ temptm->tm_mday,
|
|
|
+ temptm->tm_hour,
|
|
|
+ temptm->tm_min,
|
|
|
+ temptm->tm_sec,
|
|
|
+ 0 };
|
|
|
+
|
|
|
+ return st;
|
|
|
+}
|
|
|
+
|
|
|
+string CenterSettingsMicroServiceHelper::GetUpdateTime()
|
|
|
+{
|
|
|
+ CSimpleStringA strUpdateTime;
|
|
|
+
|
|
|
+ /** 配置后置后本地没有这个实体文件,都被框架放到运行时了,所以需要处理这个逻辑 [Gifur@202397]*/
|
|
|
+ if(ExistsFileA(m_strFilePath))
|
|
|
+ {
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ struct _stat64i32 statbuf;
|
|
|
+ _stat64i32(m_strFilePath.GetData(), &statbuf);
|
|
|
+#endif
|
|
|
+ SYSTEMTIME st = GetModifyTime(m_strFilePath.GetData());
|
|
|
+ strUpdateTime = CSimpleStringA::Format("%d-%02d-%02d-%02d:%02d:%02d",
|
|
|
+ st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ SYSTEMTIME st, stLocal;
|
|
|
+ GetSystemTime(&st);
|
|
|
+ SystemTimeToTzSpecificLocalTime(NULL, &st, &stLocal);
|
|
|
+#else
|
|
|
+ SYSTEMTIME stLocal = CSmallDateTime::GetNow().ToSystemTime();
|
|
|
+#endif
|
|
|
+ strUpdateTime = CSimpleStringA::Format("%d-%02d-%02d-%02d:%02d:%02d",
|
|
|
+ stLocal.wYear, stLocal.wMonth, stLocal.wDay,
|
|
|
+ stLocal.wHour, stLocal.wMinute, stLocal.wSecond);
|
|
|
+ }
|
|
|
+ return strUpdateTime.GetData();
|
|
|
+}
|
|
|
+
|
|
|
+void CenterSettingsMicroServiceHelper::GetTimeoutValue(int& timeout)
|
|
|
+{
|
|
|
+ int timeoutFromConfig = 0;
|
|
|
+ m_pCenterConfig->ReadConfigValueInt("CenterSetting", "Timeout", timeoutFromConfig);
|
|
|
+ if(timeoutFromConfig == 0)
|
|
|
+ return;
|
|
|
+ else
|
|
|
+ timeout = timeoutFromConfig;
|
|
|
+}
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+int CenterSettingsMicroServiceHelper::OnRequest(CenterSettingReq& req, CenterSettingResponse& res, string& errMsg)
|
|
|
+{
|
|
|
+ PROCESS_LINK_CONTEXT("LR0402101SyncCenter")
|
|
|
+ bool ret = m_pHttpFunc->Post(req, res, &nextLink);
|
|
|
+
|
|
|
+ if(ret && res.m_success)
|
|
|
+ {
|
|
|
+ if(!res.m_is_update)
|
|
|
+ return SUCC;
|
|
|
+
|
|
|
+ ConvertGBKToUtf8(res.m_strConfig);
|
|
|
+ string strConfig = res.m_strConfig;
|
|
|
+
|
|
|
+
|
|
|
+ BYTE sm3[32] = {};
|
|
|
+ if(strConfig.length() > 2)
|
|
|
+ {
|
|
|
+ if (!SM3Hash((BYTE*)(strConfig.c_str()), strlen(strConfig.c_str()), sm3))
|
|
|
+ {
|
|
|
+ errMsg = "计算SM3失败";
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")
|
|
|
+ (CSimpleStringA::Format("计算SM3失败(%s)", req.m_url.c_str()));
|
|
|
+ return CalcSM3Fail;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int sm3len = sizeof(sm3);
|
|
|
+ char* strsm3 = ConvertBytesToHexStr(sm3, 32);
|
|
|
+
|
|
|
+ if(0 != strcmp(strsm3, res.m_sm3.c_str()))
|
|
|
+ {
|
|
|
+ errMsg = "SM3校验失败";
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")
|
|
|
+ (CSimpleStringA::Format("SM3校验失败(%s)", req.m_url.c_str()));
|
|
|
+ return CheckSM3Fail;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_strVersion = res.m_version_no.c_str();
|
|
|
+
|
|
|
+ return SUCC;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //ConvertUtf8ToGBK(res.m_errMsg);
|
|
|
+ errMsg = res.m_errMsg;
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnRequest")
|
|
|
+ (CSimpleStringA::Format("访问失败:%s", res.m_errMsg.c_str()));
|
|
|
+
|
|
|
+ if(res.m_sysCode == 28 || res.m_sysCode == 7)
|
|
|
+ return AccessServiceFail;
|
|
|
+
|
|
|
+ return MANUAL;
|
|
|
+ }
|
|
|
+}
|
|
|
+#else
|
|
|
+int CenterSettingsMicroServiceHelper::GetCenterSettingsFromHttp(CenterSettingReq& req, string& errMsg)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ CenterSettingResponse res;
|
|
|
+
|
|
|
+ struct GetCenterSettingReq //Req和Ans的变量名必须和服务端json要求的一致,切记!
|
|
|
+ {
|
|
|
+ string m_terminal_no;
|
|
|
+ string m_version;
|
|
|
+ string m_update_time;
|
|
|
+ string m_config;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(m_terminal_no, m_version, m_update_time, m_config)
|
|
|
+ } getCenterSettingReq;
|
|
|
+
|
|
|
+ struct GetCenterSettingAns //Req和Ans的变量名必须和服务端json要求的一致,切记!
|
|
|
+ {
|
|
|
+ bool success;
|
|
|
+ string message;
|
|
|
+ bool is_update;
|
|
|
+ bool is_reset;
|
|
|
+ string version_no;
|
|
|
+ string sm3;
|
|
|
+ string config;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, message, is_update, is_reset, version_no, sm3, config)
|
|
|
+ }getCenterSettingAns;
|
|
|
+
|
|
|
+ HttpClientResponseResult result;
|
|
|
+ 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;
|
|
|
+ getCenterSettingReq.m_version = req.m_version;
|
|
|
+ getCenterSettingReq.m_update_time = req.m_update_time;
|
|
|
+ getCenterSettingReq.m_config = req.m_config;
|
|
|
+
|
|
|
+ SP::Module::Restful::FulfillRequestJsonBody(&config, getCenterSettingReq);
|
|
|
+
|
|
|
+ Dbg("Geting centtersetting...");
|
|
|
+
|
|
|
+ RestfulClient client = RestfulClient::getInstance();
|
|
|
+ PROCESS_LINK_CONTEXT("LR0402101GetCenterSetting");
|
|
|
+ config.PreDo();
|
|
|
+ client.Do(&config, &result, &nextLink);
|
|
|
+
|
|
|
+ Dbg("ret result.ResponseOK() = %d.", result.ResponseOK());
|
|
|
+ if (!result.ResponseOK()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Do failed: %s", result.WhatError().c_str());
|
|
|
+ errMsg = result.WhatError();
|
|
|
+ return AccessServiceFail;
|
|
|
+ }
|
|
|
+ SP::Module::Restful::CommResponseJson responseStatus;
|
|
|
+ SP::Module::Restful::GetStatusFromDebranchResponse(result.content, responseStatus);
|
|
|
+ if (!responseStatus.IsOperatedOK()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)(result.content.c_str());
|
|
|
+ errMsg = responseStatus.WhatError().c_str();
|
|
|
+ return MANUAL;
|
|
|
+ }
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", result.content.length() > 1000 ? result.content.substr(0, 1000).c_str() : result.content.c_str());
|
|
|
+ if (!SP::Module::Restful::ExtractDataFromDebranchResponse(result.content, getCenterSettingAns)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("parse json data node failed: ");
|
|
|
+ errMsg = "解析集中配置返回的信息失败";
|
|
|
+ return UNknown;
|
|
|
+ }
|
|
|
+ //transferblank(centerSettingAns.version_no);
|
|
|
+ ///** 当时粤超开发Windows版本时,要求服务端将数组转化为字符串传送,这边信创为了兼容,需要重新转为数组处理(信创是支持JSON数组) [Gifur@202398]*/
|
|
|
+ //string strConfig = centerSettingAns.config;
|
|
|
+ //vector<ConfigItem> m_config;
|
|
|
+ //SP::Utility::replaceInPlace(centerSettingAns.config, "\\\"", "\"");
|
|
|
+ //if (!Json2Object(m_config, centerSettingAns.config)) {
|
|
|
+ // DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("parse config content failed!");
|
|
|
+ // errMsg = "解析集中配置返回的配置信息失败";
|
|
|
+ // return UNknown;
|
|
|
+ //}
|
|
|
+ res.Parse(result.content);
|
|
|
+ string strConfig = SP::Utility::GBK2UTF8(res.m_strConfig);
|
|
|
+
|
|
|
+ if (!res.m_is_update) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("Centersetting not changed.");
|
|
|
+ errMsg = "集中配置已是最新版本";
|
|
|
+ return EXIST;
|
|
|
+ }
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config length:%d", strConfig.length());
|
|
|
+
|
|
|
+ BYTE sm3[32] = {};
|
|
|
+ if (strConfig.length() > 2) {
|
|
|
+ if (!SM3Hash((BYTE*)(strConfig.c_str()), strConfig.length(), sm3)) {
|
|
|
+ errMsg = "计算SM3失败";
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSettingsFromHttp")("计算SM3失败(%s)", req.m_url.c_str());
|
|
|
+ return CalcSM3Fail;
|
|
|
+ } else {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sm3:%s", res.m_sm3.c_str());
|
|
|
+ char* strsm3 = SP::Module::Util::ConvertBytesToHexStr(sm3, 32);
|
|
|
+ if (0 != strcmp(strsm3, res.m_sm3.c_str())) {
|
|
|
+ errMsg = "SM3校验失败";
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSettingsFromHttp")("SM3校验失败(%s)", req.m_url.c_str());
|
|
|
+ delete[] strsm3;
|
|
|
+ return CheckSM3Fail;
|
|
|
+ }
|
|
|
+ m_strVersion = res.m_version_no.c_str();
|
|
|
+ delete[] strsm3;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (WriteToConfig(res)) {
|
|
|
+ m_strVersion = res.m_version_no.c_str();
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("WriteToConfig m_strVersion:%s", m_strVersion.GetData());
|
|
|
+ m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, m_pCenterConfig, true);
|
|
|
+ m_pRunConfig->WriteConfigValue("CenterSetting", "version", m_strVersion);
|
|
|
+ UpdateVersion();
|
|
|
+ if (res.m_is_reset) {
|
|
|
+ LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "Update centersetting with critical items.");
|
|
|
+ }
|
|
|
+ return SUCC;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return UNknown;
|
|
|
+}
|
|
|
+#endif
|