诸暨麻将添加redis
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

113 行
3.7 KiB

  1. //////////////////////////////////// HttpClient.h
  2. #ifndef HTTPCLIENT_H
  3. #define HTTPCLIENT_H
  4. #include "StdAfx.h"
  5. #include <afxinet.h>
  6. #include <strsafe.h>
  7. #include <unordered_map>
  8. #include <process.h>
  9. #include <string>
  10. #define IE_AGENT _T("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)")
  11. // 操作成功
  12. #define SUCCESS 0
  13. // 操作失败
  14. #define FAILURE 1
  15. #define OUTTIME 2
  16. class CAttemperEngineSink;
  17. class CHttpClient
  18. {
  19. public:
  20. CHttpClient(LPCTSTR strAgent = IE_AGENT);
  21. virtual ~CHttpClient(void);
  22. int HttpGet(LPCTSTR strUrl, LPCTSTR strPostData, CString &strResponse, CString &Err);
  23. int HttpPost(LPCTSTR strUrl, LPCTSTR strPostData, CString &strResponse, CString &Err);
  24. //添加
  25. static void AddLog(DWORD dwSocketID, GETDUILIEBASE_EX LogText);
  26. //获取
  27. static std::unordered_map<DWORD, GETDUILIEBASE_EX_LIST> GetLog();
  28. //运行
  29. static unsigned __stdcall Runs(void* pParam);
  30. //启动
  31. static bool start(CAttemperEngineSink* pSink);
  32. //结束
  33. static bool end();
  34. //获取数量
  35. static DWORD GetCount();
  36. // 进行Url编码 UTF-8
  37. static CString UrlEncode(CString strUnicode);
  38. private:
  39. int ExecuteRequest(LPCTSTR strMethod, LPCTSTR strUrl, LPCTSTR strPostData, CString &strResponse,CString &Err);
  40. void Clear();
  41. static HANDLE m_hThread; // 线程句柄
  42. static unsigned m_uiThreadID; // 线程id
  43. static bool m_bRun; // 当前线程是否结束
  44. static HANDLE g_Event; // 触发事件句柄
  45. static CAttemperEngineSink* pCAttemperEngineSink; //调度钩子
  46. static void* curl;
  47. //请求信息
  48. static std::unordered_map<DWORD, GETDUILIEBASE_EX_LIST> GetData; //请求信息
  49. //锁
  50. static CCriticalSection m_CriticalSection; //线程锁
  51. private:
  52. CInternetSession *m_pSession;
  53. CHttpConnection *m_pConnection;
  54. CHttpFile *m_pFile;
  55. public:
  56. //获取验证码
  57. static bool OnGetIphoneNumber(CString csIphoneNum, DWORD dwUserID, DWORD dwSocketID);
  58. public:
  59. /**
  60. * @brief HTTP POST请求
  61. * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
  62. * @param strPost 输入参数,使用如下格式para1=val1¶2=val2&…
  63. * @param strResponse 输出参数,返回的内容
  64. * @return 返回是否Post成功
  65. */
  66. int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
  67. /**
  68. * @brief HTTP GET请求
  69. * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
  70. * @param strResponse 输出参数,返回的内容
  71. * @return 返回是否Post成功
  72. */
  73. int Get(const std::string & strUrl, std::string & strResponse);
  74. /**
  75. * @brief HTTPS POST请求,无证书版本
  76. * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
  77. * @param strPost 输入参数,使用如下格式para1=val1¶2=val2&…
  78. * @param strResponse 输出参数,返回的内容
  79. * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
  80. * @return 返回是否Post成功
  81. */
  82. int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
  83. /**
  84. * @brief HTTPS GET请求,无证书版本
  85. * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
  86. * @param strResponse 输出参数,返回的内容
  87. * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
  88. * @return 返回是否Post成功
  89. */
  90. int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);
  91. public:
  92. void SetDebug(bool bDebug);
  93. private:
  94. bool m_bDebug;
  95. };
  96. #endif // HTTPCLIENT_H