Selaa lähdekoodia

网络代理的前置工作

zhangyang 5 vuotta sitten
vanhempi
commit
4e06926e6f

+ 9 - 1
zhipuzi_pay_plugin/network/CHttpClient.cpp

@@ -122,7 +122,7 @@ int CHttpClient::Get(const std::string & strUrl, std::string & strResponse)
 /*
  *返回值说明 https://blog.csdn.net/u011857683/article/details/53069268
  **/
-int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath)
+int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath, bool is_http_proxy, std::string http_proxy_ip, std::string http_proxy_port)
 {
 	CURLcode res;
 	CURL* curl = curl_easy_init();
@@ -147,6 +147,14 @@ int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost,
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 	//curl_easy_setopt(curl, CURLOPT_COOKIE, "lwm_gray_tag=rc");;
 
+	if (is_http_proxy)
+	{
+		std::string addr = http_proxy_ip + ":" + http_proxy_port;
+		curl_easy_setopt(curl, CURLOPT_PROXY, addr.c_str());
+		curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+		curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
+	}
+
 	if (NULL == pCaPath)
 	{
 		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);

+ 1 - 1
zhipuzi_pay_plugin/network/CHttpClient.h

@@ -32,7 +32,7 @@ public:
 	* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
 	* @return 返回是否Post成功
 	*/
-	int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
+	int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL, bool is_http_proxy = false, std::string http_proxy_ip = "", std::string http_proxy_port = "");
 
 	/**
 	* @brief HTTPS GET请求,无证书版本

+ 41 - 9
zhipuzi_pay_plugin/network/CZhipuziHttpClient.cpp

@@ -3,12 +3,26 @@
 
 #include "../helper/MD5.h"
 
-CZhipuziHttpClient CZhipuziHttpClient::m_client;
+#include <curl/curl.h>
 
 CZhipuziHttpClient::CZhipuziHttpClient()
 {
-    m_username = CSetting::getUsername();
-    m_password = CSetting::getPassword();
+	//初始化curl
+	curl_global_init(CURL_GLOBAL_ALL);
+
+	//初始化htttp代理相关参数
+	std::string http_is_proxy = CSetting::GetParam("http_is_proxy");
+	if (http_is_proxy == "1")
+	{
+		m_is_http_proxy = true;
+	}
+	else
+	{
+		m_is_http_proxy = false;
+	}
+	
+	m_http_proxy_ip = CSetting::GetParam("http_proxy_ip");
+	m_http_proxy_port = CSetting::GetParam("http_proxy_port");
 
 	if (m_env == DEV)
 	{
@@ -24,6 +38,24 @@ CZhipuziHttpClient::CZhipuziHttpClient()
 	}
 }
 
+/*
+ *修改了htttp代理设置之后,这里修改状态
+ **/
+void CZhipuziHttpClient::UpdateProxy()
+{
+	std::string http_is_proxy = CSetting::GetParam("http_is_proxy");
+	if (http_is_proxy == "1")
+	{
+		m_client.m_is_http_proxy = true;
+	}
+	else
+	{
+		m_client.m_is_http_proxy = false;
+	}
+
+	m_client.m_http_proxy_ip = CSetting::GetParam("http_proxy_ip");
+	m_client.m_http_proxy_port = CSetting::GetParam("http_proxy_port");
+}
 
 CZhipuziHttpClient::~CZhipuziHttpClient()
 {
@@ -46,7 +78,7 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
     {
         //网络请求出错
         LOG_INFO("network failed!");
-        errmsg = "network failed!";
+        errmsg = CLewaimaiString::UnicodeToUTF8(L"请求服务器失败,请检查网络设置!");;
         return false;
     }
 
@@ -57,7 +89,7 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
     if(!document.IsObject())
     {
         LOG_INFO("message 非法!");
-        errmsg = "message 非法!";
+        errmsg = CLewaimaiString::UnicodeToUTF8(L"服务器错误");
         return false;
     }
 
@@ -187,7 +219,7 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
     LOG_INFO("postString:" << postString.c_str());
 
     CHttpClient m_httpClient;
-    int ret = m_httpClient.Posts(m_client.m_yewu_url + url, postString, response, NULL);
+    int ret = m_httpClient.Posts(m_client.m_yewu_url + url, postString, response, NULL, m_client.m_is_http_proxy, m_client.m_http_proxy_ip, m_client.m_http_proxy_port);
 
     LOG_INFO("response:" << response.c_str());
 
@@ -258,7 +290,7 @@ bool CZhipuziHttpClient::RequestNew(std::string url, std::map<string, string> pa
 	LOG_INFO("postString:" << postString.c_str());
 
 	CHttpClient m_httpClient;
-	int ret = m_httpClient.Posts(m_client.m_yewu_url + url, postString, response, NULL);
+	int ret = m_httpClient.Posts(m_client.m_yewu_url + url, postString, response, NULL, m_client.m_is_http_proxy, m_client.m_http_proxy_ip, m_client.m_http_proxy_port);
 
 	LOG_INFO("response:" << response.c_str());
 
@@ -329,7 +361,7 @@ bool CZhipuziHttpClient::RequestPingtai(std::string url, std::map<string, string
 	LOG_INFO("postString:" << postString.c_str());
 
 	CHttpClient m_httpClient;
-	int ret = m_httpClient.Posts(m_client.m_pingtai_url + url, postString, response, NULL);
+	int ret = m_httpClient.Posts(m_client.m_pingtai_url + url, postString, response, NULL, m_client.m_is_http_proxy, m_client.m_http_proxy_ip, m_client.m_http_proxy_port);
 
 	LOG_INFO("response:" << response.c_str());
 
@@ -400,7 +432,7 @@ bool CZhipuziHttpClient::RequestPingtaiNew(std::string url, std::map<string, str
 	LOG_INFO("postString:" << postString.c_str());
 
 	CHttpClient m_httpClient;
-	int ret = m_httpClient.Posts(m_client.m_pingtai_url + url, postString, response, NULL);
+	int ret = m_httpClient.Posts(m_client.m_pingtai_url + url, postString, response, NULL, m_client.m_is_http_proxy, m_client.m_http_proxy_ip, m_client.m_http_proxy_port);
 
 	LOG_INFO("response:" << response.c_str());
 

+ 7 - 0
zhipuzi_pay_plugin/network/CZhipuziHttpClient.h

@@ -19,6 +19,8 @@ public:
 public:
     static void Init(std::string username, std::string password);
 
+	static void UpdateProxy();
+
     static bool Login(std::string& errmsg);
 
     static bool Request(std::string url, std::map<string, string> params, std::string& response);
@@ -42,4 +44,9 @@ public:
 	std::string m_shopname;
 
 	Env m_env = DEV;
+
+	//htttp代理相关的参数
+	bool m_is_http_proxy = false;
+	std::string m_http_proxy_ip;
+	std::string m_http_proxy_port;
 };

+ 8 - 1
zhipuzi_pay_plugin/pch/pch.cpp

@@ -2,4 +2,11 @@
 
 #include "pch.h"
 
-// 一般情况下,忽略此文件,但如果你使用的是预编译标头,请保留它。
+// 一般情况下,忽略此文件,但如果你使用的是预编译标头,请保留它。
+
+//所有的全局变量都在这里初始化
+
+//最先初始化sqllite数据
+CSetting CSetting::m_setting;
+
+CZhipuziHttpClient CZhipuziHttpClient::m_client;

+ 134 - 67
zhipuzi_pay_plugin/tool/CSetting.cpp

@@ -3,14 +3,9 @@
 
 #include "CSqlite3.h"
 
-std::map<std::string, std::string> CSetting::m_paramsMap;
-std::mutex CSetting::m_mutex;
-std::map<string, string> CSetting::m_users;
-std::string CSetting::m_username;
-std::string CSetting::m_password;
-
 CSetting::CSetting()
 {
+	this->Init();
 }
 
 
@@ -18,68 +13,43 @@ CSetting::~CSetting()
 {
 }
 
-void CSetting::SetParam(std::string name, std::string value, bool isSave)
+void CSetting::Init()
 {
-    m_mutex.lock();
-
-    m_paramsMap[name] = value;
-
-    m_mutex.unlock();
+	//先读取数据库的数据
+	CSqlite3 sqllite;
+	sqllite.InitConfig();
 
-    if(isSave)
-    {
-        SaveParams();
-    }
-}
+	//再对数据进行初始化,如果没有记录的就加上默认设置
+	m_mutex.lock();
 
-std::string CSetting::GetParam(std::string name)
-{
-    m_mutex.lock();
-
-    std::string value = m_paramsMap[name];
+	//系统设置的参数
+	std::string setting_is_auto_start = "setting_is_auto_start";
+	if (CSystem::IsAutoStart() == true)
+	{
+		m_paramsMap[setting_is_auto_start] = "1";
+	}
+	else
+	{
+		m_paramsMap[setting_is_auto_start] = "0";
+	}
 
-    m_mutex.unlock();
+	std::string setting_is_auto_login = "setting_is_auto_login";
+	if (m_paramsMap.find(setting_is_auto_login) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_auto_login] = "0";
+	}
 
-    return value;
-}
+	std::string setting_is_remember_password = "setting_is_remember_password";
+	if (m_paramsMap.find(setting_is_remember_password) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_remember_password] = "1";
+	}
 
-void CSetting::Init()
-{
-    //先读取数据库的数据
-    CSqlite3 sqllite;
-    sqllite.InitConfig();
-
-    //再对数据进行初始化,如果没有记录的就加上默认设置
-    m_mutex.lock();
-
-    //系统设置的参数
-    std::string setting_is_auto_start = "setting_is_auto_start";
-    if(CSystem::IsAutoStart() == true)
-    {
-        m_paramsMap[setting_is_auto_start] = "1";
-    }
-    else
-    {
-        m_paramsMap[setting_is_auto_start] = "0";
-    }
-
-    std::string setting_is_auto_login = "setting_is_auto_login";
-    if(m_paramsMap.find(setting_is_auto_login) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_auto_login] = "0";
-    }
-
-    std::string setting_is_remember_password = "setting_is_remember_password";
-    if(m_paramsMap.find(setting_is_remember_password) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_remember_password] = "1";
-    }
-
-    std::string setting_is_close_min = "setting_is_close_min";
-    if(m_paramsMap.find(setting_is_close_min) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_close_min] = "1";
-    }
+	std::string setting_is_close_min = "setting_is_close_min";
+	if (m_paramsMap.find(setting_is_close_min) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_close_min] = "1";
+	}
 
 	//从这里开始是插件系统设置的内容
 
@@ -239,6 +209,25 @@ void CSetting::Init()
 		m_paramsMap[shoukuan_setting_mianqueren] = "0";
 	}
 
+	std::string http_is_proxy = "http_is_proxy";
+	if (m_paramsMap.find(http_is_proxy) == m_paramsMap.end())
+	{
+		m_paramsMap[http_is_proxy] = "0";
+	}
+
+	std::string http_proxy_ip = "http_proxy_ip";
+	if (m_paramsMap.find(http_proxy_ip) == m_paramsMap.end())
+	{
+		m_paramsMap[http_proxy_ip] = "";
+	}
+
+	std::string http_proxy_port = "http_proxy_port";
+	if (m_paramsMap.find(http_proxy_port) == m_paramsMap.end())
+	{
+		//默认不开启收款免确认
+		m_paramsMap[http_proxy_port] = "";
+	}
+
 	//当前的上班状态
 	std::string jiaoban_is_work = "jiaoban_is_work";
 	if (m_paramsMap.find(jiaoban_is_work) == m_paramsMap.end())
@@ -253,20 +242,98 @@ void CSetting::Init()
 		m_paramsMap[jiaoban_shangban_time] = "";
 	}
 
-    m_mutex.unlock();
+	m_mutex.unlock();
+
+	//设置好默认参数之后,将默认参数写回到数据库
+	CSetting::SaveParams();
+}
+
+void CSetting::SetParam(std::string name, std::string value, bool isSave)
+{
+	m_setting.m_mutex.lock();
+
+	m_setting.m_paramsMap[name] = value;
+
+	m_setting.m_mutex.unlock();
+
+	if (isSave)
+	{
+		SaveParams();
+	}
+}
+
+std::string CSetting::GetParam(std::string name)
+{
+	m_setting.m_mutex.lock();
+
+	if (m_setting.m_paramsMap.find(name) == m_setting.m_paramsMap.end())
+	{
+		m_setting.m_mutex.unlock();
+
+		return "";
+	}
+
+	std::string value = m_setting.m_paramsMap[name];
+
+	m_setting.m_mutex.unlock();
+
+	return value;
+}
+
+void CSetting::SetUser(std::string name, std::string password, bool isSave)
+{
+	m_setting.m_users[name] = password;
+
+	if (isSave)
+	{
+		SaveUsers();
+	}
+}
+
+std::string CSetting::GetUser(std::string name)
+{
+	if (m_setting.m_users.find(name) == m_setting.m_users.end())
+	{
+		return "";
+	}
+
+	return m_setting.m_users[name];
+}
+
+std::map<string, string> CSetting::getUsers()
+{
+	return m_setting.m_users;
+}
+
+std::string CSetting::getValue(std::string name)
+{
+	return m_setting.m_paramsMap[name];
+}
+
+void CSetting::SetLoginInfo(std::string username, std::string password)
+{
+	m_setting.m_username = username;
+	m_setting.m_password = password;
+}
+
+std::string CSetting::getUsername()
+{
+	return m_setting.m_username;
+}
 
-    //设置好默认参数之后,将默认参数写回到数据库
-    SaveParams();
+std::string CSetting::getPassword()
+{
+	return m_setting.m_password;
 }
 
 void CSetting::SaveParams()
 {
     CSqlite3 sqllite;
-    sqllite.SaveParams(m_paramsMap);
+    sqllite.SaveParams(m_setting.m_paramsMap);
 }
 
 void CSetting::SaveUsers()
 {
     CSqlite3 sqllite;
-    sqllite.SaveUsers(m_users);
+    sqllite.SaveUsers(m_setting.m_users);
 }

+ 24 - 72
zhipuzi_pay_plugin/tool/CSetting.h

@@ -2,83 +2,32 @@
 
 #include "../pch/pch.h"
 
-class ChufangPrinter
-{
-public:
-    std::string date;
-    std::string name;
-    std::string ip;
-    std::string guige;
-    std::string fendan;
-    std::string fenlei;
-    std::string fenlei_ids;
-};
-
-class FoodType
-{
-public:
-    std::string name;
-    std::string type_id;
-};
-
 class CSetting
 {
 public:
     CSetting();
     ~CSetting();
 
+	//刚打开程序的时候,根据数据库初始化内存,并且添加默认参数
+	void Init();
+
     //修改内存中的参数设置
     static void SetParam(std::string name, std::string value, bool isSave = true);
     static std::string GetParam(std::string name);
 
-    static void SetUser(std::string name, std::string password, bool isSave = true)
-    {
-        m_users[name] = password;
-
-        if(isSave)
-        {
-            SaveUsers();
-        }
-    }
-
-    static std::string GetUser(std::string name)
-    {
-        if(m_users.find(name) == m_users.end())
-        {
-            return "";
-        }
-
-        return m_users[name];
-    }
-
-    static std::map<string, string> getUsers()
-    {
-        return m_users;
-    }
-
-    //刚打开程序的时候,根据数据库初始化内存,并且添加默认参数
-    static void Init();
-
-    static std::string getValue(std::string name)
-    {
-        return m_paramsMap[name];
-    }
-
-    static void SetLoginInfo(std::string username, std::string password)
-    {
-        m_username = username;
-        m_password = password;
-    }
-
-    static std::string getUsername()
-    {
-        return m_username;
-    }
-
-    static std::string getPassword()
-    {
-        return m_password;
-    }
+	static void SetUser(std::string name, std::string password, bool isSave = true);
+
+	static std::string GetUser(std::string name);
+
+	static std::map<string, string> getUsers();
+
+	static std::string getValue(std::string name);
+
+	static void SetLoginInfo(std::string username, std::string password);
+
+	static std::string getUsername();
+	
+	static std::string getPassword();
 
     /*
      *把内存中的参数,写到数据库中
@@ -87,14 +36,17 @@ public:
 
     static void SaveUsers();
 
+public:
+	static CSetting m_setting;
+
 private:
-    static std::map<std::string, std::string> m_paramsMap;
+    std::map<std::string, std::string> m_paramsMap;
 
-    static std::mutex m_mutex;
+    std::mutex m_mutex;
 
-    static std::map<string, string> m_users;
+    std::map<string, string> m_users;
 
-    static std::string m_username;
-    static std::string m_password;
+    std::string m_username;
+    std::string m_password;
 };
 

+ 101 - 8
zhipuzi_pay_plugin/wnd/CShoukuanWnd.cpp

@@ -183,7 +183,7 @@ LRESULT CShoukuanWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
 		{
 			CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_fail_attention")));
 
-			std::wstring ws_fail_message = L"失败信息:" + CLewaimaiString::UTF8ToUnicode(m_fail_message) + L",按任意键关闭窗口,";
+			std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
 			std::wstring ws_attention = ws_fail_message + to_wstring(m_timer_now) + L" 秒后自动关闭";
 
 			pFailMessage->SetText(ws_attention.c_str());
@@ -483,7 +483,7 @@ LRESULT CShoukuanWnd::OnShoukuanFail(UINT uMsg, WPARAM wParam, LPARAM lParam, BO
 
 	CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_fail_attention")));
 
-	std::wstring ws_fail_message = L"失败信息:" + CLewaimaiString::UTF8ToUnicode(m_fail_message) + L",按任意键关闭窗口,";
+	std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
 	std::wstring ws_attention = ws_fail_message + to_wstring(m_timer_now) + L" 秒后自动关闭";
 
 	pFailMessage->SetText(ws_attention.c_str());
@@ -627,7 +627,16 @@ void CShoukuanWnd::HandleShoukuan()
 	std::string response;
 
 	std::string url = "/saomashoukuan/sendorder";
-	CZhipuziHttpClient::Request(url.c_str(), params, response);
+	bool ret = CZhipuziHttpClient::Request(url.c_str(), params, response);
+	if (ret == false)
+	{
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"请求服务器失败,请检查网络设置!";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+		return;
+	}
 
 	rapidjson::Document document;
 	document.Parse(response.c_str());
@@ -635,12 +644,22 @@ void CShoukuanWnd::HandleShoukuan()
 	if (document.HasParseError())
 	{
 		LOG_INFO("parse response error!");
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 		return;
 	}
 
 	if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
 	{
 		LOG_INFO("json error!");
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 		return;
 	}
 
@@ -649,6 +668,11 @@ void CShoukuanWnd::HandleShoukuan()
 	if (errcode != 0)
 	{
 		LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 		return;
 	}
 
@@ -671,7 +695,7 @@ void CShoukuanWnd::HandleShoukuan()
 		//支付失败
 		m_shoukuan_status = 4;
 
-		m_fail_message = data["message"].GetString();
+		m_fail_message = CLewaimaiString::UTF8ToUnicode(data["message"].GetString());
 
 		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 	}
@@ -684,6 +708,12 @@ void CShoukuanWnd::HandleShoukuan()
 		//需要查询支付状态
 		SendMessage(WM_SHOUKUAN_STATUS_NEEDPASSWORD, 0, 0);
 	}
+
+	m_shoukuan_status = 4;
+
+	m_fail_message = L"服务器错误";
+
+	SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 }
 
 void CShoukuanWnd::HandleShoukuanPassword()
@@ -697,7 +727,16 @@ void CShoukuanWnd::HandleShoukuanPassword()
 		std::string response;
 
 		std::string url = "/saomashoukuan/queryorderstatus";
-		CZhipuziHttpClient::Request(url.c_str(), params, response);
+		bool ret = CZhipuziHttpClient::Request(url.c_str(), params, response);
+		if (ret == false)
+		{
+			m_shoukuan_status = 4;
+
+			m_fail_message = L"请求服务器失败,请检查网络设置!";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+			return;
+		}
 
 		rapidjson::Document document;
 		document.Parse(response.c_str());
@@ -705,12 +744,22 @@ void CShoukuanWnd::HandleShoukuanPassword()
 		if (document.HasParseError())
 		{
 			LOG_INFO("parse response error!");
+			m_shoukuan_status = 4;
+
+			m_fail_message = L"服务器错误";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 			return;
 		}
 
 		if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
 		{
 			LOG_INFO("json error!");
+			m_shoukuan_status = 4;
+
+			m_fail_message = L"服务器错误";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 			return;
 		}
 
@@ -719,6 +768,11 @@ void CShoukuanWnd::HandleShoukuanPassword()
 		if (errcode != 0)
 		{
 			LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+			m_shoukuan_status = 4;
+
+			m_fail_message = L"服务器错误";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 			return;
 		}
 
@@ -743,15 +797,24 @@ void CShoukuanWnd::HandleShoukuanPassword()
 			//表示顾客那边出问题,已经失败了
 			m_shoukuan_status = 4;
 
-			m_fail_message = "顾客取消支付,请重新扫码收款";
+			m_fail_message = L"顾客取消支付,请重新扫码收款";
 
 			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+
+			break;
 		}
 		else if (s_status == "fail")
 		{
 			//这个只是表示状态未知
 			Sleep(1000);
 		}
+
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+		break;
 	}
 }
 
@@ -771,7 +834,16 @@ void CShoukuanWnd::HandleCancelShoukuan()
 	std::string response;
 
 	std::string url = "saomashoukuan/closeorder";
-	CZhipuziHttpClient::Request(url.c_str(), params, response);
+	bool ret = CZhipuziHttpClient::Request(url.c_str(), params, response);
+	if (ret == false)
+	{
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"请求服务器失败,请检查网络设置!";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+		return;
+	}
 
 	rapidjson::Document document;
 	document.Parse(response.c_str());
@@ -779,12 +851,22 @@ void CShoukuanWnd::HandleCancelShoukuan()
 	if (document.HasParseError())
 	{
 		LOG_INFO("parse response error!");
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 		return;
 	}
 
 	if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
 	{
 		LOG_INFO("json error!");
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 		return;
 	}
 
@@ -793,6 +875,11 @@ void CShoukuanWnd::HandleCancelShoukuan()
 	if (errcode != 0)
 	{
 		LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+		m_shoukuan_status = 4;
+
+		m_fail_message = L"服务器错误";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 		return;
 	}
 
@@ -806,8 +893,14 @@ void CShoukuanWnd::HandleCancelShoukuan()
 		//取消成功,订单变为失败状态
 		m_shoukuan_status = 4;
 
-		m_fail_message = CLewaimaiString::UnicodeToUTF8(L"商家取消收款");
+		m_fail_message = L"商家取消收款";
 		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 	}
+
+	m_shoukuan_status = 4;
+
+	m_fail_message = L"服务器错误";
+
+	SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 }
 

+ 1 - 1
zhipuzi_pay_plugin/wnd/CShoukuanWnd.h

@@ -107,7 +107,7 @@ public:
 	//收款状态 0:未开始 1:请求发给服务器了,但是暂时还没得到反馈 2:查询密码中 3:成功 4:失败 5:正在取消支付
 	int m_shoukuan_status = 0;
 
-	std::string m_fail_message;
+	std::wstring m_fail_message;
 
 	//窗口关闭的定时器时间
 	int m_timer_now = 4;

+ 39 - 0
zhipuzi_pay_plugin/wnd/CSystemSettingWnd.cpp

@@ -379,6 +379,23 @@ void CSystemSettingWnd::Init()
 		mianqueren->SetCheck(false);
 	}
 
+	CCheckBoxUI* is_http_proxy = static_cast<CCheckBoxUI*>(m_pm.FindControl(L"shoukuan_setting_isdaili"));
+	std::string http_is_proxy = CSetting::GetParam("http_is_proxy");
+	if (http_is_proxy == "1")
+	{
+		is_http_proxy->SetCheck(true);
+	}
+	else
+	{
+		is_http_proxy->SetCheck(false);
+	}
+
+	CEditUI* httpIpEdit = static_cast<CEditUI*>(m_pm.FindControl(L"shoukuan_setting_daili_ip"));
+	httpIpEdit->SetText(CLewaimaiString::UTF8ToUnicode(CSetting::GetParam("http_proxy_ip")).c_str());
+
+	CEditUI* httpPortEdit = static_cast<CEditUI*>(m_pm.FindControl(L"shoukuan_setting_daili_port"));
+	httpPortEdit->SetText(CLewaimaiString::UTF8ToUnicode(CSetting::GetParam("http_proxy_port")).c_str());
+
     //初始化快捷键的展示
     UINT shoukuan_mod = (UINT)atoi(CSetting::GetParam("system_setting_kuaijiejian_shoukuan_mod").c_str());
     UINT shoukuan_vk = (UINT)atoi(CSetting::GetParam("system_setting_kuaijiejian_shoukuan_vk").c_str());
@@ -895,6 +912,28 @@ void CSystemSettingWnd::HandleClickMsg(TNotifyUI& msg)
 		{
 			CSetting::SetParam("shoukuan_setting_mianqueren", "0");
 		}
+
+		//Http代理相关
+		CCheckBoxUI* is_http_proxy = static_cast<CCheckBoxUI*>(m_pm.FindControl(L"shoukuan_setting_isdaili"));
+		if (is_http_proxy->IsSelected())
+		{
+			CSetting::SetParam("http_is_proxy", "1");
+		}
+		else
+		{
+			CSetting::SetParam("http_is_proxy", "0");
+		}
+
+		CEditUI* httpIpEdit = static_cast<CEditUI*>(m_pm.FindControl(L"shoukuan_setting_daili_ip"));
+		std::wstring http_proxy_ip = httpIpEdit->GetText();
+		CSetting::SetParam("http_proxy_ip", CLewaimaiString::UnicodeToUTF8(http_proxy_ip));
+
+		CEditUI* httpPortEdit = static_cast<CEditUI*>(m_pm.FindControl(L"shoukuan_setting_daili_port"));
+		std::wstring http_proxy_port = httpPortEdit->GetText();
+		CSetting::SetParam("http_proxy_port", CLewaimaiString::UnicodeToUTF8(http_proxy_port));
+
+		//更新httt代理状态
+		CZhipuziHttpClient::UpdateProxy();
 	}
     else if(senderName == _T("kuaijiejian_setting_jiesuan_btn"))
     {

+ 60 - 9
zhipuzi_pay_plugin/wnd/CTuikuanWnd.cpp

@@ -183,7 +183,7 @@ LRESULT CTuikuanWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
 		{
 			CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("tuikuan_pay_fail_attention")));
 
-			std::wstring ws_fail_message = L"失败信息:" + CLewaimaiString::UTF8ToUnicode(m_fail_message) + L",按任意键关闭窗口,";
+			std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
 			std::wstring ws_attention = ws_fail_message + to_wstring(m_timer_now) + L" 秒后自动关闭";
 
 			pFailMessage->SetText(ws_attention.c_str());
@@ -443,7 +443,7 @@ LRESULT CTuikuanWnd::OnTuikuanFail(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
 
 	CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("tuikuan_pay_fail_attention")));
 
-	std::wstring ws_fail_message = L"失败信息:" + CLewaimaiString::UTF8ToUnicode(m_fail_message) + L",按任意键关闭窗口,";
+	std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
 	std::wstring ws_attention = ws_fail_message + to_wstring(m_timer_now) + L" 秒后自动关闭";
 
 	pFailMessage->SetText(ws_attention.c_str());
@@ -531,7 +531,16 @@ void CTuikuanWnd::HandleTuikuan()
 	std::string response;
 
 	std::string url = "/saomashoukuan/refundbythirdtradeno";
-	CZhipuziHttpClient::Request(url.c_str(), params, response);
+	bool ret = CZhipuziHttpClient::Request(url.c_str(), params, response);
+	if (ret == false)
+	{
+		m_tuikuan_status = 4;
+
+		m_fail_message = L"请求服务器失败,请检查网络设置!";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+		return;
+	}
 
 	rapidjson::Document document;
 	document.Parse(response.c_str());
@@ -542,7 +551,7 @@ void CTuikuanWnd::HandleTuikuan()
 
 		m_tuikuan_status = 4;
 
-		m_fail_message = "服务器错误!";
+		m_fail_message = L"服务器错误!";
 
 		SendMessage(WM_TUIKUAN_STATUS_FAIL, 0, 0);
 
@@ -555,7 +564,7 @@ void CTuikuanWnd::HandleTuikuan()
 
 		m_tuikuan_status = 4;
 
-		m_fail_message = "服务器错误!";
+		m_fail_message = L"服务器错误!";
 
 		SendMessage(WM_TUIKUAN_STATUS_FAIL, 0, 0);
 
@@ -570,7 +579,7 @@ void CTuikuanWnd::HandleTuikuan()
 
 		m_tuikuan_status = 4;
 
-		m_fail_message = "服务器错误!";
+		m_fail_message = L"服务器错误!";
 
 		SendMessage(WM_TUIKUAN_STATUS_FAIL, 0, 0);
 
@@ -596,7 +605,7 @@ void CTuikuanWnd::HandleTuikuan()
 		//退款失败
 		m_tuikuan_status = 4;
 
-		m_fail_message = data["errmsg"].GetString();
+		m_fail_message = CLewaimaiString::UTF8ToUnicode(data["errmsg"].GetString());
 
 		SendMessage(WM_TUIKUAN_STATUS_FAIL, 0, 0);
 	}
@@ -610,6 +619,12 @@ void CTuikuanWnd::HandleTuikuan()
 		//需要查询支付状态
 		SendMessage(WM_TUIKUAN_STATUS_NEEDPASSWORD, 0, 0);
 	}
+
+	m_tuikuan_status = 4;
+
+	m_fail_message = L"服务器错误!";
+
+	SendMessage(WM_TUIKUAN_STATUS_FAIL, 0, 0);
 }
 
 void CTuikuanWnd::HandleTuikuanPassword()
@@ -623,7 +638,16 @@ void CTuikuanWnd::HandleTuikuanPassword()
 		std::string response;
 
 		std::string url = "/saomashoukuan/queryorderrefundstatus";
-		CZhipuziHttpClient::Request(url.c_str(), params, response);
+		bool ret = CZhipuziHttpClient::Request(url.c_str(), params, response);
+		if (ret == false)
+		{
+			m_tuikuan_status = 4;
+
+			m_fail_message = L"请求服务器失败,请检查网络设置!";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+			return;
+		}
 
 		rapidjson::Document document;
 		document.Parse(response.c_str());
@@ -631,12 +655,25 @@ void CTuikuanWnd::HandleTuikuanPassword()
 		if (document.HasParseError())
 		{
 			LOG_INFO("parse response error!");
+
+			m_tuikuan_status = 4;
+
+			m_fail_message = L"服务器错误!";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+			return;
+
 			return;
 		}
 
 		if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
 		{
 			LOG_INFO("json error!");
+			m_tuikuan_status = 4;
+
+			m_fail_message = L"服务器错误!";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 			return;
 		}
 
@@ -645,6 +682,11 @@ void CTuikuanWnd::HandleTuikuanPassword()
 		if (errcode != 0)
 		{
 			LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+			m_tuikuan_status = 4;
+
+			m_fail_message = L"服务器错误!";
+
+			SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
 			return;
 		}
 
@@ -666,14 +708,23 @@ void CTuikuanWnd::HandleTuikuanPassword()
 			//退款失败了
 			m_tuikuan_status = 4;
 
-			m_fail_message = data["errmsg"].GetString();
+			m_fail_message = CLewaimaiString::UTF8ToUnicode(data["errmsg"].GetString());
 
 			SendMessage(WM_TUIKUAN_STATUS_FAIL, 0, 0);
+
+			break;
 		}
 		else if (s_status == "refunding")
 		{
 			//这个只是表示状态未知
 			Sleep(1000);
 		}
+
+		m_tuikuan_status = 4;
+
+		m_fail_message = L"服务器错误!";
+
+		SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
+		break;
 	}
 }

+ 1 - 1
zhipuzi_pay_plugin/wnd/CTuikuanWnd.h

@@ -97,7 +97,7 @@ public:
 	std::string m_order_no;
 	std::string m_out_trade_no;
 
-	std::string m_fail_message;
+	std::wstring m_fail_message;
 
 	//´°¿Ú¹Ø±ÕµÄ¶¨Ê±Æ÷ʱ¼ä
 	int m_timer_now = 4;

+ 0 - 8
zhipuzi_pay_plugin/zhipuzi_pay_plugin.cpp

@@ -2,8 +2,6 @@
 
 #include "wnd/CLoginWnd.h"
 
-#include <curl/curl.h>
-
 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                       _In_opt_ HINSTANCE hPrevInstance,
                       _In_ LPWSTR    lpCmdLine,
@@ -19,12 +17,6 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
     CLewaimaiLog log;
     log.Init();
 
-    //初始化系统设置
-	CSetting::Init();
-
-	//初始化curl
-	curl_global_init(CURL_GLOBAL_ALL);
-
     //开始展示窗口
     CPaintManagerUI::SetInstance(hInstance);
 #ifdef NDEBUG