|
|
@@ -32,7 +32,7 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
|
|
|
std::map<string, string> params;
|
|
|
|
|
|
std::string response;
|
|
|
- bool ret = m_client.Request("/login/login", params, response);
|
|
|
+ bool ret = m_client.RequestNew("/login/login", params, response);
|
|
|
|
|
|
if (!ret)
|
|
|
{
|
|
|
@@ -67,22 +67,17 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> params, std::string& response)
|
|
|
+bool CZhipuziHttpClient::RequestOld(std::string url, std::map<string, string> params, std::string& response)
|
|
|
{
|
|
|
std::string timestamp = to_string(time(NULL));
|
|
|
std::string nonce = "123456";
|
|
|
- std::string machinecode = "e6bc5694877b2aec";
|
|
|
-
|
|
|
- std::string lwm_appid = "84b19199fd221a78c491cd553cbb4ab7";
|
|
|
- std::string open_secret = "#repast!@#AfAS#@!";
|
|
|
|
|
|
//先添加默认参数,用于计算签名
|
|
|
- params["machinecode"] = machinecode;
|
|
|
- params["username"] = m_username;
|
|
|
- params["password"] = md5(m_password);
|
|
|
- params["lwm_appid"] = "84b19199fd221a78c491cd553cbb4ab7";
|
|
|
+ params["machinecode"] = m_client.m_machinecode;
|
|
|
+ params["username"] = m_client.m_username;
|
|
|
params["nonce"] = nonce;
|
|
|
params["timestamp"] = timestamp;
|
|
|
+ params["url"] = m_client.m_old_url + url;
|
|
|
|
|
|
//计算签名
|
|
|
std::string postString;
|
|
|
@@ -101,8 +96,10 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
|
|
|
LOG_INFO("postString:" << postString.c_str());
|
|
|
|
|
|
//用于计算签名的临时变量
|
|
|
- string tmp = md5(postString);
|
|
|
- tmp += open_secret;
|
|
|
+ std::string password = md5(m_client.m_password);
|
|
|
+ transform(password.begin(), password.end(), password.begin(), ::toupper);
|
|
|
+
|
|
|
+ string tmp = postString + password;
|
|
|
|
|
|
std::string sign = md5(tmp);
|
|
|
transform(sign.begin(), sign.end(), sign.begin(), ::toupper);
|
|
|
@@ -110,6 +107,7 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
|
|
|
|
|
|
//加上签名,去掉url,计算post
|
|
|
params["sign"] = sign;
|
|
|
+ params.erase("url");
|
|
|
|
|
|
postString = "";
|
|
|
for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
|
|
|
@@ -126,7 +124,8 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
|
|
|
|
|
|
LOG_INFO("postString:" << postString.c_str());
|
|
|
|
|
|
- int ret = m_httpClient.Posts(m_url + url, postString, response, NULL);
|
|
|
+ CHttpClient m_httpClient;
|
|
|
+ int ret = m_httpClient.Posts(m_client.m_old_url + url, postString, response, NULL);
|
|
|
|
|
|
LOG_INFO("response:" << response.c_str());
|
|
|
|
|
|
@@ -137,25 +136,76 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
+}
|
|
|
|
|
|
-/*
|
|
|
- rapidjson::Document doc;
|
|
|
- doc.SetObject();
|
|
|
- rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); //获取分配器
|
|
|
+bool CZhipuziHttpClient::RequestNew(std::string url, std::map<string, string> params, std::string& response)
|
|
|
+{
|
|
|
+ std::string timestamp = to_string(time(NULL));
|
|
|
+ std::string nonce = "123456";
|
|
|
+
|
|
|
+ std::string lwm_appid = "84b19199fd221a78c491cd553cbb4ab7";
|
|
|
+ std::string open_secret = "#repast!@#AfAS#@!";
|
|
|
|
|
|
- doc.AddMember(rapidjson::StringRef("useranme"), rapidjson::StringRef(m_username.c_str()), allocator);
|
|
|
+ //先添加默认参数,用于计算签名
|
|
|
+ params["machinecode"] = m_client.m_machinecode;
|
|
|
+ params["username"] = m_client.m_username;
|
|
|
+ params["password"] = md5(m_client.m_password);
|
|
|
+ params["lwm_appid"] = "84b19199fd221a78c491cd553cbb4ab7";
|
|
|
+ params["nonce"] = nonce;
|
|
|
+ params["timestamp"] = timestamp;
|
|
|
|
|
|
- doc.AddMember(rapidjson::StringRef("timestamp"), rapidjson::StringRef(timestamp.c_str()), allocator);
|
|
|
+ //计算签名
|
|
|
+ std::string postString;
|
|
|
+ for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
|
|
|
+ {
|
|
|
+ postString += it->first + "=" + it->second;
|
|
|
|
|
|
-
|
|
|
- doc.AddMember(rapidjson::StringRef("nonce"), rapidjson::StringRef(nonce.c_str()), allocator);
|
|
|
+ it++;
|
|
|
|
|
|
- doc.AddMember(rapidjson::StringRef("machinecode"), rapidjson::StringRef(machinecode.c_str()), allocator);
|
|
|
+ if (it != params.end())
|
|
|
+ {
|
|
|
+ postString += "&";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- rapidjson::StringBuffer buffer;
|
|
|
- rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
|
|
- doc.Accept(writer);
|
|
|
- std::string json = std::string(buffer.GetString());
|
|
|
+ LOG_INFO("postString:" << postString.c_str());
|
|
|
|
|
|
- LOG_INFO("json:" << json.c_str());*/
|
|
|
+ //用于计算签名的临时变量
|
|
|
+ string tmp = md5(postString);
|
|
|
+ tmp += open_secret;
|
|
|
+
|
|
|
+ std::string sign = md5(tmp);
|
|
|
+ transform(sign.begin(), sign.end(), sign.begin(), ::toupper);
|
|
|
+ LOG_INFO("sign:" << sign.c_str());
|
|
|
+
|
|
|
+ //加上签名,去掉url,计算post
|
|
|
+ params["sign"] = sign;
|
|
|
+
|
|
|
+ postString = "";
|
|
|
+ for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
|
|
|
+ {
|
|
|
+ postString += it->first + "=" + it->second;
|
|
|
+
|
|
|
+ it++;
|
|
|
+
|
|
|
+ if (it != params.end())
|
|
|
+ {
|
|
|
+ postString += "&";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LOG_INFO("postString:" << postString.c_str());
|
|
|
+
|
|
|
+ CHttpClient m_httpClient;
|
|
|
+ int ret = m_httpClient.Posts(m_client.m_new_url + url, postString, response, NULL);
|
|
|
+
|
|
|
+ LOG_INFO("response:" << response.c_str());
|
|
|
+
|
|
|
+ if (ret == 0)
|
|
|
+ {
|
|
|
+ //ret为0表示没有出错
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|