SMSHandle.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef _SMS_HANDLE_HEADER_
  2. #define _SMS_HANDLE_HEADER_
  3. #include "DBInterface.h"
  4. #include "HttpTransByGet.h"
  5. typedef struct _SEND_RESPONEINFO_
  6. {
  7. CString strSendStatus;
  8. CString strSendCount;
  9. CString strBalance;
  10. CString strErPhone;
  11. CString strSid;
  12. }ResponebySend, *pResponebySend;
  13. typedef struct _QUERYACCOUNTINFO_
  14. {
  15. CString strSendStatus;
  16. CString strAccount;
  17. CString strBalance;
  18. CString strSMSCharacterCount;
  19. CString strSignatures;
  20. CString strOwnedOperators;
  21. }QuerAccountInfo, *pQuerAccountInfo;
  22. #define VERIFYDATA(name,sex,birthday,today,lastfewdate,phone,check) \
  23. if(birthday.IsEmpty()) continue;\
  24. int nMonth = _ttoi(birthday.Mid(5,2));\
  25. int nDay = _ttoi(birthday.Mid(8,2));\
  26. if ( (nMonth >> 2) > 3 || (nDay >> 5) > 0 ) continue;\
  27. if(check == _T("1") )\
  28. birthday = LuanrToSolarDate(CTime::GetCurrentTime().GetYear(),_ttoi(birthday.Mid(5,2)), _ttoi(birthday.Mid(8,2)));\
  29. else\
  30. birthday.Format(_T("%04d-%02d-%02d"),CTime::GetCurrentTime().GetYear(),_ttoi(birthday.Mid(5,2)), _ttoi(birthday.Mid(8,2)));\
  31. COleDateTime Solar;\
  32. Solar.SetDateTime(_ttoi(birthday.Left(4)),_ttoi(birthday.Mid(5,2)),_ttoi(birthday.Mid(8,2)),0,0,0);\
  33. Solar -= Span;\
  34. lastfewdate.Format(_T("%04d-%02d-%02d"),Solar.GetYear(),Solar.GetMonth(),Solar.GetDay());\
  35. if ( today >= lastfewdate && today < birthday)\
  36. GenerateToSendreg(name,sex,phone,s_SMSInfo.msgContent1);
  37. #define VERIFYHOSPITALCHECK1(strArray,strChildMsgArray,a,b,c,d,e,f) VerifyHospitalCheck1(strArray.ElementAt(a),strChildMsgArray.ElementAt(b),strArray.ElementAt(c),strChildMsgArray.ElementAt(d),strArray.ElementAt(e),strArray.ElementAt(f));
  38. #pragma once
  39. class CSMSHandle
  40. {
  41. public:
  42. CSMSHandle();
  43. ~CSMSHandle();
  44. public:
  45. static SMSInfo s_SMSInfo; // 该成员应该受保存,防止意外修改;
  46. TCHAR m_szAccount[MAX_NAME_LEN]; // 短信账号;
  47. TCHAR m_szPassWord[MAX_NAME_LEN]; // 账号密码;
  48. DWORD m_dwblance; // 短信余额;
  49. ULONGLONG m_ulCountOfSended; // 已发送的短信条数;
  50. std::vector<SmsType> m_vtSMSTypeOfChild;
  51. std::vector<SmsType> m_vtSMSTypeOfWedding;
  52. CString CalculateFilter_Child();
  53. CString CalculateFilter_Wedding();
  54. CString GetHTTPErrorInf()
  55. {
  56. return m_httpGet.GetErrorInfo();
  57. }
  58. private:
  59. ThreadSection s_critSection;
  60. ThreadSection *ReturnSection() {
  61. return &s_critSection;
  62. }
  63. CHttpTransByGet m_httpGet;
  64. INT_PTR SendSMS(LPCTSTR lpStringToSend, CONST INT &nIndex, CONST INT &nGroup, LPCTSTR lpAutoId);
  65. VOID QuerySMSStatus(LPCTSTR lpSid, LPCTSTR lpAutoId);
  66. void UTF8ToWideChar(LPBYTE lpRespone, CString &strRespone);
  67. void UrlUTF8Decode(LPBYTE lpRespone, CString &strRespone);
  68. void AnalyzeAccoutStatus(CString &strRespone); // 解析账号的返回状态值;
  69. INT AnalyzeSendStatus(LPBYTE lpRespone, ResponebySend &lRespone); // 解析发送的返回状态值;
  70. void AnalyzeQueryStatus(CString &strRespone); // 解析查询的返回状态值;
  71. // 应该非静态+const比较好,防止s_SMSInfo被意外修改;
  72. static void GenerateToSendreg( IN CONST CString &strName, IN CONST CString &strSex, IN CONST CString &strPhone, IN CString &strContent, IN CONST CString &strMsgtype);
  73. static BOOL IsValidDate(CONST CString &strDate, BOOL bThisyear = TRUE);
  74. public:
  75. void GetMainInfo(); // 获取主要信息;
  76. INT_PTR ReadySendSMS(CString& strPhones, CString& strContent, CString& strTime, CString& strAutoId);
  77. HANDLE m_hSendSMSThread;
  78. HANDLE m_hGenerateSMSThread;
  79. HANDLE m_hSendEvent;
  80. HANDLE m_hGenerateEvent;
  81. HANDLE m_hWaitableTime;
  82. static BOOL m_bGenerateEndof;
  83. static DWORD WINAPI SendSMSThread(LPVOID lpParam); // 发送短信的线程;
  84. static DWORD WINAPI GenerateSMSThread(LPVOID lpParam); // 生成短信线程;
  85. int StartThread();
  86. int EndofThread();
  87. BOOL GetSMSBlance(QuerAccountInfo &tAccountInfo);
  88. protected:
  89. // ---------------------------------------------------------------------------------------------------------------------------------------
  90. // 客户端有选择"一周"、"两周"、"三周"、"满月"至"十一月"、"一岁"至"三岁"。要在客户里自动将这些中文转为天数。
  91. // 短信类型msgtyped:
  92. // ==0,没有归类的短信;
  93. // == 1,生日短信;
  94. // == 2,百天或结婚纪念日短信;
  95. // == 15,结婚当天;
  96. // == 10000,儿童满n天;
  97. // == 20000,怀孕满n天;
  98. static BOOL VerifyCheck1(CONST CString &strMsgtype, CONST CString &strName, CONST CString &strSex, CONST CString &strPhone, CString strBirthday, CONST CString &strCheck);
  99. static BOOL VerifyCheck2(CONST CString &strMsgtype, CONST CString &strName, CONST CString &strSex, CONST CString &strPhone, CString strBirthday, CONST CString &strCheck);
  100. static BOOL VerifyCheck15(CONST CString &strMsgtype, CONST CString &strName, CONST CString &strSex, CONST CString &strPhone, CString strWiddingDay, CONST CString &strCheck);
  101. static BOOL VerifyHospitalCheck1(
  102. CONST CString &strMsgtype,
  103. CONST CString &strName,
  104. CONST CString &strDays, // 出生满_ttoi(strDays)天;
  105. CONST CString &strPhone,
  106. CString strContent,
  107. CString strBirthday,
  108. CONST CString &strCheck);
  109. static BOOL VerifyHospitalCheck2(
  110. CONST CString &strMsgtype,
  111. CONST CString &strName,
  112. CONST CString &strDays,
  113. CONST CString &strPhone,
  114. CString strContent,
  115. CString strOrderDate, // 订单日期;
  116. CString strPregnancyDate // 已怀孕天数;
  117. );
  118. public:
  119. // 儿童版本;
  120. static VOID CHandleDindanClient(CArray<CStringArray, CStringArray> *pArrayOfDindanClient, CArray<CStringArray, CStringArray> *pArrayOfChildMsg = NULL);
  121. static VOID CHandleClient2(CArray<CStringArray, CStringArray> *pArrayOfClien2, CArray<CStringArray, CStringArray> *pArrayOfChildMsg = NULL);
  122. static VOID CHandleClient3(CArray<CStringArray, CStringArray> *pArrayOfClien3, CArray<CStringArray, CStringArray> *pArrayOfChildMsg = NULL);
  123. static VOID CHandleHospitalClient(CArray<CStringArray, CStringArray> *pArrayOfHospitalClient, CArray<CStringArray, CStringArray> *pArrayOfChildMsg);
  124. // 婚纱版本;
  125. static VOID WHandleDindanClient(CArray<CStringArray, CStringArray> *pArrayOfDindanClient, CArray<CStringArray, CStringArray> *pArrayOfChildMsg = NULL);
  126. static VOID WHandleClient2(CArray<CStringArray, CStringArray> *pArrayOfClien2, CArray<CStringArray, CStringArray> *pArrayOfChildMsg = NULL);
  127. static VOID WHandleClient3(CArray<CStringArray, CStringArray> *pArrayOfClien3, CArray<CStringArray, CStringArray> *pArrayOfChildMsg = NULL);
  128. static VOID WHandleHospitalClient(CArray<CStringArray, CStringArray> *pArrayOfHospitalClient, CArray<CStringArray, CStringArray> *pArrayOfChildMsg);
  129. };
  130. #endif