SMSHandle.h 6.1 KB

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