|
@@ -19,6 +19,10 @@ int CNetWork::GetHttpStatus() {
|
|
|
return m_http_status;
|
|
|
}
|
|
|
|
|
|
+void CNetWork::SetUrlArray(std::vector<ServerListUrl> data) {
|
|
|
+ m_url_list = data;
|
|
|
+}
|
|
|
+
|
|
|
HTTPRET CNetWork::Version(std::string& data) {
|
|
|
std::vector<cpr::Parameter> p;
|
|
|
p.push_back({ "tag","win" });
|
|
@@ -70,6 +74,7 @@ HTTPRET CNetWork::GetServerNode(std::string& data) {
|
|
|
|
|
|
HTTPRET CNetWork::GetSysConfig(std::string& data)
|
|
|
{
|
|
|
+
|
|
|
std::vector<cpr::Parameter> p;
|
|
|
std::string text = GetUrl("/api/client/v3/getconfig", p);
|
|
|
if (text.empty()) {
|
|
@@ -144,6 +149,9 @@ HTTPRET CNetWork::PostLogin(LPCSTR username, LPCSTR password, std::string& data)
|
|
|
}
|
|
|
|
|
|
HTTPRET CNetWork::GetSysConfigFromUser(LPCSTR username, LPCSTR password, std::string& data) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
std::vector<cpr::Parameter> p;
|
|
|
p.push_back({ "email",username });
|
|
|
p.push_back({ "password",password });
|
|
@@ -226,6 +234,8 @@ SStringW CNetWork::GetLastErrorW()
|
|
|
|
|
|
std::string CNetWork::GetUrl(std::string path, std::vector<cpr::Parameter> parame,std::string token)
|
|
|
{
|
|
|
+ AutoToggleNode();
|
|
|
+
|
|
|
cpr::Parameters ps;
|
|
|
std::vector<cpr::Parameter>::iterator it_i;
|
|
|
for (it_i = parame.begin(); it_i != parame.end(); ++it_i)
|
|
@@ -244,7 +254,7 @@ std::string CNetWork::GetUrl(std::string path, std::vector<cpr::Parameter> param
|
|
|
hander = cpr::Header{ {"accept", "application/json"} };
|
|
|
}
|
|
|
|
|
|
- auto s = fmt::format("{0}{1}", m_url, path.c_str());
|
|
|
+
|
|
|
|
|
|
cpr::Response r;
|
|
|
|
|
@@ -252,12 +262,15 @@ std::string CNetWork::GetUrl(std::string path, std::vector<cpr::Parameter> param
|
|
|
std::string res_test = "";
|
|
|
//auto session = GetSession();
|
|
|
int count = 3;
|
|
|
+ /*int serverurlid = 0;*/
|
|
|
do
|
|
|
{
|
|
|
if (count <= 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ auto s = fmt::format("{0}{1}", m_url, path.c_str());
|
|
|
|
|
|
if (parame.empty())
|
|
|
{
|
|
@@ -293,6 +306,7 @@ std::string CNetWork::GetUrl(std::string path, std::vector<cpr::Parameter> param
|
|
|
else {
|
|
|
m_error_msg = UpdateError(r.error.code, r.error.message);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (!res_test.empty())
|
|
@@ -379,6 +393,7 @@ std::string CNetWork::PostUrl(std::string path, std::vector<cpr::Pair> parame, s
|
|
|
|
|
|
m_error_msg = UpdateError(r.error.code, r.error.message);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (!res_test.empty())
|
|
@@ -395,7 +410,41 @@ std::string CNetWork::PostUrl(std::string path, std::vector<cpr::Pair> parame, s
|
|
|
|
|
|
return res_test;
|
|
|
}
|
|
|
+void CNetWork::AutoToggleNode() {
|
|
|
+
|
|
|
+ cpr::Header hander;
|
|
|
+ hander = cpr::Header{ {"accept", "application/json"} };
|
|
|
+
|
|
|
+ std::vector<cpr::Parameter> p;
|
|
|
+ p.push_back({ "tag","win" });
|
|
|
+ p.push_back({ "appverion",S_CW2A(VERSION).GetBuffer(0) });
|
|
|
+ cpr::Parameters ps;
|
|
|
+ std::vector<cpr::Parameter>::iterator it_i;
|
|
|
+ for (it_i = p.begin(); it_i != p.end(); ++it_i)
|
|
|
+ {
|
|
|
+ ps.Add(*it_i);
|
|
|
+ //ps(cpr::Parameter({ it->first, it->second }));
|
|
|
+ }
|
|
|
+ //Çл»½Úµã£¬
|
|
|
+ for each (ServerListUrl itme in m_url_list)
|
|
|
+ {
|
|
|
+ auto s = fmt::format("{0}{1}", itme.url, "/api/client/v3/version");
|
|
|
+ m_session.SetHeader(hander);
|
|
|
+ m_session.SetVerifySsl(false);
|
|
|
+ m_session.SetTimeout(cpr::Timeout{ TIMEOUTE });
|
|
|
+ m_session.SetUrl(s.c_str());
|
|
|
+ m_session.SetParameters(ps);
|
|
|
+ auto r = m_session.Get();
|
|
|
+ if (r.status_code == 200) {
|
|
|
+ m_url = itme.url;
|
|
|
+ Logger::getSingletonPtr()->INFO(S_CW2A(itme.name).GetBuffer(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
std::string CNetWork::Retrying(std::string path, std::vector<cpr::Parameter> parame, std::string token)
|
|
|
{
|
|
|
|