Explorar el Código

暂时可以登陆了

张洋 hace 6 años
padre
commit
9a9bb37000

+ 144 - 0
zhipuzi_pay_plugin/network/CZhipuziHttpClient.cpp

@@ -177,6 +177,78 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
     return false;
 }
 
+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 = "kJnkkHODnoloay197k97G129J";
+	std::string open_secret = "kMDNjjid91ydo#!9DH1";
+
+	//先添加默认参数,用于计算签名
+	params["machinecode"] = "d31a20c2567006c5";
+	params["username"] = CLewaimaiString::UrlEncode(m_client.m_username);
+	params["password"] = md5(m_client.m_password);
+	params["lwm_appid"] = lwm_appid;
+	params["nonce"] = nonce;
+	params["timestamp"] = timestamp;
+
+	//计算签名
+	std::string 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());
+
+	//用于计算签名的临时变量
+	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_yewu_ur + url, postString, response, NULL);
+
+	LOG_INFO("response:" << response.c_str());
+
+	if (ret == 0)
+	{
+		//ret为0表示没有出错
+		return true;
+	}
+
+	return false;
+}
+
 bool CZhipuziHttpClient::RequestPingtai(std::string url, std::map<string, string> params, std::string& response)
 {
 	std::string timestamp = to_string(time(NULL));
@@ -247,3 +319,75 @@ bool CZhipuziHttpClient::RequestPingtai(std::string url, std::map<string, string
 
 	return false;
 }
+
+bool CZhipuziHttpClient::RequestPingtaiNew(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#@!";
+
+	//先添加默认参数,用于计算签名
+	params["machinecode"] = "d31a20c2567006c5";
+	params["username"] = CLewaimaiString::UrlEncode(m_client.m_username);
+	params["password"] = md5(m_client.m_password);
+	params["lwm_appid"] = lwm_appid;
+	params["nonce"] = nonce;
+	params["timestamp"] = timestamp;
+
+	//计算签名
+	std::string 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());
+
+	//用于计算签名的临时变量
+	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_pingtai_url + url, postString, response, NULL);
+
+	LOG_INFO("response:" << response.c_str());
+
+	if (ret == 0)
+	{
+		//ret为0表示没有出错
+		return true;
+	}
+
+	return false;
+}

+ 3 - 0
zhipuzi_pay_plugin/network/CZhipuziHttpClient.h

@@ -14,7 +14,10 @@ public:
     static bool Login(std::string& errmsg);
 
     static bool Request(std::string url, std::map<string, string> params, std::string& response);
+	static bool RequestNew(std::string url, std::map<string, string> params, std::string& response);
+
 	static bool RequestPingtai(std::string url, std::map<string, string> params, std::string& response);
+	static bool RequestPingtaiNew(std::string url, std::map<string, string> params, std::string& response);
 public:
     static CZhipuziHttpClient m_client;
 

+ 45 - 16
zhipuzi_pay_plugin/wnd/CLoginWnd.cpp

@@ -538,7 +538,7 @@ void CLoginWnd::HandleLogin()
 		std::string response;
 
 		std::string url = "/common/merchant/account/user/syncuserdata";
-		CZhipuziHttpClient::Request(url.c_str(), params, response);
+		CZhipuziHttpClient::RequestNew(url.c_str(), params, response);
 
 		rapidjson::Document document;
 		document.Parse(response.c_str());
@@ -553,29 +553,58 @@ void CLoginWnd::HandleLogin()
 			return;
 		}
 
-		if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
+		if (document.HasMember("error_code"))
 		{
-			pLoginResultLabel->SetText(std::wstring(_T("服务器错误")).c_str());
-			pLoginResultLabel->SetVisible(true);
+			if (!document.HasMember("error_code") || !document.HasMember("error_msg") || !document.HasMember("data"))
+			{
+				pLoginResultLabel->SetText(std::wstring(_T("服务器错误")).c_str());
+				pLoginResultLabel->SetVisible(true);
 
-			PostMessage(WM_LOGIN_ERROR);
+				PostMessage(WM_LOGIN_ERROR);
 
-			return;
-		}
+				return;
+			}
 
-		rapidjson::Value& v_errcode = document["errcode"];
-		int errcode = v_errcode.GetInt();
-		if (errcode != 0)
-		{
-			std::string errmsg = document["errmsg"].GetString();
+			rapidjson::Value& v_errcode = document["error_code"];
+			int errcode = v_errcode.GetInt();
+			if (errcode != 0)
+			{
+				std::string errmsg = document["error_msg"].GetString();
 
-			pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
-			pLoginResultLabel->SetVisible(true);
+				pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
+				pLoginResultLabel->SetVisible(true);
 
-			PostMessage(WM_LOGIN_ERROR);
+				PostMessage(WM_LOGIN_ERROR);
 
-			return;
+				return;
+			}
 		}
+		else if (document.HasMember("errcode"))
+		{
+			if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
+			{
+				pLoginResultLabel->SetText(std::wstring(_T("服务器错误")).c_str());
+				pLoginResultLabel->SetVisible(true);
+
+				PostMessage(WM_LOGIN_ERROR);
+
+				return;
+			}
+
+			rapidjson::Value& v_errcode = document["errcode"];
+			int errcode = v_errcode.GetInt();
+			if (errcode != 0)
+			{
+				std::string errmsg = document["errmsg"].GetString();
+
+				pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
+				pLoginResultLabel->SetVisible(true);
+
+				PostMessage(WM_LOGIN_ERROR);
+
+				return;
+			}
+		}	
 
 		rapidjson::Value& data = document["data"];
 		rapidjson::Value& shop_name = data["shop_name"];