LYFZSendMsg.cpp 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844
  1. // LYFZSendMsg.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZSendMsg.h"
  5. #include "ChildFrm.h"
  6. #include "LYFZSendMsgDoc.h"
  7. #include "LYFZSendMsgView.h"
  8. #include "ChoosePhotoSkin.h"
  9. #include "HttpClient.h"
  10. #include "Lzari.h"
  11. #include <tlhelp32.h>
  12. #include <wincrypt.h>
  13. #include <Mmsystem.h>
  14. #include "mysqldata.h"
  15. #include <afxsock.h>
  16. #include <process.h>
  17. //#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
  18. #include "AnalysisJXTRespond.h"
  19. #define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
  20. #define KEYLENGTH 0x00800000
  21. #define ENCRYPT_ALGORITHM CALG_RC4
  22. #define ENCRYPT_BLOCK_SIZE 8
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. #define NEWFORM 1
  29. extern int g_bSend;
  30. extern int g_bMsgRoad;
  31. extern int g_bDebug;
  32. extern int g_bMsgRoadtemp;
  33. //---------------------------------------------------------------------------
  34. typedef char* (__stdcall *FnMongateGetVer)();
  35. typedef int (__stdcall *FnMongateChangePwd)(int sock, const char* pszAccount,
  36. const char* pszOldPwd, const char* pszNewPwd);
  37. typedef int (__stdcall *FnMongateConnect)(const char* pszIP, int iPort, const char* pszAccount,
  38. const char* pszPwd);
  39. typedef void (__stdcall *FnMongateDisconnect)(int sock);
  40. typedef int (__stdcall *FnMongateQueryBalance)(int sock);
  41. typedef int (__stdcall *FnMongateQueryUsed)(int sock);
  42. typedef int (__stdcall *FnMongateSendSms)(int sock, const char* pszMobis, const char* pszMsg);
  43. typedef int (__stdcall *FnMongateConnectSocks4Proxy)(const char* ,int ,const char* ,int ,const char* ,const char* );
  44. typedef int (__stdcall *FnMongateCsGetSms)(SOCKET , char [500][255]);
  45. typedef int (__stdcall *FnMongateVasGetSms)(SOCKET , char [500][255]);
  46. typedef int (__stdcall *FnMongateVasSendSms)(SOCKET , const char* , const char* , const char* , const char* ,const char* , const char* , int );
  47. typedef int (__stdcall *FnMongateCsSendSmsHttp)(SOCKET , const char* ,const char* , int , char* );
  48. typedef int (__stdcall *FnMongateTestConn)(SOCKET );
  49. typedef int (__stdcall *FnMongateCsGetStatusReport)(SOCKET , char [500][255]);
  50. typedef int (__stdcall *FnMongateCsSendSms)(SOCKET , const char* ,const char* , int , char* );
  51. typedef int (__stdcall *FnMongateConnectSocks5Proxy)( const char* , int ,const char* ,const char* ,const char* ,int ,const char* ,const char* );
  52. typedef int (__stdcall *FnMongateConnectHttpProxy)(const char*,int ,const char* ,const char* ,const char* , int , const char* , const char* );
  53. typedef int (__stdcall *FnMongateTestConnHttp)(int);
  54. typedef int (__stdcall *FnMongateCsGetSmsHttp)(SOCKET , char [500][255]);
  55. typedef int (__stdcall *FnMongateCsGetStatusReportHttp)(SOCKET , char [500][255]);
  56. typedef int (__stdcall *FnMongateConnectHttpProxy)(const char* pszProxyIP,
  57. int iProxyPort,const char* pszProxyAccount,const char* pszProxyPwd,
  58. const char* pszIP, int iPort, const char* pszAccount, const char* pszPwd);
  59. typedef int (__stdcall *FnMongateTestMsgEx)(SOCKET sock,const char* pStrMessage,char *keywords);
  60. typedef int (__stdcall *FnMongateTestMsgExHttp)(SOCKET sock,const char* pStrMessage,char *keyword);
  61. typedef int (__stdcall *FnMongateCsSPSendSmsNew)(SOCKET sock, const char* pszMobis,
  62. const char* pszMsg, int iMobiCount,const char* pszSubPort,char* pszSN);
  63. int m_hsock=0;
  64. HMODULE g_hDll=NULL;
  65. FnMongateGetVer MongateGetVer;
  66. //tcp/ip method
  67. FnMongateTestMsgEx MongateTestMsgEx;
  68. FnMongateTestMsgExHttp MongateTestMsgExHttp;
  69. FnMongateConnect MongateConnect;
  70. FnMongateDisconnect MongateDisconnect;
  71. FnMongateChangePwd MongateChangePwd;
  72. FnMongateQueryBalance MongateQueryBalance;
  73. FnMongateQueryUsed MongateQueryUsed;
  74. FnMongateSendSms MongateSendSms;
  75. FnMongateCsGetSms MongateCsGetSms;
  76. FnMongateVasGetSms MongateVasGetSms;
  77. FnMongateVasSendSms MongateVasSendSms;
  78. FnMongateTestConn MongateTestConn;
  79. FnMongateCsGetStatusReport MongateCsGetStatusReport;
  80. FnMongateCsSendSms MongateCsSendSms;
  81. FnMongateConnectSocks4Proxy MongateConnectSocks4Proxy;
  82. FnMongateConnectSocks5Proxy MongateConnectSocks5Proxy;
  83. //http method
  84. FnMongateConnect MongateConnectHttp;
  85. FnMongateQueryBalance MongateQueryBalanceHttp;
  86. FnMongateQueryUsed MongateQueryUsedHttp;
  87. FnMongateSendSms MongateSendSmsHttp;
  88. FnMongateChangePwd MongateChangePwdHttp;
  89. FnMongateDisconnect MongateDisconnectHttp;
  90. FnMongateTestConnHttp MongateTestConnHttp;
  91. FnMongateCsSendSmsHttp MongateCsSendSmsHttp;
  92. FnMongateConnectHttpProxy MongateConnectHttpProxy;
  93. FnMongateCsGetSmsHttp MongateCsGetSmsHttp;
  94. FnMongateCsGetStatusReportHttp MongateCsGetStatusReportHttp;
  95. FnMongateCsSPSendSmsNew MongateCsSPSendSmsNew;
  96. //Font *g_BlackFont=NULL;
  97. CDatabase *g_curdb=NULL;
  98. CDatabase g_db;
  99. CDatabase g_db2;
  100. CDatabase g_db3;
  101. CString g_date;
  102. CString g_title;
  103. CArray<CStringArray, CStringArray>g_userarray;
  104. CArray<CStringArray, CStringArray>g_cominfoarray;
  105. CArray<DWORD,DWORD>g_lengarray;
  106. CArray<DWORD,DWORD>g_btnlengarray;
  107. CArray<BYTE*,BYTE*>g_pointerarray;
  108. DWORD g_btnleng[8];
  109. int g_btnlengpos=-1;
  110. int g_nYearpos=-1;
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CLYFZSendMsgApp
  113. BOOL g_bShowOK=0;
  114. BOOL g_bStaffAchievementShow=0;
  115. USER g_user;
  116. CString g_mainpath;
  117. CString g_server;
  118. CString g_path1;
  119. CString g_path2;
  120. CString g_path3;
  121. CString g_path4;
  122. DWORD g_ncount;
  123. CFont g_titlefont;
  124. DWORD g_nSendCode=0;
  125. BOOL g_bSendOK=0;
  126. SENDHEAD g_sendhead;
  127. CArray<CStringArray, CStringArray>g_hisyeararray;
  128. extern CFont g_listctrlfont;
  129. //CMainCtrl g_tMainCtrl;
  130. #pragma comment(lib, "Transport.lib")
  131. #pragma comment(lib, "Winmm.lib")
  132. BEGIN_MESSAGE_MAP(CLYFZSendMsgApp, CWinApp)
  133. //{{AFX_MSG_MAP(CLYFZSendMsgApp)
  134. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  135. // NOTE - the ClassWizard will add and remove mapping macros here.
  136. // DO NOT EDIT what you see in these blocks of generated code!
  137. //}}AFX_MSG_MAP
  138. // Standard file based document commands
  139. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  140. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  141. END_MESSAGE_MAP()
  142. /////////////////////////////////////////////////////////////////////////////
  143. // CLYFZSendMsgApp construction
  144. float g_fscalex;
  145. float g_fscaley;
  146. DEVMODE g_dm;
  147. CLYFZSendMsgApp::CLYFZSendMsgApp()
  148. {
  149. // TODO: add construction code here,
  150. // Place all significant initialization in InitInstance
  151. g_dm.dmSize = sizeof(DEVMODE) ;
  152. EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&g_dm);
  153. g_fscalex=(float)g_dm.dmPelsWidth/1024.0;
  154. g_fscaley=(float)g_dm.dmPelsHeight/768.0;
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // The one and only CLYFZSendMsgApp object
  158. CLYFZSendMsgApp theApp;
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CLYFZSendMsgApp initialization
  161. DWORD FindAppProcessID(CString path)
  162. {
  163. try
  164. {
  165. HANDLE handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  166. PROCESSENTRY32 Info;
  167. Info.dwSize = sizeof(PROCESSENTRY32);
  168. path.MakeLower ();
  169. if(::Process32First(handle,&Info))
  170. {
  171. do
  172. {
  173. CString ss=Info.szExeFile;
  174. ss.MakeLower ();
  175. if(ss.Find (path)!=-1 || (!ss.CompareNoCase(path)) )
  176. {
  177. ::CloseHandle(handle);
  178. return Info.th32ProcessID;
  179. }
  180. }
  181. while(::Process32Next(handle,&Info));
  182. ::CloseHandle(handle);
  183. }
  184. return -1;
  185. }
  186. catch(...)
  187. {
  188. }
  189. }
  190. int GetPhoneCount(CString phones)
  191. {
  192. int count=0;
  193. int pos=phones.Find (",");
  194. if(pos!=-1)
  195. {
  196. count++;
  197. phones=phones.Right (phones.GetLength ()-pos-1);
  198. pos=phones.Find (",");
  199. while(pos!=-1)
  200. {
  201. count++;
  202. phones=phones.Right (phones.GetLength ()-pos-1);
  203. pos=phones.Find (",");
  204. }
  205. count++;
  206. }
  207. else
  208. count++;
  209. return count;
  210. }
  211. BOOL MyExecuteSQL(CDatabase *pdb, CString sql)
  212. {
  213. // MyLock lock("xiaoaccessdbmsg");
  214. try
  215. {
  216. pdb->ExecuteSQL (sql);
  217. }
  218. catch(...)
  219. {
  220. return 0;
  221. }
  222. return 1;
  223. }
  224. void ResetReg(CString id)
  225. {
  226. CString sql;
  227. sql.Format ("update [sendreg] set [msgcount2]='%d' where [autoid]=%d", 0, atol(id));
  228. MyExecuteSQL(&g_db2, sql);
  229. }
  230. BOOL CheckBadWords2(CString str,BOOL bMsg)
  231. {
  232. return 1;
  233. }
  234. CString g_temp;
  235. BOOL CheckBadWords(CString str,BOOL bMsg)
  236. {
  237. CString badwords[165]={\
  238. "【call5.me】",\
  239. "您可拨020",\
  240. "88btt.com热线400611",\
  241. "400678165",\
  242. "海王星",\
  243. "博天堂",\
  244. "十八大",\
  245. "钓鱼岛",\
  246. "无限次数提款",\
  247. "广东地和",\
  248. "利来",\
  249. "抢劫",\
  250. "fa lun",\
  251. "强奸",\
  252. "dafa",\
  253. "falun",\
  254. "SIM卡抽奖",\
  255. "罢工",\
  256. "罢课",\
  257. "暴乱",\
  258. "婊子",\
  259. "操你",\
  260. "操你娘",\
  261. "蠢猪",\
  262. "达赖",\
  263. "打倒",\
  264. "大法",\
  265. "大纪元",\
  266. "弹药",\
  267. "钓鱼岛",\
  268. "东突",\
  269. "东突厥斯坦伊斯兰运动",\
  270. "发抡",\
  271. "发仑",\
  272. "发伦",\
  273. "发囵",\
  274. "发沦",\
  275. "发纶",\
  276. "发轮",\
  277. "发论",\
  278. "法 轮 功",\
  279. "法.轮.功",\
  280. "法抡",\
  281. "法仑",\
  282. "法伦",\
  283. "法囵",\
  284. "法沦",\
  285. "法纶",\
  286. "法轮",\
  287. "法论",\
  288. "反革命",\
  289. "反日",\
  290. "分裂",\
  291. "干你娘",\
  292. "功友",\
  293. "古怪歌",\
  294. "国研新闻邮件",\
  295. "黑庄",\
  296. "宏志",\
  297. "洪志",\
  298. "胡锦涛",\
  299. "鸡巴",\
  300. "鸡毛信文汇",\
  301. "妓女",\
  302. "简鸿章",\
  303. "江八点",\
  304. "江独裁",\
  305. "江泽民",\
  306. "疆独",\
  307. "教徒",\
  308. "锦涛",\
  309. "靖国神社",\
  310. "九、评",\
  311. "九.评",\
  312. "九码",\
  313. "九-评",\
  314. "拉丹",\
  315. "拉登",\
  316. "李鹏",\
  317. "联总之声传单",\
  318. "灵动卡",\
  319. "六合彩",\
  320. "六码",\
  321. "吕秀莲",\
  322. "绿色环保手机",\
  323. "美国之音",\
  324. "猛料",\
  325. "迷药",\
  326. "民运",\
  327. "民猪",\
  328. "嫖娼",\
  329. "迫害",\
  330. "枪支",\
  331. "强奸",\
  332. "窃听器",\
  333. "人民报",\
  334. "人民报讯",\
  335. "人民大众时事参考",\
  336. "人民内情真相",\
  337. "人民真实报道",\
  338. "人权",\
  339. "日你妈",\
  340. "日他",\
  341. "三码",\
  342. "三陪",\
  343. "色情",\
  344. "傻B",\
  345. "涉日",\
  346. "十六大",\
  347. "示威",\
  348. "他妈的",\
  349. "台*湾",\
  350. "特等奖",\
  351. "天葬",\
  352. "突厥斯坦",\
  353. "推翻",\
  354. "王八蛋",\
  355. "温家宝",\
  356. "无能",\
  357. "香港总部",\
  358. "小鸡鸡",\
  359. "新华举报",\
  360. "新华内情",\
  361. "新闻封锁",\
  362. "畜生",\
  363. "玄`机",\
  364. "压迫",\
  365. "淫秽",\
  366. "银行联合管理局",\
  367. "印尼伊斯兰祈祷团",\
  368. "游行",\
  369. "舆论",\
  370. "造反",\
  371. "真善忍",\
  372. "镇压",\
  373. "正法",\
  374. "政变",\
  375. "政治风波",\
  376. "中俄边界新约",\
  377. "中国银联",\
  378. "中华民国",\
  379. "中奖",\
  380. "朱容基",\
  381. "自焚",\
  382. "自由运动",\
  383. "达赖",\
  384. "套牌",\
  385. "情妇",\
  386. "监听",\
  387. "巴南电信",\
  388. "合川分公司",\
  389. "合川电信",\
  390. "死光",\
  391. "116114",\
  392. "北京宝诚",\
  393. "华盛投资",\
  394. "名门国际",\
  395. "利博",\
  396. "赤橙黄绿",\
  397. "免佣BJL首发",\
  398. "洗*码优惠",\
  399. "【俱乐部】",\
  400. "18266381922",\
  401. "回拨卡",\
  402. "号码百事通推出短信订机票!实时"};
  403. for(int i=0; i<165; i++)
  404. {
  405. g_temp=badwords[i];
  406. if(str.Find (g_temp)!=-1)
  407. {
  408. // AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
  409. return 0;
  410. }
  411. }
  412. return 1;
  413. }
  414. extern int g_iLeft; // Jeff.通过查询短信服务商获得的短信可用的余额;
  415. extern int g_iUsed;
  416. extern int g_nQuery;
  417. int g_bRunOnce=0;
  418. BOOL IsPlaySound()
  419. {
  420. return 0;
  421. CTime tm=CTime::GetCurrentTime ();
  422. if( !(tm.GetHour ()>22 && tm.GetHour ()<9) )return 1;
  423. return 0;
  424. }
  425. void Encode(const char *Inbuf, char *Outbuf)
  426. {
  427. char table[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  428. unsigned char c80,c81,c82;
  429. int i,k;
  430. int nInLen=strlen(Inbuf);
  431. // int nOutLen;
  432. if(strlen(Inbuf)==0) //输入出错了
  433. exit(-1);
  434. int IndexOut=0;
  435. unsigned short tmp1,tmp2;
  436. k=nInLen/3; ///完整的、可以凑足3倍数的部分
  437. for(i=0;i<k;i++)
  438. {
  439. c80=Inbuf[i*3];
  440. c81 = Inbuf[i*3+1];
  441. c82 = Inbuf[i*3+2];
  442. tmp1=(unsigned short)c80 <<8 | c81 ;
  443. tmp2=(unsigned short)c81 <<8 | c82;
  444. tmp1= (tmp1>>4 ) & 0x003f;
  445. tmp2= (tmp2>>6 ) & 0x003f;
  446. Outbuf[IndexOut]=table[c80>>2];
  447. IndexOut++;
  448. Outbuf[IndexOut]=table[tmp1];
  449. IndexOut++;
  450. Outbuf[IndexOut]=table[tmp2];
  451. IndexOut++;
  452. Outbuf[IndexOut]=table[c82 & 0x3f];
  453. IndexOut++;
  454. }
  455. if(nInLen%3==0)
  456. {
  457. Outbuf[IndexOut]='\0';
  458. return;
  459. }
  460. ////////////////////////剩余的不足整倍数的部分
  461. k=nInLen%3;
  462. i=nInLen/3;
  463. c80=Inbuf[i*3];
  464. if(k==1)
  465. {
  466. Outbuf[IndexOut]=table[(c80 >>2) & 0x3f];
  467. IndexOut++;
  468. Outbuf[IndexOut]=table[(c80 <<4) & 0x3f];
  469. IndexOut++;
  470. Outbuf[IndexOut]='=';
  471. IndexOut++;
  472. Outbuf[IndexOut]='=';
  473. IndexOut++;
  474. }
  475. else
  476. {
  477. c81 = Inbuf[i*3+1];
  478. tmp1=(unsigned short)c80 <<8 | c81;
  479. tmp1= (tmp1>>4 ) & 0x003f;
  480. Outbuf[IndexOut]=table[(c80 >>2) & 0x3f];
  481. IndexOut++;
  482. Outbuf[IndexOut]=table[tmp1];
  483. IndexOut++;
  484. Outbuf[IndexOut]=table[(c81 <<2) & 0x3f];
  485. IndexOut++;
  486. Outbuf[IndexOut]='=';
  487. IndexOut++;
  488. }
  489. //end of some more.
  490. Outbuf[IndexOut]='\0';
  491. }
  492. void Decode( char *Inbuf, char *Outbuf)
  493. {
  494. int nInLen;
  495. CString Base64Code("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
  496. nInLen=strlen(Inbuf);
  497. if(nInLen%4!=0) //长度有误
  498. exit(-1);
  499. int nOutLen=nInLen /4 *3;
  500. Outbuf=new char[nOutLen +4]; ///////////为输出分配存储空间
  501. int i=0;
  502. while(Inbuf[i] != '\0') /////把末尾的“===”转换为0
  503. if(Inbuf[i]== '=')
  504. Inbuf[i]=0;
  505. unsigned short a,b,c,d;
  506. char tmp;
  507. for(int LoopValue=0;LoopValue<nInLen/4;LoopValue++) //循环变量
  508. {
  509. a= Base64Code.Find(Inbuf[LoopValue*4]);
  510. b= Base64Code.Find(Inbuf[LoopValue*4 +1]);
  511. if(Inbuf[LoopValue*4 +2]==0)
  512. c=0;
  513. else
  514. c= Base64Code.Find(Inbuf[LoopValue*4 +2]);
  515. if(Inbuf[LoopValue*4 +3]==0)
  516. d=0;
  517. else
  518. d= Base64Code.Find(Inbuf[LoopValue*4 +3]);
  519. tmp= (a <<6) | (b>>4);
  520. *Outbuf=tmp;
  521. Outbuf++;
  522. tmp= (b<<4) | ((c>>2) <<4);
  523. if(tmp!=0)
  524. {
  525. *Outbuf=tmp;
  526. Outbuf++;
  527. }
  528. tmp= (c<<6) | d;
  529. if(tmp!=0)
  530. {
  531. *Outbuf=tmp;
  532. Outbuf++;
  533. }
  534. }
  535. *Outbuf=0;
  536. }
  537. int GetFormBalanceJXT(CString name, CString psw)
  538. {//http://service.winic.org:8009/webservice/public/remoney.asp?uid=lyfz&pwd=123456
  539. CHttpClient conn;
  540. CString value="http://service.winic.org:8009/webservice/public/remoney.asp?";
  541. CString temp;
  542. temp.Format ("uid=%s", name);
  543. value+=temp;
  544. temp.Format ("&pwd=%s", psw);
  545. value+=temp;
  546. value=conn.doGet(value);
  547. if(value.Find ("-")!=-1)return -1;
  548. if(value.Find ("null")!=-1)return -1;
  549. int count=(int)(atof(value)/0.05);
  550. return count;
  551. }
  552. int GetFormBalanceSYT(CString name, CString psw)
  553. {
  554. CHttpClient conn;
  555. CString value="http://www.mb2e.com/ws/SelSum.aspx?";
  556. CString temp;
  557. temp.Format ("CorpID=%s", name);
  558. value+=temp;
  559. temp.Format ("&Pwd=%s", psw);
  560. value+=temp;
  561. value=conn.doGet(value);
  562. if(value.Find ("-")!=-1)return -1;
  563. return atoi(value);
  564. }
  565. CString GetFormBalanceBeiJing(CString name, CString psw)
  566. {
  567. CHttpClient conn;
  568. CString value="http://121.52.221.108/send/getfee.aspx?";
  569. CString temp;
  570. temp.Format ("name=%s", name);
  571. value+=temp;
  572. temp.Format ("&pwd=%s", psw);
  573. value+=temp;
  574. value=conn.doGet(value);
  575. int pos=value.Find ("&");
  576. if(pos==-1)
  577. {
  578. return "-1";
  579. }
  580. value=value.Left (pos);value.TrimLeft ("id=");
  581. return value;
  582. }
  583. // ----------------------------------------------------------------------------
  584. // remark by Jeff: 2014-09-17 PM;
  585. // 函数:
  586. // 描述:通过账号密码登录指定短信服务商,获取短信可用余额(Money);
  587. // 参数:
  588. // name:短信服务账号;
  589. // psw: 短信服务密码;
  590. //
  591. // 通过全局变量g_bMsgRoad来指定短信服务商;
  592. // 使用的全局变量:g_bMsgRoad 短信服务商, == 0 ??? ; == 1 吉信通; == 2 ???;
  593. //
  594. // ----------------------------------------------------------------------------
  595. int GetFormBalance(CString name, CString psw)
  596. {
  597. // return atoi(GetFormBalanceBeiJing("lyfzrj", "lyfzrj123"));
  598. if(g_bMsgRoad==1)
  599. {
  600. return GetFormBalanceJXT( name, psw);
  601. }
  602. else if(g_bMsgRoad==2)
  603. {
  604. return GetFormBalanceSYT( name, psw);
  605. }
  606. CHttpClient conn;
  607. CString value="http://www2.lansea.com.cn/servlet/UserServiceAPI?";
  608. CString temp;
  609. value+="method=getRestMoney";
  610. temp.Format ("&username=%s", name);
  611. value+=temp;
  612. temp.Format ("&password=%s", psw);
  613. value+=temp;
  614. value=conn.doGet(value);
  615. CString finder="gateSmsNum=";
  616. int pos=value.Find (finder);
  617. if(pos==-1)return -1;
  618. value=value.Right (value.GetLength ()-finder.GetLength ()-pos);
  619. pos=value.Find (";");
  620. if(pos!=-1)
  621. {
  622. value=value.Left(pos);
  623. }
  624. return atoi(value);
  625. }
  626. // ----------------------------------------------------------------------------
  627. // Remark by Jeff;
  628. // 函数:SendFormMsgJXT
  629. // 描述:使用HTTP方式连接吉信通服务端来发送短信;
  630. // 参数:
  631. // 返回:
  632. //
  633. // 吉信通返回:
  634. // 000:发送短信成功;
  635. // -11:短信内容超长(70个字符); // 经过询问吉信通技术员,该返回值基本没有任何参考价值!
  636. //
  637. // HTTP返回格式:
  638. // -02/Send:1/Consumption:0/Tmoney:0 / sid;
  639. // 状态码/发送条数/当次消费金额/总体余额/短信编号;
  640. // ----------------------------------------------------------------------------
  641. int SendFormMsgJXT(CString name, CString psw, CString phones, CString content, CString &pRtn)
  642. {
  643. //http://service.winic.org:8009/sys_port/gateway/?id=lyfz&pwd=123456&to=18666532220&content=hello33
  644. CHttpClient conn;
  645. CString value="http://service.winic.org:8009/sys_port/gateway/?";
  646. CString temp;
  647. temp.Format ("id=%s", name);
  648. value+=temp;
  649. temp.Format ("&pwd=%s", psw);
  650. value+=temp;
  651. temp.Format ("&to=%s", phones);
  652. value+=temp;
  653. temp.Format ("&content=%s", content);
  654. value+=temp;
  655. pRtn=conn.doGet(value);
  656. if(pRtn.GetLength()<3)return 0;
  657. if(pRtn.Left(3)=="000")return 1;
  658. if(pRtn.GetLength()>50)pRtn=pRtn.Left(50);
  659. return 0;
  660. }
  661. void SendFormMsgJXT_01(CString name, CString psw, CString phones, CString content, CString &pRtn)
  662. {
  663. //http://service.winic.org:8009/sys_port/gateway/?id=lyfz&pwd=123456&to=18666532220&content=hello33
  664. CHttpClient conn;
  665. CString value="http://service.winic.org:8009/sys_port/gateway/?";
  666. CString temp;
  667. temp.Format ("id=%s", name);
  668. value+=temp;
  669. temp.Format ("&pwd=%s", psw);
  670. value+=temp;
  671. temp.Format ("&to=%s", phones);
  672. value+=temp;
  673. temp.Format ("&content=%s", content);
  674. value+=temp;
  675. pRtn = conn.doGet(value);
  676. #if 0
  677. if(pRtn.GetLength()<3)return 0;
  678. if(pRtn.Left(3)=="000")return 1;
  679. if(pRtn.GetLength()>50)pRtn=pRtn.Left(50);
  680. return 0;
  681. #endif
  682. }
  683. CString SendFormMsgBeiJing(CString name, CString psw, CString phones, CString content, CString &pRtn)
  684. {
  685. try
  686. {
  687. CHttpClient conn;
  688. CString value="http://121.52.221.108/send/gsend.aspx?";
  689. value="http://121.52.221.108/send/g70send.aspx?";
  690. CString temp;
  691. temp.Format ("name=%s", name);
  692. value+=temp;
  693. temp.Format ("&pwd=%s", psw);
  694. value+=temp;
  695. temp.Format ("&dst=%s", phones);
  696. value+=temp;
  697. temp.Format ("&msg=%s", content);
  698. value+=temp;
  699. temp.Format ("&sequeid=%s", "12345");
  700. value+=temp;
  701. pRtn=conn.doGet(value);
  702. }
  703. catch(...)
  704. {
  705. }
  706. return pRtn;
  707. }
  708. int SendFormMsgSYT(CString name, CString psw, CString phones, CString content, CString &pRtn)
  709. {
  710. CHttpClient conn;
  711. CString value="http://www.mb2e.com/ws/Send2.aspx?";
  712. if(phones.Find (",")!=-1)value="http://www.mb2e.com/ws/BatchSend2.aspx?";
  713. CString temp;
  714. temp.Format ("CorpID=%s", name);
  715. value+=temp;
  716. temp.Format ("&Pwd=%s", psw);
  717. value+=temp;
  718. temp.Format ("&Mobile=%s", phones);
  719. value+=temp;
  720. temp.Format ("&Content=%s", content);
  721. value+=temp;
  722. pRtn=conn.doGet(value);
  723. if(atoi(pRtn)>0)return 1;
  724. return 0;
  725. }
  726. // Jeff.SendFormMsg没有被其他任何函数调用;
  727. //
  728. int SendFormMsg(CString name, CString psw, CString phones, CString content, CString &pRtn)
  729. {
  730. if(g_bMsgRoad==1)
  731. {
  732. return SendFormMsgJXT( name, psw, phones, content, pRtn);
  733. }
  734. else if(g_bMsgRoad==2)
  735. {
  736. return SendFormMsgSYT( name, psw, phones, content, pRtn);
  737. }
  738. CHttpClient conn;
  739. CString value="http://www2.lansea.com.cn/servlet/UserServiceAPI?";
  740. CString temp;
  741. value+="method=sendSMS";
  742. value+="&isLongSms=0";
  743. temp.Format ("&username=%s", name);
  744. value+=temp;
  745. temp.Format ("&password=%s", psw);
  746. value+=temp;
  747. value+="&smstype=1";
  748. temp.Format ("&mobile=%s", phones);
  749. value+=temp;
  750. temp.Format ("&content=%s", content);
  751. value+=temp;
  752. pRtn=conn.doGet(value);
  753. CString finder="success";
  754. int pos=pRtn.Find (finder);
  755. if(pos==-1)return 0;
  756. return 1;
  757. }
  758. int FindArray(CStringArray *pArray, CString Str)
  759. {
  760. for(int i=0; i<pArray->GetSize(); i++)
  761. {
  762. if(pArray->ElementAt(i)==Str)
  763. return i;
  764. }
  765. return -1;
  766. }
  767. BOOL g_bLoadroad2clientarray=1;
  768. CStringArray g_road2clientarray;
  769. CStringArray g_road3clientarray;
  770. void Loadroad2clientarray()
  771. {
  772. if(g_bLoadroad2clientarray)
  773. {
  774. g_bLoadroad2clientarray=0;
  775. g_road2clientarray.RemoveAll();
  776. g_road3clientarray.RemoveAll();
  777. CRstClientInfo rsSt;
  778. rsSt.m_strFilter ="[road]='1'";
  779. rsSt.m_pDatabase=&g_db2;
  780. rsSt.Open();
  781. while(!rsSt.IsEOF())
  782. {
  783. g_road2clientarray.Add(rsSt.m_account) ;
  784. rsSt.MoveNext();
  785. }
  786. rsSt.Close();
  787. rsSt.m_strFilter ="[road]='2'";
  788. rsSt.m_pDatabase=&g_db2;
  789. rsSt.Open();
  790. while(!rsSt.IsEOF())
  791. {
  792. g_road3clientarray.Add(rsSt.m_account) ;
  793. rsSt.MoveNext();
  794. }
  795. rsSt.Close();
  796. }
  797. }
  798. int GetLengthEx2(CString str)
  799. {
  800. wchar_t wstr[500];
  801. int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
  802. return k;
  803. }
  804. void FirstLetter(int nCode, CString& strLetter)
  805. {
  806. if(nCode >= 1601 && nCode < 1637) strLetter = _T("A");
  807. if(nCode >= 1637 && nCode < 1833) strLetter = _T("B");
  808. if(nCode >= 1833 && nCode < 2078) strLetter = _T("C");
  809. if(nCode >= 2078 && nCode < 2274) strLetter = _T("D");
  810. if(nCode >= 2274 && nCode < 2302) strLetter = _T("E");
  811. if(nCode >= 2302 && nCode < 2433) strLetter = _T("F");
  812. if(nCode >= 2433 && nCode < 2594) strLetter = _T("G");
  813. if(nCode >= 2594 && nCode < 2787) strLetter = _T("H");
  814. if(nCode >= 2787 && nCode < 3106) strLetter = _T("J");
  815. if(nCode >= 3106 && nCode < 3212) strLetter = _T("K");
  816. if(nCode >= 3212 && nCode < 3472) strLetter = _T("L");
  817. if(nCode >= 3472 && nCode < 3635) strLetter = _T("M");
  818. if(nCode >= 3635 && nCode < 3722) strLetter = _T("N");
  819. if(nCode >= 3722 && nCode < 3730) strLetter = _T("O");
  820. if(nCode >= 3730 && nCode < 3858) strLetter = _T("P");
  821. if(nCode >= 3858 && nCode < 4027) strLetter = _T("Q");
  822. if(nCode >= 4027 && nCode < 4086) strLetter = _T("R");
  823. if(nCode >= 4086 && nCode < 4390) strLetter = _T("S");
  824. if(nCode >= 4390 && nCode < 4558) strLetter = _T("T");
  825. if(nCode >= 4558 && nCode < 4684) strLetter = _T("W");
  826. if(nCode >= 4684 && nCode < 4925) strLetter = _T("X");
  827. if(nCode >= 4925 && nCode < 5249) strLetter = _T("Y");
  828. if(nCode >= 5249 && nCode < 5590) strLetter = _T("Z");
  829. }
  830. void GetFirstLetter(CString strName, CString& strFirstLetter)
  831. {
  832. try
  833. {
  834. TBYTE ucHigh, ucLow;
  835. int nCode;
  836. CString strRet;
  837. strFirstLetter.Empty();
  838. for (int i=0; i<strName.GetLength(); i++)
  839. {
  840. if ( (TBYTE)strName[i] < 0x80 )
  841. {
  842. strRet=strName.Mid (i,1);
  843. strRet.MakeUpper ();
  844. strFirstLetter += strRet;
  845. continue;
  846. }
  847. ucHigh = (TBYTE)strName[i];
  848. ucLow = (TBYTE)strName[i+1];
  849. if ( ucHigh < 0xa1 || ucLow < 0xa1)
  850. continue;
  851. else
  852. // Treat code by section-position as an int type parameter,
  853. // so make following change to nCode.
  854. nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;
  855. FirstLetter(nCode, strRet);
  856. strFirstLetter += strRet;
  857. i++;
  858. }
  859. }
  860. catch(...)
  861. {
  862. }
  863. }
  864. //--------------------------------------------------------------
  865. //
  866. //
  867. //
  868. //
  869. //
  870. //--------------------------------------------------------------
  871. unsigned __stdcall SendMsgThread(LPVOID lpParam)
  872. {
  873. ll: CLYFZSendMsgApp *pDlg=(CLYFZSendMsgApp*)lpParam;
  874. /*
  875. pDlg->m_bRunning=false;
  876. pDlg->m_bTerminate=false;
  877. _endthreadex( 0 ); pDlg->m_hThread=NULL;
  878. return 0;
  879. */
  880. int bSendTypeUnicom=0;
  881. int step=0;
  882. try
  883. {
  884. BOOL bServer=1;
  885. CString account="5500037";
  886. CString psw="516842";
  887. char spsw[100];
  888. Encode(psw, spsw);
  889. psw=spsw;
  890. CString account0=account;
  891. CString psw0=psw;
  892. while(1)
  893. {
  894. if(pDlg->m_bTerminate)break;
  895. step=0;
  896. // if(g_bLoadroad2clientarray)Loadroad2clientarray();
  897. g_bMsgRoad=g_bMsgRoadtemp;
  898. if(g_bMsgRoad==1)
  899. {
  900. account=Global::g_szSMSAccount;
  901. psw=Global::g_szSMSPassword;
  902. }
  903. else if(g_bMsgRoad==2)
  904. {
  905. account="test01";
  906. psw="123456";
  907. }
  908. else
  909. {
  910. account=account0;
  911. psw=psw0;
  912. }
  913. if(g_nQuery==1)
  914. {
  915. // g_iLeft = atoi(GetFormBalanceBeiJing("lyfzrj", "lyfzrj123"));//GetFormBalance(account, psw);
  916. // g_iUsed= atoi(GetFormBalanceBeiJing("lyfzrj1", "lyfz1234"));
  917. g_iLeft =GetFormBalance(account, psw); // Jeff 通过查询短信服务商获得的短信可用的余额;
  918. g_iUsed=0;
  919. g_nQuery=0;
  920. }
  921. // Jeff.g_bSend用来控制线程是否继续操作;
  922. if(g_bSend==0)
  923. {
  924. ::Sleep (1000);
  925. continue;
  926. }
  927. // Jeff remark:
  928. // g_bRunOnce作用? 用来重置什么?
  929. // msgcount2 == -2是什么作用?
  930. if(g_bRunOnce==0)
  931. {
  932. CString sql;
  933. sql.Format ("update [sendreg] set [msgcount2]='%d' where [msgcount2]='%d'", 0, -2);
  934. if(MyExecuteSQL(&g_db2, sql)==0)
  935. {
  936. ::Sleep(100);
  937. WriteLogin("重置失败!");
  938. continue;
  939. }
  940. }
  941. g_bRunOnce++;
  942. if(g_bRunOnce==10)g_bRunOnce=0;
  943. CString id; // 表自增id;
  944. CString phones; // 接收短信的手机号;
  945. CString content; // 短信内容;
  946. CString timestamp; // 短信生成时间;
  947. CString log; // 短信日志;
  948. timestamp=CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
  949. int timestampleng=timestamp.GetLength ();
  950. //BOOL bEof=0; // Jeff,这个变量命名使人误会!应该命名为bValid或bValidRecord,有效或有效的记录;
  951. BOOL bValidRecord = FALSE; // Jeff Modify;
  952. CString clientaccount;
  953. // -----------------------------------------------------------------------------------------
  954. // Remark by Jeff 2014-09-17
  955. // 每次Open数据集时,打开的永远是符合查询条件的第一条记录;
  956. // 当线程处理速度赶不上新短信内容插入的速度时,这样会造成短信积压,记录集最底部的记录永远是最后发送的;
  957. // 如果一直有新短信内容插入数据库表,那么记录集底部的短信就有可能永远不会被发送出去,造成所谓的"短信发不出去".
  958. // 应该使用MoveLast()移动到最后一条记录,从记录集底部开始发送;
  959. // -----------------------------------------------------------------------------------------
  960. if(1)
  961. {
  962. step=1;
  963. RstSendReg rsSt;
  964. rsSt.m_strFilter ="[msgcount2]='0' and ([log] is null or [log]<>'超过12小时' or [log]='超过12小时重发')";
  965. rsSt.m_pDatabase=&g_db2;
  966. rsSt.Open();
  967. if(!rsSt.IsEOF())
  968. {
  969. //bEof=1;
  970. bValidRecord = TRUE;
  971. id=rsSt.m_id;
  972. phones=rsSt.m_phones;
  973. content=rsSt.m_content;
  974. timestamp=rsSt.m_timestamp;
  975. log=rsSt.log;
  976. rsSt.Close();
  977. clientaccount=rsSt.m_account;
  978. if(clientaccount=="453203" && content=="阳光贝贝儿童摄影祝您全家元旦快乐元月6号前办理VIP赠礼品送成长录老会员免 费升级更多优 惠登陆WWW·SXYGBB·COM或3826526")
  979. {
  980. RstSendReg rsSt;
  981. rsSt.m_strFilter.Format("[msgcount2]<>'0' and content='阳光贝贝儿童摄影祝您全家元旦快乐元月6号前办理VIP赠礼品送成长录老会员免 费升级更多优 惠登陆WWW·SXYGBB·COM或3826526' and phones like '%%s%'", phones);
  982. rsSt.m_pDatabase=&g_db2;
  983. rsSt.Open();
  984. BOOL exist=0;
  985. if(!rsSt.IsEOF())
  986. {
  987. exist=1;
  988. }
  989. rsSt.Close();
  990. if(exist)
  991. {
  992. CString sql;
  993. sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s' where [autoid]=%d", 1, "77777777", atol(id));
  994. MyExecuteSQL(&g_db2, sql);
  995. continue;
  996. }
  997. }
  998. }
  999. else
  1000. {
  1001. // WriteLogin("查询无未发信息!");
  1002. rsSt.Close();
  1003. }
  1004. }
  1005. step=2;
  1006. if(g_bMsgRoad==1)
  1007. {
  1008. account=Global::g_szSMSAccount;
  1009. psw=Global::g_szSMSPassword;
  1010. }
  1011. bSendTypeUnicom=0; // 用途???
  1012. // -----------------------------------------------------------------------------------------
  1013. // Remark by Jeff:
  1014. // g_road2clientarray 初始化或插入数据的函数在Loadroad2clientarray(); 但是,整个程序却没有任何一处调用该函数;
  1015. // 唯一调用Loadroad2clientarray()的是在本线程,却被注释掉的;
  1016. // 那么g_road2clientarray为空的数组,FindArray就没有任何意义;
  1017. // 同样g_road3clientarray也是与g_road2clientarray一样的函数初始化和插入数据;
  1018. // 这样导致 bSendTypeUnicom == 2 永久性的;
  1019. // -----------------------------------------------------------------------------------------
  1020. if(-1 != FindArray(&g_road2clientarray, clientaccount))
  1021. bSendTypeUnicom=1;
  1022. if(-1 != FindArray(&g_road3clientarray, clientaccount))
  1023. bSendTypeUnicom=2;
  1024. //if(bEof)
  1025. if( bValidRecord )
  1026. {
  1027. content.TrimLeft();
  1028. content.TrimRight();
  1029. content.Replace("\r", "");
  1030. content.Replace("", "");
  1031. content.Replace("\n", "");
  1032. content.Replace("'", "");
  1033. // content.Replace ("短信", "信");
  1034. // content.Replace ("信息", "信");
  1035. content.Replace ("优惠", "优蕙");
  1036. content.Replace ("询", "讯");
  1037. content.Replace ("免费", "免費");
  1038. content.Replace ("珺", "君");
  1039. content.Replace (",北京", "北-京");
  1040. content.Replace ("拨打", "撥打");
  1041. content.Replace ("销售", "銷售");
  1042. content.Replace ("热线", "专线");
  1043. content.Replace ("抢购", "购买");
  1044. content.Replace ("彧", "或");
  1045. content.Replace ("QQ", "扣扣");
  1046. content.Replace ("第一次", "第1次");
  1047. content.Replace ("兑换", "换取");
  1048. content.Replace ("账户", "帳戶");
  1049. content.Replace ("账号", "帳号");
  1050. content.Replace ("户名", "戶名");
  1051. content.Replace ("刺激", "剌激");
  1052. content.Replace ("集团", "集團");
  1053. content.Replace ("10159", "10158");
  1054. phones.TrimLeft();
  1055. phones.TrimRight();
  1056. CString sql;
  1057. // Jeff:短信内容与strarray数组里任意元素的相同,短信不发送,但仍收费;
  1058. CStringArray strarray;
  1059. strarray.Add ("!");
  1060. strarray.Add ("!!");
  1061. strarray.Add ("!!!");
  1062. strarray.Add ("!");
  1063. strarray.Add ("!!");
  1064. strarray.Add ("!!!");
  1065. strarray.Add (".");
  1066. strarray.Add ("..");
  1067. strarray.Add ("...");
  1068. strarray.Add ("。");
  1069. strarray.Add ("。。");
  1070. strarray.Add ("。。。");
  1071. strarray.Add ("上");
  1072. BOOL bSend=1;
  1073. for(int y=0; y<strarray.GetSize(); y++)
  1074. {
  1075. if(content==strarray.ElementAt(y))
  1076. {
  1077. bSend=0;
  1078. break;
  1079. }
  1080. }
  1081. step=3;
  1082. if(!bSend) // 针对上面strarray==content的情况;
  1083. {
  1084. sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s' where [autoid]=%d", 1, "88888888", atol(id));
  1085. MyExecuteSQL(&g_db2, sql);
  1086. continue;
  1087. }
  1088. // 查询条件:"[msgcount2]='0' and ([log] is null or [log]<>'超过12小时' or [log]='超过12小时重发')"
  1089. // log != 超过12小时重发 && ([log] is null or [log]<>'超过12小时')
  1090. if(timestamp.GetLength()==14 && log != "超过12小时重发")
  1091. {
  1092. if(timestamp.Left(2)=="20")
  1093. {
  1094. CTime tm(atoi(timestamp.Mid (0,4)),atoi(timestamp.Mid (4,2)),atoi(timestamp.Mid (6,2)),atoi(timestamp.Mid (8,2)),atoi(timestamp.Mid (10,2)),atoi(timestamp.Mid (12,2)));
  1095. CTime tm2=CTime::GetCurrentTime ();
  1096. CTimeSpan dt=tm2-tm;
  1097. if(dt.GetDays()>1)
  1098. {
  1099. // timestamp+="超";
  1100. sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s',[timestamp]='%s' where [autoid]=%d", 0, "超过12小时", timestamp,atol(id));
  1101. MyExecuteSQL(&g_db2, sql);
  1102. continue;
  1103. }
  1104. }
  1105. }
  1106. step=4;
  1107. sql.Format ("update [sendreg] set [msgcount2]='%d' where [autoid]=%d", -2, atol(id));
  1108. if(MyExecuteSQL(&g_db2, sql)==0)
  1109. {
  1110. WriteLogin("保存发送中失败!");
  1111. ::Sleep (100);
  1112. continue;
  1113. }
  1114. step=5;
  1115. ////////////////////连接
  1116. int count=GetPhoneCount(phones);
  1117. step=6;
  1118. CString pRtn;
  1119. int nRet;
  1120. #if 0
  1121. /* if(bSendTypeUnicom==0)//北京
  1122. {
  1123. SendFormMsgBeiJing("lyfzrj", "lyfzrj123", phones, content, pRtn);
  1124. step=7;
  1125. CString strRes1;
  1126. GetFirstLetter(pRtn, strRes1); step=8;
  1127. pRtn=strRes1;
  1128. if(pRtn.GetLength ()>250)
  1129. {
  1130. pRtn=pRtn.Left (250);
  1131. }
  1132. }
  1133. else if(bSendTypeUnicom==1)//北京
  1134. {
  1135. SendFormMsgBeiJing("lyfzrj1", "lyfz1234", phones, content, pRtn);
  1136. step=9;
  1137. CString strRes1;
  1138. GetFirstLetter(pRtn, strRes1);
  1139. step=10;
  1140. pRtn=strRes1;
  1141. if(pRtn.GetLength ()>250)
  1142. {
  1143. pRtn=pRtn.Left (250);
  1144. }
  1145. }
  1146. else*/
  1147. {
  1148. SendFormMsgJXT("lyfz", "lyfz0752", phones, content, pRtn);
  1149. CString strRes1;
  1150. GetFirstLetter(pRtn, strRes1);
  1151. pRtn=strRes1;
  1152. if(pRtn.GetLength ()>250)
  1153. {
  1154. pRtn=pRtn.Left (250);
  1155. }
  1156. }
  1157. step=11;
  1158. pRtn.MakeLower();
  1159. CString log=pRtn;
  1160. sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s',[sendtime]='%s' where [autoid]=%d", count, log, CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S"), atol(id) );
  1161. if(MyExecuteSQL(&g_db2, sql)==0)
  1162. {
  1163. // if(bSendTypeUnicom!=2)//北京维那
  1164. // WriteLogin("保存发送记录失败北京维那!");
  1165. // else
  1166. WriteLogin("保存发送记录失败2!");
  1167. }
  1168. step=12;
  1169. ::Sleep (100);
  1170. #else
  1171. SendFormMsgJXT_01(Global::g_szSMSAccount, Global::g_szSMSPassword, phones, content, pRtn);
  1172. if ( pRtn == "")
  1173. {
  1174. // 短信发往运营商服务平台返回异常;
  1175. // 认为没有发送,不处理,不扣费;
  1176. // sql.Format("update sendreg set [msgcount2]='%d',[log]='%s',[sendtime]='%s' where [autoid]=%d", count ,log, CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"), atol(id) );
  1177. }
  1178. else
  1179. {
  1180. AnalysisJXTRespond AnalysisRespond;
  1181. pRtn.MakeLower();
  1182. if ( AnalysisRespond.AnalysisRespondString(pRtn) != 0 /*0xF*/ ) // 0xF表示返回的结果是正常的;
  1183. {
  1184. //CString log=pRtn;
  1185. // Jeff,假如AnalysisRespond.nStatus=0,最好在这里更新msgcount的值:如果原来的值小于当前值,则update;
  1186. // SQL:update sendreg set [msgcount]=case when [msgcount]< nSendCount then nSendCount else [msgcount],msgcount2=nSendCount,log="",sendtime="" where autoid=""
  1187. sql.Format("update sendreg set [msgcount]=case when [msgcount] < '%d' then '%d' else [msgcount] end,[msgcount2]='%d',[log]='%s',[sendtime]='%s' where [autoid]=%d",
  1188. AnalysisRespond.nSendCount,AnalysisRespond.nSendCount,AnalysisRespond.nSendCount, pRtn, CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"), atol(id));
  1189. //sql.Format("update sendreg set [msgcount2]='%d',[log]='%s',[sendtime]='%s' where [autoid]=%d",AnalysisRespond.nSendCount, pRtn, CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"), atol(id) );
  1190. }
  1191. else
  1192. {
  1193. // 返回其他值,表示有异常。此处只处理返回0的结果;
  1194. // 扣费正常执行,不修改msgcount的值;
  1195. log = pRtn;
  1196. sql.Format("update sendreg set [msgcount2]='%d',[log]='%s',[sendtime]='%s' where [autoid]=%d", count, log, CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"), atol(id) );
  1197. }
  1198. step=11;
  1199. if(MyExecuteSQL(&g_db2, sql)==0)
  1200. {
  1201. WriteLogin("保存发送记录失败2!");
  1202. }
  1203. step=12;
  1204. ::Sleep (100);
  1205. }
  1206. #endif
  1207. }
  1208. else
  1209. {
  1210. ::Sleep (6000);
  1211. }
  1212. }
  1213. }
  1214. catch(...)
  1215. {
  1216. CString str;
  1217. str.Format("step:%d", step);
  1218. /* if(bSendTypeUnicom!=2)
  1219. WriteLogin("发送出错,北京维那!"+str);
  1220. else*/
  1221. WriteLogin("发送出错!"+str);
  1222. goto ll;
  1223. }
  1224. pDlg->m_bRunning=false;
  1225. pDlg->m_bTerminate=false;
  1226. _endthreadex( 0 ); // Jeff.调用了_endthreadex(0)退出后,下面的代码就不会执行;
  1227. pDlg->m_hThread=NULL;
  1228. return 0;
  1229. }
  1230. void BakData(CString savedir)
  1231. {
  1232. char server[50];
  1233. DWORD leng=50;
  1234. memset(server, 0, 50);
  1235. ::GetComputerName (server, &leng);
  1236. CString localname=server;
  1237. CDatabase g_masterdb;
  1238. try
  1239. {
  1240. CString strCon;
  1241. if (Global::g_dwDBServerPort != 0)
  1242. {
  1243. if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
  1244. strCon.Format(DB_SW_CONN_WITH_PORT, Global::g_szDBSource, Global::g_dwDBServerPort,_T("master"));
  1245. else
  1246. strCon.Format(DB_SS_CONN_WITH_PORT,Global::g_szDBSource, Global::g_dwDBServerPort, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
  1247. }
  1248. else
  1249. {
  1250. if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
  1251. strCon.Format(DB_SW_CONN_WITHOUT_PORT, Global::g_szDBSource, _T("master"));
  1252. else
  1253. strCon.Format(DB_SS_CONN_WITHOUT_PORT,Global::g_szDBSource, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
  1254. }
  1255. g_masterdb.OpenEx(strCon,CDatabase::noOdbcDialog);
  1256. }
  1257. catch(CDBException * e)
  1258. {
  1259. }
  1260. try
  1261. {
  1262. CTime tm=CTime::GetCurrentTime ();
  1263. CTimeSpan dt(1, 0, 0, 0);
  1264. CTime tm2;
  1265. tm2=tm;
  1266. CString savepath;
  1267. savepath.Format("%s\\%s(sql).bak", savedir, tm2.Format ("%Y%m%d") );
  1268. BOOL bBak=0;
  1269. BOOL bBak2=0;
  1270. if(::PathFileExists (savepath)==0)
  1271. {
  1272. g_masterdb.SetQueryTimeout(600);
  1273. {
  1274. CString sql;
  1275. sql.Format("BACKUP DATABASE dbmsg TO DISK='%s' WITH FORMAT", savepath);
  1276. try
  1277. {
  1278. g_masterdb.ExecuteSQL (sql);
  1279. bBak=1;
  1280. }
  1281. catch(CDBException * e)
  1282. {
  1283. WriteLogin(e->m_strError);
  1284. WriteLogin("备份失败!");
  1285. }
  1286. }
  1287. g_masterdb.SetQueryTimeout(10);
  1288. }
  1289. if(bBak)
  1290. {
  1291. CTimeSpan dt2(15, 0, 0, 0);
  1292. CTimeSpan dt3(365, 0, 0, 0);
  1293. CTime tm3=tm-dt2;
  1294. CTime tm4=tm-dt3;
  1295. while(tm3>tm4)
  1296. {
  1297. savepath.Format("%s\\%s.bak", savedir, tm3.Format ("%Y%m%d") );
  1298. #ifdef SQLSERVER_VERSION
  1299. savepath.Format("%s\\%s(sql).bak", savedir, tm3.Format ("%Y%m%d") );
  1300. #endif
  1301. if(!::PathFileExists (savepath))
  1302. break;
  1303. ::DeleteFile (savepath);
  1304. tm3-=dt;
  1305. }
  1306. }
  1307. }
  1308. catch(...)
  1309. {
  1310. WriteLogin("出错在函数BakData2中");
  1311. }
  1312. g_masterdb.Close ();
  1313. }
  1314. BOOL CLYFZSendMsgApp::InitInstance()
  1315. {
  1316. HANDLE hObject = CreateMutex(NULL,FALSE,_T("CLYFZSendMxxsgAppxiao2"));
  1317. if(GetLastError() == ERROR_ALREADY_EXISTS)
  1318. {
  1319. WriteLogin("已存在进程");
  1320. return false;
  1321. }
  1322. char path[MAX_PATH];
  1323. ::GetModuleFileName (NULL, path, MAX_PATH);
  1324. g_mainpath=path;
  1325. g_mainpath=g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
  1326. m_bTerminate=false;
  1327. m_bRunning=false;
  1328. m_hThread = NULL;
  1329. m_bRunning=true;
  1330. WriteLogin("开始启动");
  1331. AfxEnableControlContainer();
  1332. // Standard initialization
  1333. // If you are not using these features and wish to reduce the size
  1334. // of your final executable, you should remove from the following
  1335. // the specific initialization routines you do not need.
  1336. //g_listctrlfont.CreatePointFont (110, _T("System"));
  1337. g_listctrlfont.CreatePointFont (110, _T("System"));
  1338. #ifdef _AFXDLL
  1339. Enable3dControls(); // Call this when using MFC in a shared DLL
  1340. #else
  1341. Enable3dControlsStatic(); // Call this when linking to MFC statically
  1342. #endif
  1343. SetRegistryKey(_T("LYFZ-MSGSend"));
  1344. // 1.设定使用的短信服务商;
  1345. CString version = _T ("Version 1.0");
  1346. g_bMsgRoad=GetProfileInt (version, "msgroad", 1);
  1347. g_bMsgRoad=1;//吉信通
  1348. g_bMsgRoadtemp=g_bMsgRoad;
  1349. g_bDebug=GetProfileInt (version, "debug", 0);
  1350. if(g_bDebug==0)
  1351. {
  1352. CString autorunpath=g_mainpath+"\\AutoRun2.exe";
  1353. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_SHOWNORMAL);
  1354. CString sendpath=g_mainpath+"\\AutoRun3.exe";
  1355. ShellExecute(NULL, _T("open"), sendpath, NULL, NULL, SW_SHOWNORMAL);
  1356. }
  1357. // 2.连接数据库;
  1358. BOOL bMasterDb=0;
  1359. BOOL bUserDb=0;
  1360. char server[50];
  1361. DWORD leng=50;
  1362. memset(server, 0, 50);
  1363. ::GetComputerName (server, &leng);
  1364. CString localname=server;
  1365. Global::GetIniInfo();
  1366. CDatabase g_masterdb;
  1367. ll: try
  1368. {
  1369. CString strCon;
  1370. if (Global::g_dwDBServerPort != 0)
  1371. {
  1372. if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
  1373. strCon.Format(DB_SW_CONN_WITH_PORT, Global::g_szDBSource, Global::g_dwDBServerPort,_T("master"));
  1374. else
  1375. strCon.Format(DB_SS_CONN_WITH_PORT,Global::g_szDBSource, Global::g_dwDBServerPort, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
  1376. }
  1377. else
  1378. {
  1379. if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
  1380. strCon.Format(DB_SW_CONN_WITHOUT_PORT, Global::g_szDBSource, _T("master"));
  1381. else
  1382. strCon.Format(DB_SS_CONN_WITHOUT_PORT,Global::g_szDBSource, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
  1383. }
  1384. g_masterdb.OpenEx(strCon,CDatabase::noOdbcDialog);
  1385. bMasterDb=1;
  1386. }
  1387. catch(CDBException * e)
  1388. {
  1389. }
  1390. if(bMasterDb==0)
  1391. {
  1392. WriteLogin("sql数据库未启动!");
  1393. ::Sleep (1000);
  1394. goto ll;
  1395. }
  1396. try
  1397. {
  1398. g_db.OpenEx(Global::g_szConnectString,CDatabase::noOdbcDialog);
  1399. bUserDb=1;
  1400. g_curdb=&g_db;
  1401. g_masterdb.Close();
  1402. char server[50];
  1403. DWORD leng=50;
  1404. memset(server, 0, 50);
  1405. ::GetComputerName (server, &leng);
  1406. CString localname=server;
  1407. CString savedir="\\\\"+localname+"\\短信平台备份";
  1408. BakData(savedir);
  1409. savedir=g_mainpath+"\\短信客户资料备份";
  1410. if(!::PathFileExists (savedir))
  1411. ::CreateDirectory (savedir, NULL);
  1412. BakData(savedir);
  1413. }
  1414. catch(CDBException * e)
  1415. {
  1416. WriteLogin("数据库连接失败-"+e->m_strError);
  1417. e->Delete();
  1418. ::Sleep (1000);
  1419. goto ll;
  1420. }
  1421. try
  1422. {
  1423. g_db2.OpenEx(Global::g_szConnectString,CDatabase::noOdbcDialog);
  1424. }
  1425. catch(CDBException * e)
  1426. {
  1427. WriteLogin("数据库连接失败-"+e->m_strError);
  1428. e->Delete();
  1429. ::Sleep (1000);
  1430. goto ll;
  1431. }
  1432. try
  1433. {
  1434. g_db3.OpenEx(Global::g_szConnectString,CDatabase::noOdbcDialog);
  1435. }
  1436. catch(CDBException * e)
  1437. {
  1438. WriteLogin("数据库连接失败-"+e->m_strError);
  1439. e->Delete();
  1440. ::Sleep (1000);
  1441. goto ll;
  1442. }
  1443. g_db.SetQueryTimeout(60*2);
  1444. g_db2.SetQueryTimeout(60*2);
  1445. g_db3.SetQueryTimeout(60*2);
  1446. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  1447. // Register the application's document templates. Document templates
  1448. // serve as the connection between documents, frame windows and views.
  1449. if(g_bMsgRoad==0)
  1450. {
  1451. g_hDll = ::LoadLibrary(g_mainpath+"\\LYFZGateway.dll");
  1452. if (NULL == g_hDll)
  1453. {
  1454. WriteLogin("加载dll失败");
  1455. return 0;
  1456. }
  1457. MongateChangePwd = (FnMongateChangePwd)::GetProcAddress(g_hDll, "MongateChangePwd");
  1458. MongateConnect = (FnMongateConnect)::GetProcAddress(g_hDll, "MongateConnect");
  1459. MongateDisconnect = (FnMongateDisconnect)::GetProcAddress(g_hDll, "MongateDisconnect");
  1460. MongateCsGetSms = (FnMongateCsGetSms)::GetProcAddress(g_hDll, "MongateCsGetSms");
  1461. MongateVasGetSms = (FnMongateVasGetSms)::GetProcAddress(g_hDll, "MongateVasGetSms");
  1462. MongateGetVer = (FnMongateGetVer)::GetProcAddress(g_hDll, "MongateGetVer");
  1463. MongateTestConn = (FnMongateTestConn)::GetProcAddress(g_hDll, "MongateTestConn");
  1464. MongateQueryBalance = (FnMongateQueryBalance)::GetProcAddress(g_hDll, "MongateQueryBalance");
  1465. MongateVasSendSms = (FnMongateVasSendSms)::GetProcAddress(g_hDll, "MongateVasSendSms");
  1466. MongateSendSms = (FnMongateSendSms)::GetProcAddress(g_hDll, "MongateSendSms");
  1467. MongateQueryUsed = (FnMongateQueryUsed)::GetProcAddress(g_hDll, "MongateQueryUsed");
  1468. MongateCsSendSms = (FnMongateCsSendSms)::GetProcAddress(g_hDll, "MongateCsSendSms");
  1469. MongateCsGetStatusReport = (FnMongateCsGetStatusReport)::GetProcAddress(g_hDll, "MongateCsGetStatusReport");
  1470. MongateConnectSocks4Proxy = (FnMongateConnectSocks4Proxy)::GetProcAddress(g_hDll, "MongateConnectSocks4Proxy");
  1471. MongateConnectSocks5Proxy = (FnMongateConnectSocks5Proxy)::GetProcAddress(g_hDll, "MongateConnectSocks5Proxy");
  1472. MongateConnectHttpProxy = (FnMongateConnectHttpProxy)::GetProcAddress(g_hDll, "MongateConnectHttpProxy");
  1473. MongateTestMsgEx = (FnMongateTestMsgEx)::GetProcAddress(g_hDll, "MongateTestMsgEx");
  1474. MongateTestMsgExHttp =(FnMongateTestMsgExHttp)::GetProcAddress(g_hDll, "MongateTestMsgExHttp");
  1475. MongateQueryBalanceHttp = (FnMongateQueryBalance)::GetProcAddress(g_hDll, "MongateQueryBalanceHttp");
  1476. MongateQueryUsedHttp = (FnMongateQueryUsed)::GetProcAddress(g_hDll, "MongateQueryUsedHttp");
  1477. MongateConnectHttp = (FnMongateConnect)::GetProcAddress(g_hDll, "MongateConnectHttp");
  1478. MongateCsSendSmsHttp = (FnMongateCsSendSms)::GetProcAddress(g_hDll, "MongateCsSendSmsHttp");
  1479. MongateCsGetSmsHttp = (FnMongateCsGetSmsHttp)::GetProcAddress(g_hDll, "MongateCsGetSmsHttp");
  1480. MongateCsGetStatusReportHttp = (FnMongateCsGetStatusReport)::GetProcAddress(g_hDll, "MongateCsGetStatusReportHttp");
  1481. MongateChangePwdHttp = (FnMongateChangePwd)::GetProcAddress(g_hDll, "MongateChangePwdHttp");
  1482. MongateTestConnHttp = (FnMongateTestConnHttp)::GetProcAddress(g_hDll, "MongateTestConnHttp");
  1483. MongateConnectHttpProxy = (FnMongateConnectHttpProxy)::GetProcAddress(g_hDll, "MongateConnectHttpProxy");
  1484. MongateCsSPSendSmsNew = (FnMongateCsSPSendSmsNew)::GetProcAddress(g_hDll, "MongateCsSPSendSmsNew");
  1485. }
  1486. g_titlefont.CreatePointFont (160, _T("宋体"));
  1487. CMultiDocTemplate* pDocTemplate;
  1488. pDocTemplate = new CMultiDocTemplate(
  1489. IDR_MAINFRAME,
  1490. NULL,
  1491. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  1492. RUNTIME_CLASS(CLYFZSendMsgView));
  1493. AddDocTemplate(pDocTemplate);
  1494. // create main MDI Frame window
  1495. CMainFrame* pMainFrame = new CMainFrame;
  1496. if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  1497. {
  1498. WriteLogin("窗口初始化失败");
  1499. return FALSE;
  1500. }
  1501. m_pMainWnd = pMainFrame;
  1502. if(g_bMsgRoad==0)
  1503. m_pMainWnd->SetWindowText ("利亚方舟短信发送管理系统--南海短信");
  1504. else if(g_bMsgRoad==1)
  1505. m_pMainWnd->SetWindowText ("利亚方舟短信发送管理系统--吉信通");
  1506. else if(g_bMsgRoad==2)
  1507. m_pMainWnd->SetWindowText ("利亚方舟短信发送管理系统--商务通");
  1508. m_pMainWnd->UpdateWindow();
  1509. return TRUE;
  1510. }
  1511. /////////////////////////////////////////////////////////////////////////////
  1512. // CAboutDlg dialog used for App About
  1513. class CAboutDlg : public CDialog
  1514. {
  1515. public:
  1516. CAboutDlg();
  1517. // Dialog Data
  1518. //{{AFX_DATA(CAboutDlg)
  1519. enum { IDD = IDD_ABOUTBOX };
  1520. //}}AFX_DATA
  1521. // ClassWizard generated virtual function overrides
  1522. //{{AFX_VIRTUAL(CAboutDlg)
  1523. protected:
  1524. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  1525. //}}AFX_VIRTUAL
  1526. // Implementation
  1527. protected:
  1528. //{{AFX_MSG(CAboutDlg)
  1529. // No message handlers
  1530. //}}AFX_MSG
  1531. DECLARE_MESSAGE_MAP()
  1532. };
  1533. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  1534. {
  1535. //{{AFX_DATA_INIT(CAboutDlg)
  1536. //}}AFX_DATA_INIT
  1537. }
  1538. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  1539. {
  1540. CDialog::DoDataExchange(pDX);
  1541. //{{AFX_DATA_MAP(CAboutDlg)
  1542. //}}AFX_DATA_MAP
  1543. }
  1544. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  1545. //{{AFX_MSG_MAP(CAboutDlg)
  1546. // No message handlers
  1547. //}}AFX_MSG_MAP
  1548. END_MESSAGE_MAP()
  1549. // App command to run the dialog
  1550. void CLYFZSendMsgApp::OnAppAbout()
  1551. {
  1552. CAboutDlg aboutDlg;
  1553. aboutDlg.DoModal();
  1554. }
  1555. /////////////////////////////////////////////////////////////////////////////
  1556. // CLYFZSendMsgApp message handlers
  1557. CString newGUID()
  1558. {
  1559. CString str;
  1560. GUID guid;
  1561. CoInitialize(NULL);
  1562. if (S_OK == ::CoCreateGuid(&guid))
  1563. {
  1564. str.Format (
  1565. "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  1566. guid.Data1,
  1567. guid.Data2,
  1568. guid.Data3,
  1569. guid.Data4[0], guid.Data4[1],
  1570. guid.Data4[2], guid.Data4[3],
  1571. guid.Data4[4], guid.Data4[5],
  1572. guid.Data4[6], guid.Data4[7]);
  1573. }
  1574. CoUninitialize();
  1575. return str.Left (28);
  1576. }
  1577. void ConvertToPrice(CString &str)
  1578. {
  1579. if(str.Find ('.')==-1)return;
  1580. str.TrimRight ('0');
  1581. str.TrimRight ('.');
  1582. }
  1583. BOOL IsHasRights(int pos)
  1584. {return 1;
  1585. if(g_user.rights.GetLength ()>pos)
  1586. {
  1587. BOOL ret=atoi(g_user.rights.Mid (pos,1));
  1588. if(ret==0)AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  1589. return ret;
  1590. }
  1591. AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  1592. return 0;
  1593. }
  1594. BOOL IsHasRights2(int pos)
  1595. {return 1;
  1596. if(g_user.rights.GetLength ()>pos)
  1597. {
  1598. BOOL ret=atoi(g_user.rights.Mid (pos,1));
  1599. return ret;
  1600. }
  1601. return 0;
  1602. }
  1603. BOOL IsHasRightsnew(int pos)
  1604. {
  1605. if(g_user.rights.GetLength ()>pos)
  1606. {
  1607. BOOL ret=atoi(g_user.rights.Mid (pos,1));
  1608. if(ret==0)AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  1609. return ret;
  1610. }
  1611. AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  1612. return 0;
  1613. }
  1614. BOOL IsHasRights2new(int pos)
  1615. {
  1616. if(g_user.rights.GetLength ()>pos)
  1617. {
  1618. BOOL ret=atoi(g_user.rights.Mid (pos,1));
  1619. return ret;
  1620. }
  1621. return 0;
  1622. }
  1623. int CLYFZSendMsgApp::ExitInstance()
  1624. {
  1625. // TODO: Add your specialized code here and/or call the base class
  1626. if (m_hsock != 0)
  1627. MongateDisconnect(m_hsock);
  1628. if(g_hDll)
  1629. ::FreeLibrary (g_hDll);
  1630. try
  1631. {
  1632. g_db.Close ();
  1633. return CWinApp::ExitInstance();
  1634. }
  1635. catch(...)
  1636. {
  1637. }
  1638. //g_tMainCtrl.StopServer();
  1639. //Transport_UnInit();
  1640. return CWinApp::ExitInstance();
  1641. }
  1642. void LoadImageFromBuf(Bitmap **img, BYTE *pData, DWORD leng)
  1643. {
  1644. try
  1645. {
  1646. if(pData==NULL)return;
  1647. if(*img)delete *img;
  1648. *img=NULL;
  1649. // Allocate global memory on which to create stream
  1650. HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
  1651. if(m_hMem==NULL)return;
  1652. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  1653. memcpy(pmem,pData,leng);
  1654. IStream* pstm;
  1655. CreateStreamOnHGlobal(m_hMem,TRUE,&pstm);
  1656. // load from stream
  1657. *img=Gdiplus::Bitmap::FromStream(pstm);
  1658. // free/release stuff
  1659. GlobalUnlock(m_hMem);
  1660. pstm->Release();
  1661. }
  1662. catch(...)
  1663. {
  1664. }
  1665. }
  1666. void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)
  1667. {
  1668. try
  1669. {
  1670. if(pData==NULL)return;
  1671. if(*img)delete *img;
  1672. *img=NULL;
  1673. // Allocate global memory on which to create stream
  1674. HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
  1675. if(m_hMem==NULL)return;
  1676. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  1677. memcpy(pmem,pData,leng);
  1678. IStream* pstm;
  1679. CreateStreamOnHGlobal(m_hMem,TRUE,&pstm);
  1680. // load from stream
  1681. *img=Gdiplus::Image::FromStream(pstm);
  1682. // free/release stuff
  1683. GlobalUnlock(m_hMem);
  1684. pstm->Release();
  1685. }
  1686. catch(...)
  1687. {
  1688. }
  1689. }
  1690. void LoadImageFromBuf(Image **img, CString path)
  1691. {
  1692. try
  1693. {
  1694. CFile fp;
  1695. if(fp.Open (path, CFile::modeRead))
  1696. {
  1697. DWORD leng=fp.GetLength ();
  1698. BYTE *pData=new BYTE[leng];
  1699. fp.Read (pData, leng);
  1700. fp.Close ();
  1701. LoadImageFromBuf(img, pData, leng);
  1702. delete []pData;
  1703. }
  1704. }
  1705. catch(...)
  1706. {
  1707. }
  1708. }
  1709. void LoadImageFromBuf(Bitmap **img, CString path)
  1710. {
  1711. try
  1712. {
  1713. CFile fp;
  1714. if(fp.Open (path, CFile::modeRead))
  1715. {
  1716. DWORD leng=fp.GetLength ();
  1717. BYTE *pData=new BYTE[leng];
  1718. fp.Read (pData, leng);
  1719. fp.Close ();
  1720. LoadImageFromBuf(img, pData, leng);
  1721. delete []pData;
  1722. }
  1723. }
  1724. catch(...)
  1725. {
  1726. }
  1727. }
  1728. int GetType(CString str)
  1729. {
  1730. BOOL bDigit=1;
  1731. BOOL bAlpha=1;
  1732. for(int i=0; i<str.GetLength (); i++)
  1733. {
  1734. // if(!::isdigit (str.GetAt (i)))
  1735. if(! ((str.GetAt (i)<=0 && str.GetAt (i)>=9) ))
  1736. bDigit=0;
  1737. if(! ((str.GetAt (i)<='z' && str.GetAt (i)>='a') || (str.GetAt (i)<='Z' && str.GetAt (i)>='A')))
  1738. //else if(!::isalpha ( ((unsigned char)str.GetAt (i))))
  1739. bAlpha=0;
  1740. if(bDigit==0 && bAlpha==0)return 0;
  1741. }
  1742. if(bDigit)
  1743. {
  1744. return 1;
  1745. }
  1746. else if(bAlpha)
  1747. {
  1748. return 2;
  1749. }
  1750. else
  1751. return 0;
  1752. }
  1753. void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
  1754. {
  1755. try
  1756. {
  1757. HGLOBAL hGlobal = NULL;
  1758. HRSRC hSource = NULL;
  1759. LPVOID lpVoid = NULL;
  1760. int nSize = 0;
  1761. BOOL bResult=FALSE;
  1762. hSource = FindResource(NULL, lpszResourceName, ResourceType);
  1763. if(hSource == NULL)return;
  1764. hGlobal = LoadResource(NULL, hSource);
  1765. if(hGlobal == NULL)return;
  1766. lpVoid = LockResource(hGlobal);
  1767. if(lpVoid == NULL)return;
  1768. nSize = (UINT)SizeofResource(NULL, hSource);
  1769. LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
  1770. UnlockResource(hGlobal); // 16Bit Windows Needs This
  1771. FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
  1772. }
  1773. catch(...)
  1774. {
  1775. }
  1776. }
  1777. CString FilterBZ(CString &bz)
  1778. {
  1779. bz.Replace ("'", "");
  1780. /* int i=bz.GetLength ()-1;
  1781. char c;
  1782. for(;i>=0;i--)
  1783. {
  1784. c=bz.GetAt (i);
  1785. if(c<32)// && c!=10 && c!=13)
  1786. bz.Delete (i);
  1787. }*/
  1788. if(bz.GetLength ()>1023)
  1789. {
  1790. AfxMessageBox("文字太长, 字符串将被截取!", MB_ICONSTOP);
  1791. bz=bz.Left (1023);
  1792. }
  1793. return bz;
  1794. }
  1795. BOOL GIsHalfHZ(const CString &str)
  1796. {
  1797. int len=str.GetLength();
  1798. BOOL IsHalf=FALSE;
  1799. for(int i=0;i<len;i++)
  1800. {
  1801. if(str.GetAt(i) < 0) IsHalf=!IsHalf;
  1802. }
  1803. return IsHalf;
  1804. }
  1805. void RectFitDes(int width, int height, CRect &rc)
  1806. {
  1807. try
  1808. {
  1809. if(width==0 || height==0)return;
  1810. float fscale=(float)width/(float)height;
  1811. float rcscale=((float)rc.Width ())/((float)rc.Height ());
  1812. int rcwid=rc.Width ();
  1813. int rchei=rc.Height ();
  1814. int dt=0;
  1815. if(rcscale<fscale)
  1816. {
  1817. dt=(rchei-rcwid/fscale)/2;
  1818. rc.top+=dt;
  1819. rc.bottom-=dt;
  1820. }
  1821. else
  1822. {
  1823. dt=(rcwid-rchei*fscale)/2;
  1824. rc.left +=dt;
  1825. rc.right-=dt;
  1826. }
  1827. }
  1828. catch(...)
  1829. {
  1830. }
  1831. }
  1832. int GetPos(DWORD leng)
  1833. {
  1834. if(g_lengarray.GetSize()==0)
  1835. {
  1836. g_sendhead.bsql=0;
  1837. g_sendhead.code[0]=105;
  1838. g_sendhead.tabcount=1;
  1839. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return -1;
  1840. DWORD leng;
  1841. DWORD readbytes=0;
  1842. memcpy(&leng, g_pData+readbytes, sizeof(DWORD));
  1843. readbytes+=sizeof(DWORD);
  1844. {
  1845. CMemFile memfile;
  1846. memfile.Attach (g_pData+readbytes, leng);
  1847. readbytes+=leng;
  1848. CArchive ar(&memfile, CArchive::load);
  1849. g_lengarray.Serialize (ar);
  1850. ar.Close();
  1851. memfile.Detach ();
  1852. }
  1853. memcpy(&leng, g_pData+readbytes, sizeof(DWORD));
  1854. readbytes+=sizeof(DWORD);
  1855. {
  1856. CMemFile memfile;
  1857. memfile.Attach (g_pData+readbytes, leng);
  1858. readbytes+=leng;
  1859. CArchive ar(&memfile, CArchive::load);
  1860. g_btnlengarray.Serialize (ar);
  1861. ar.Close();
  1862. memfile.Detach ();
  1863. }
  1864. memcpy(&leng, g_pData+readbytes, sizeof(DWORD));
  1865. readbytes+=sizeof(DWORD);
  1866. int count=leng/sizeof(RESDATA2);
  1867. for(int i=0; i<count; i++)
  1868. {
  1869. BYTE *pData=new BYTE[sizeof(RESDATA2)];
  1870. memcpy(pData, g_pData+readbytes, sizeof(RESDATA2));
  1871. readbytes+=sizeof(RESDATA2);
  1872. g_pointerarray.Add(pData);
  1873. /* RESDATA2 *pRes=(RESDATA2*)pData;
  1874. CString str;
  1875. str.Format ("%d", pRes->nPicBmpCount [0]);
  1876. AfxMessageBox(str);
  1877. str.Format ("%d", pRes->nPicBmpCount [1]);
  1878. AfxMessageBox(str);
  1879. str.Format ("%d", pRes->nPicBmpCount [2]);
  1880. AfxMessageBox(str);
  1881. str.Format ("%d", pRes->nPicBmpCount [3]);
  1882. AfxMessageBox(str);
  1883. str.Format ("%d", pRes->nPicBmpCount [4]);
  1884. AfxMessageBox(str);
  1885. str.Format ("%d", pRes->nPicBmpCount [5]);
  1886. AfxMessageBox(str);*/
  1887. }
  1888. }
  1889. for(int i=0; i<g_lengarray.GetSize (); i++)
  1890. {
  1891. if(leng==g_lengarray.ElementAt (i))
  1892. {
  1893. return i;
  1894. }
  1895. }
  1896. return -1;
  1897. }
  1898. extern RESDATA2 g_resdata2;
  1899. BOOL LoadLia(CString path, BYTE **pData, BYTE **pDataBegin, Image **pBk, HWND hwnd)
  1900. {
  1901. return 0;
  1902. }
  1903. BOOL CheckDateOK(CString str)
  1904. {
  1905. if(str.IsEmpty ())return 1;
  1906. CString tip;
  1907. int i;
  1908. CString demo=CTime::GetCurrentTime ().Format ("%Y-%m-%d");
  1909. if(str.GetLength ()!=demo.GetLength ())
  1910. goto ll;
  1911. //2009-01-01
  1912. if(str.GetAt (4)!='-')
  1913. goto ll;
  1914. if(str.GetAt (7)!='-')
  1915. goto ll;
  1916. for( i=0; i<str.GetLength (); i++)
  1917. {
  1918. if(i==4 || i==7)continue;
  1919. if(str.GetAt (i)<'0' || str.GetAt (i)>'9')
  1920. goto ll;
  1921. }
  1922. return 1;
  1923. ll:
  1924. tip.Format ("日期:%s格式错误!\r\n样板:%s", str, demo);
  1925. AfxMessageBox(tip, MB_ICONSTOP);
  1926. return 0;
  1927. }
  1928. int GetOrientation(Image *image)
  1929. {
  1930. if(image )
  1931. {
  1932. UINT totalBufferSize;
  1933. UINT numProperties;
  1934. image->GetPropertySize(&totalBufferSize, &numProperties);
  1935. // Allocate the buffer that will receive the property items.
  1936. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  1937. // Fill the buffer.
  1938. image->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  1939. // Print the id data member of each property item.
  1940. for(UINT j = 0; j < numProperties; ++j)
  1941. {
  1942. if(PropertyTagOrientation==pAllItems[j].id)
  1943. {
  1944. short* ptrLong = (short*)(pAllItems[j].value);
  1945. int ret=(int)*ptrLong;
  1946. free(pAllItems);
  1947. return ret;
  1948. //str.Format("%d", *ptrLong);
  1949. //MessageBox(str);
  1950. }
  1951. }
  1952. free(pAllItems);
  1953. }
  1954. return 1;
  1955. }
  1956. int CLYFZSendMsgApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
  1957. {
  1958. // TODO: Add your specialized code here and/or call the base class
  1959. return CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
  1960. }
  1961. void WriteLogin(CString str)
  1962. {
  1963. CStdioFile fp;
  1964. CString path=g_mainpath+"\\短信平台日志.txt";
  1965. if(::PathFileExists (path))
  1966. {
  1967. fp.Open (path, CFile::modeWrite);
  1968. int length=fp.GetLength ();
  1969. if(length>1024*1024)
  1970. {
  1971. fp.Close ();
  1972. ::DeleteFile (path);
  1973. return;
  1974. }
  1975. fp.SeekToEnd ();
  1976. }
  1977. else
  1978. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  1979. fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
  1980. fp.Close ();
  1981. }
  1982. void WriteLogin2(CString str)
  1983. {
  1984. CStdioFile fp;
  1985. CString path=g_mainpath+"\\短信平台日志2.txt";
  1986. if(::PathFileExists (path))
  1987. {
  1988. fp.Open (path, CFile::modeWrite);
  1989. int length=fp.GetLength ();
  1990. if(length>1024*1024)
  1991. {
  1992. fp.Close ();
  1993. ::DeleteFile (path);
  1994. return;
  1995. }
  1996. fp.SeekToEnd ();
  1997. }
  1998. else
  1999. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  2000. fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
  2001. fp.Close ();
  2002. }
  2003. BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword)
  2004. {
  2005. try
  2006. {
  2007. HCRYPTPROV hCryptProv;
  2008. HCRYPTKEY hKey;
  2009. HCRYPTHASH hHash;
  2010. PBYTE pbBuffer;
  2011. DWORD dwBlockLen;
  2012. DWORD dwBufferLen;
  2013. DWORD dwCount;
  2014. //以下获得一个CSP句柄
  2015. if(CryptAcquireContext(
  2016. &hCryptProv,
  2017. NULL, //NULL表示使用默认密钥容器,默认密钥容器名为用户登陆名
  2018. NULL,
  2019. PROV_RSA_FULL,
  2020. 0))
  2021. {
  2022. printf("A cryptographic provider has been acquired. \n");
  2023. }
  2024. else//密钥容器不存在
  2025. {
  2026. if(CryptAcquireContext(
  2027. &hCryptProv,
  2028. NULL,
  2029. NULL,
  2030. PROV_RSA_FULL,
  2031. CRYPT_NEWKEYSET))//创建密钥容器
  2032. {
  2033. //创建密钥容器成功,并得到CSP句柄
  2034. printf("A new key container has been created.\n");
  2035. }
  2036. else
  2037. {
  2038. return 0;
  2039. }
  2040. }
  2041. //--------------------------------------------------------------------
  2042. // 创建一个会话密钥(session key)
  2043. // 会话密钥也叫对称密钥,用于对称加密算法。
  2044. // (注: 一个Session是指从调用函数CryptAcquireContext到调用函数
  2045. // CryptReleaseContext 期间的阶段。)
  2046. //--------------------------------------------------------------------
  2047. // Create a hash object.
  2048. if(CryptCreateHash(
  2049. hCryptProv,
  2050. CALG_MD5,
  2051. 0,
  2052. 0,
  2053. &hHash))
  2054. {
  2055. printf("A hash object has been created. \n");
  2056. }
  2057. else
  2058. {
  2059. return 0;
  2060. }
  2061. //--------------------------------------------------------------------
  2062. // 用输入的密码产生一个散列
  2063. if(CryptHashData(
  2064. hHash,
  2065. (BYTE *)szPassword,
  2066. strlen(szPassword),
  2067. 0))
  2068. {
  2069. printf("The password has been added to the hash. \n");
  2070. }
  2071. else
  2072. {
  2073. return 0;
  2074. }
  2075. //--------------------------------------------------------------------
  2076. // 通过散列生成会话密钥(session key)
  2077. if(CryptDeriveKey(
  2078. hCryptProv,
  2079. ENCRYPT_ALGORITHM,
  2080. hHash,
  2081. KEYLENGTH,
  2082. &hKey))
  2083. {
  2084. printf("An encryption key is derived from the password hash. \n");
  2085. }
  2086. else
  2087. {
  2088. return 0;
  2089. }
  2090. //--------------------------------------------------------------------
  2091. // Destroy the hash object.
  2092. CryptDestroyHash(hHash);
  2093. hHash = NULL;
  2094. //--------------------------------------------------------------------
  2095. // The session key is now ready.
  2096. //--------------------------------------------------------------------
  2097. // 因为加密算法是按ENCRYPT_BLOCK_SIZE 大小的块加密的,所以被加密的
  2098. // 数据长度必须是ENCRYPT_BLOCK_SIZE 的整数倍。下面计算一次加密的
  2099. // 数据长度。
  2100. dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
  2101. //--------------------------------------------------------------------
  2102. // Determine the block size. If a block cipher is used,
  2103. // it must have room for an extra block.
  2104. if(ENCRYPT_BLOCK_SIZE > 1)
  2105. dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
  2106. else
  2107. dwBufferLen = dwBlockLen;
  2108. dwCount=dwBufferLen;
  2109. //--------------------------------------------------------------------
  2110. // In a do loop, encrypt the source file and write to the source file.
  2111. int count;
  2112. // if(leng%dwBlockLen==0)
  2113. count=leng/dwBufferLen;
  2114. // else
  2115. // count=leng/dwBlockLen+1;
  2116. int i;
  2117. for( i=0; i<count; i++)
  2118. {
  2119. pbBuffer=buffer+i*dwBufferLen;
  2120. // 加密数据
  2121. if(!CryptEncrypt(
  2122. hKey, //密钥
  2123. 0, //如果数据同时进行散列和加密,这里传入一个散列对象
  2124. 0, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE.
  2125. //这里通过判断是否到文件尾来决定是否为最后一块。
  2126. 0, //保留
  2127. pbBuffer, //输入被加密数据,输出加密后的数据
  2128. &dwCount, //输入被加密数据实际长度,输出加密后数据长度
  2129. dwBufferLen)) //pbBuffer的大小。
  2130. {
  2131. return 0;
  2132. }
  2133. }
  2134. if(leng%dwBlockLen)
  2135. {
  2136. pbBuffer=buffer+i*dwBufferLen;
  2137. dwCount=leng-i*dwBufferLen;
  2138. if(!CryptEncrypt(
  2139. hKey, //密钥
  2140. 0, //如果数据同时进行散列和加密,这里传入一个散列对象
  2141. TRUE, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE.
  2142. //这里通过判断是否到文件尾来决定是否为最后一块。
  2143. 0, //保留
  2144. pbBuffer, //输入被加密数据,输出加密后的数据
  2145. &dwCount, //输入被加密数据实际长度,输出加密后数据长度
  2146. dwBufferLen)) //pbBuffer的大小。
  2147. {
  2148. return 0;
  2149. }
  2150. }
  2151. //--------------------------------------------------------------------
  2152. // Destroy session key.
  2153. if(hKey)
  2154. CryptDestroyKey(hKey);
  2155. //--------------------------------------------------------------------
  2156. // Destroy hash object.
  2157. if(hHash)
  2158. CryptDestroyHash(hHash);
  2159. //--------------------------------------------------------------------
  2160. // Release provider handle.
  2161. if(hCryptProv)
  2162. CryptReleaseContext(hCryptProv, 0);
  2163. return(TRUE);
  2164. }
  2165. catch(...)
  2166. {
  2167. }
  2168. }
  2169. BOOL CLYFZSendMsgApp::TerminateThread()
  2170. {
  2171. try
  2172. {
  2173. if ( !m_bRunning )
  2174. return TRUE;
  2175. m_bTerminate=true;
  2176. for(int i=0; i<10; i++)
  2177. {
  2178. if(m_bRunning==0)break;
  2179. ::Sleep (1000);
  2180. }
  2181. if(m_hThread)
  2182. {
  2183. ::TerminateThread (m_hThread, 0);
  2184. ::CloseHandle(m_hThread);
  2185. }
  2186. /* for( ; ; )
  2187. {
  2188. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  2189. break;
  2190. MSG msg;
  2191. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  2192. {
  2193. if (!AfxGetApp()->PumpMessage())
  2194. break;
  2195. }
  2196. }
  2197. ::CloseHandle(m_hThread); */
  2198. m_bRunning=false;
  2199. return TRUE;
  2200. }
  2201. catch(...)
  2202. {
  2203. WriteLogin("出错在函数TerminateThread中");
  2204. }
  2205. try
  2206. {
  2207. if ( !m_bRunning2 )
  2208. return TRUE;
  2209. m_bTerminate2=true;
  2210. for(int i=0; i<10; i++)
  2211. {
  2212. if(m_bRunning2==0)break;
  2213. ::Sleep (1000);
  2214. }
  2215. if(m_hThread2)
  2216. {
  2217. ::TerminateThread (m_hThread2, 0);
  2218. ::CloseHandle(m_hThread2);
  2219. }
  2220. m_bRunning2=false;
  2221. return TRUE;
  2222. }
  2223. catch(...)
  2224. {
  2225. WriteLogin("出错在函数TerminateThread2中");
  2226. }
  2227. }
  2228. //把utf8转成unicode,再转成cstring
  2229. void ConvertUTF8ToANSI(char* strUTF8,CString &strANSI) //
  2230. {
  2231. int nLen = ::MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,(LPCTSTR)strUTF8,-1,NULL,0); //返回需要的unicode长度
  2232. WCHAR * wszANSI = new WCHAR[nLen+1];
  2233. memset(wszANSI, 0, nLen * 2 + 2);
  2234. nLen = MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUTF8, -1, wszANSI, nLen); //把utf8转成unicode
  2235. nLen = WideCharToMultiByte(CP_ACP, 0, wszANSI, -1, NULL, 0, NULL, NULL); //得到要的ansi长度
  2236. char *szANSI=new char[nLen + 1];
  2237. memset(szANSI, 0, nLen + 1);
  2238. WideCharToMultiByte (CP_ACP, 0, wszANSI, -1, szANSI, nLen, NULL,NULL); //把unicode转成ansi
  2239. strANSI = szANSI;
  2240. delete wszANSI;
  2241. delete szANSI;
  2242. }
  2243. BOOL g_bReceiveRoad2=1;
  2244. CString GetReceiveMsg()
  2245. {
  2246. CHttpClient conn;
  2247. CString value="http://121.52.221.108/send/readxmlsmsconfig.aspx?name=lyfzrj&pwd=lyfzrj123";
  2248. if(g_bReceiveRoad2)
  2249. value="http://121.52.221.108/send/readxmlsmsconfig.aspx?name=lyfzrj1&pwd=lyfz1234";
  2250. return conn.doGet(value);
  2251. }
  2252. BOOL IsExistReceiveMsg(CString id)
  2253. {
  2254. CRecordset myset(&g_db3);
  2255. CString sql="select count(*) as cot from receivemsg where id='"+id+"'";
  2256. myset.Open (CRecordset::forwardOnly, sql);
  2257. myset.GetFieldValue ("cot", sql);
  2258. myset.Close();
  2259. return atoi(sql);
  2260. }
  2261. void DelExistReceiveMsg(CString id)
  2262. {
  2263. CHttpClient conn;
  2264. CString value="http://121.52.221.108/send/configupsms.aspx?name=lyfzrj&pwd=lyfzrj123&ids="+id;
  2265. if(g_bReceiveRoad2)
  2266. value="http://121.52.221.108/send/configupsms.aspx?name=lyfzrj1&pwd=lyfz1234&ids="+id;
  2267. conn.doGet(value);
  2268. }
  2269. // 接收短信内容线程;
  2270. unsigned __stdcall ReceiveMsgThread(LPVOID lpParam)
  2271. {
  2272. CLYFZSendMsgApp *pDlg=(CLYFZSendMsgApp*)lpParam;
  2273. try
  2274. {
  2275. CString sql,str,id,phone,content,datetime,delid,strbak;
  2276. str="&";
  2277. int leng=str.GetLength ();
  2278. str="2013-04-12 11:35:28";
  2279. int leng2=str.GetLength ();
  2280. int pos;
  2281. while(1)
  2282. {
  2283. // WriteLogin("查回复!");
  2284. CRecordset myset(&g_db3);
  2285. myset.Open (CRecordset::forwardOnly, "SELECT phone FROM [dbmsg].[dbo].[receivemsg] where account is null");
  2286. while(!myset.IsEOF())
  2287. {
  2288. myset.GetFieldValue ("phone", str);
  2289. sql.Format("update [receivemsg] set account=(select top 1 account from sendreg where [phones] like '%s' order by [timestamp2] desc\
  2290. ) where [phone]='%s'", "%"+str+"%", str);
  2291. MyExecuteSQL(&g_db3, sql);
  2292. sql.Format("update [receivemsg] set account='未找到' where [phone]='%s' and account is null", str);
  2293. MyExecuteSQL(&g_db3, sql);
  2294. myset.MoveNext();
  2295. }
  2296. myset.Close();
  2297. str="";
  2298. g_bReceiveRoad2=!g_bReceiveRoad2;
  2299. str=GetReceiveMsg();
  2300. if(str.Find("||||")==-1)
  2301. {
  2302. WriteLogin("回复返回");
  2303. ::Sleep (10000);
  2304. continue;
  2305. }
  2306. str.TrimRight ();
  2307. CString finder="||||";
  2308. if(str.Right (finder.GetLength ())==finder)str=str.Left (str.GetLength ()-finder.GetLength ());
  2309. CStringArray strarray;
  2310. pos=str.Find (finder);
  2311. if(pos==-1)
  2312. {
  2313. strarray.Add (str);
  2314. }
  2315. else
  2316. {
  2317. while(pos!=-1)
  2318. {
  2319. strarray.Add ( str.Left (pos));
  2320. str=str.Right (str.GetLength ()-pos-finder.GetLength ());
  2321. pos=str.Find (finder);
  2322. }
  2323. strarray.Add (str);
  2324. }
  2325. delid="";
  2326. for(int i=0; i<strarray.GetSize (); i++)
  2327. {
  2328. if(delid!="")
  2329. {
  2330. if(delid.Right (1)==";")
  2331. delid=delid.Left (delid.GetLength ()-1);
  2332. DelExistReceiveMsg(delid);delid="";
  2333. }
  2334. str=strarray.ElementAt (i);
  2335. str.Replace("&sequeid=12345", "");
  2336. strbak=str;
  2337. // WriteLogin("开始:"+str);
  2338. pos=str.Find ("&");
  2339. if(pos==-1)
  2340. {
  2341. ::Sleep (5000);WriteLogin("回复返回2:"+strbak);
  2342. continue;
  2343. }
  2344. id=str.Left (pos);id.TrimLeft ("id=");
  2345. id.TrimLeft ();
  2346. delid+=id+";";
  2347. str=str.Right (str.GetLength ()-pos-leng);
  2348. pos=str.Find ("&");
  2349. if(pos==-1)
  2350. {
  2351. ::Sleep (5000);WriteLogin("回复返回3:"+strbak);
  2352. continue;
  2353. }
  2354. str=str.Right (str.GetLength ()-pos-leng);
  2355. pos=str.Find ("&");
  2356. if(pos==-1)
  2357. {
  2358. ::Sleep (5000);WriteLogin("回复返回4:"+strbak);
  2359. continue;
  2360. }
  2361. phone=str.Left (pos);phone.TrimLeft ("src=");
  2362. str=str.Right (str.GetLength ()-pos-leng);
  2363. pos=str.Find ("&");
  2364. if(pos==-1)
  2365. {
  2366. ::Sleep (5000);WriteLogin("回复返回5:"+strbak);
  2367. continue;
  2368. }
  2369. content=str.Left (pos);content.TrimLeft ("msg=");
  2370. str=str.Right (str.GetLength ()-pos-leng);
  2371. pos=str.ReverseFind ('&');
  2372. if(pos==-1)
  2373. {
  2374. ::Sleep (5000);WriteLogin("回复返回6:"+strbak);
  2375. continue;
  2376. }
  2377. datetime=str.Right (str.GetLength ()-pos-leng);datetime.TrimLeft ("time=");
  2378. datetime.TrimRight ();
  2379. if(datetime.GetLength ()!=leng2)
  2380. { WriteLogin("回复返回7"+datetime+strbak);
  2381. ::Sleep (5000);
  2382. continue;
  2383. }
  2384. if(IsExistReceiveMsg(id))
  2385. {
  2386. WriteLogin("回复返回8:"+strbak);
  2387. if(delid!="")
  2388. {
  2389. if(delid.Right (1)==";")
  2390. delid=delid.Left (delid.GetLength ()-1);
  2391. DelExistReceiveMsg(delid);delid="";
  2392. }
  2393. continue;
  2394. }
  2395. content.Replace ("'", "");
  2396. content.Replace ("^", "");
  2397. str="insert into receivemsg([id],[phone],[content],[datetime]) values('"+id+"','"+phone+"','"+content+"','"+datetime+"')";
  2398. if(MyExecuteSQL(&g_db3, str)==0)
  2399. {
  2400. WriteLogin("保存回复记录失败!");
  2401. ::Sleep (5000);
  2402. continue;
  2403. }::Sleep (5000);
  2404. if(delid!="")
  2405. {
  2406. if(delid.Right (1)==";")
  2407. delid=delid.Left (delid.GetLength ()-1);
  2408. DelExistReceiveMsg(delid);delid="";
  2409. }
  2410. }
  2411. //删除
  2412. if(delid!="")
  2413. {
  2414. if(delid.Right (1)==";")
  2415. delid=delid.Left (delid.GetLength ()-1);
  2416. DelExistReceiveMsg(delid);
  2417. }
  2418. ::Sleep (5000);
  2419. }
  2420. }
  2421. catch(...)
  2422. {
  2423. }
  2424. pDlg->m_bRunning2=false;
  2425. pDlg->m_bTerminate2=false;
  2426. _endthreadex( 0 ); pDlg->m_hThread2=NULL;
  2427. WriteLogin("回复线程关闭!");
  2428. return 0;
  2429. }
  2430. void CLYFZSendMsgApp::RunThread()
  2431. {
  2432. m_bTerminate=false;
  2433. m_bRunning=false;
  2434. m_hThread = NULL;
  2435. m_bRunning=true;
  2436. m_hThread = (HANDLE)_beginthreadex(NULL,0, SendMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  2437. return;
  2438. m_bTerminate2=false;
  2439. m_bRunning2=false;
  2440. m_hThread2 = NULL;
  2441. m_bRunning2=true;
  2442. m_hThread2 = (HANDLE)_beginthreadex(NULL,0, ReceiveMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
  2443. }
  2444. //发送出错
  2445. /*
  2446. 移动:
  2447. 139,138,137,136,135,134,159,158,152,151,150,157,188,187,144
  2448. 联通:
  2449. 130,131,132,155,156,186,185
  2450. 电信:
  2451. 133,153,189,180
  2452. */
  2453. //------------------------------------------------------------------------------
  2454. // Remark by Jeff;
  2455. // 函数:CheckPhoneType
  2456. // 描述:判断手机号属于哪个运营商的;
  2457. // 参数:
  2458. // phoneno: 欲判断的手机号;
  2459. //
  2460. // 返回:返回0表示移动; 1表示联通; 2表示电信; 3表示小灵通; -1表示未知的;
  2461. //
  2462. // 注意:
  2463. //
  2464. //------------------------------------------------------------------------------
  2465. int CheckPhoneType(CString phoneno)
  2466. {
  2467. int i;
  2468. if(phoneno.IsEmpty ())return -1;
  2469. for( i=0; i<phoneno.GetLength (); i++)
  2470. {
  2471. if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
  2472. }
  2473. if(phoneno.GetAt (0)=='1')
  2474. {
  2475. if(phoneno.GetLength ()!=11)
  2476. return -1;
  2477. int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144,182,147,183,184,178};
  2478. int unicom[]={130,131,132,155,156,186,185,176};
  2479. int telecom[]={133,153,189,180,181,177};
  2480. for(i=0; i<sizeof(mobile)/sizeof(int); i++)
  2481. {
  2482. if(mobile[i]==atoi(phoneno.Left (3)))
  2483. {
  2484. return 0;
  2485. }
  2486. }
  2487. for(i=0; i<sizeof(unicom)/sizeof(int); i++)
  2488. {
  2489. if(unicom[i]==atoi(phoneno.Left (3)))
  2490. {
  2491. return 1;
  2492. }
  2493. }
  2494. for(i=0; i<sizeof(telecom)/sizeof(int); i++)
  2495. {
  2496. if(telecom[i]==atoi(phoneno.Left (3)))
  2497. {
  2498. return 2;
  2499. }
  2500. }
  2501. return -1;
  2502. }
  2503. /* else if(phoneno.GetAt (0)=='0')
  2504. {
  2505. if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
  2506. {
  2507. return 3;
  2508. }
  2509. }*/
  2510. return -1;
  2511. }
  2512. //------------------------------------------------------------------------------------------
  2513. // Remark by Jeff: 2014.09.21
  2514. // 函数:GetCount
  2515. // 描述:指定短信内容和手机号,计算出要发送的短信条数;
  2516. // 参数:
  2517. // phones: 以逗号分隔的手机号串;
  2518. // content: 短信内容;
  2519. //
  2520. // 返回:短信条数;
  2521. //
  2522. // 注意:
  2523. //
  2524. //------------------------------------------------------------------------------------------
  2525. int GetCount(CString phones, CString content)
  2526. {
  2527. // 1.首先分析出短信内容会被拆分成多少条短信发送;
  2528. int nNumberOfTextMsg = 0; // 短信条数;
  2529. int nWCharLen = ::MultiByteToWideChar(CP_ACP,0,content,-1,NULL,0); // Jeff.无论constent是否空,MultiByteToWideChar返回结果都>=1;
  2530. // 魔数MSG_LENGTH = 67:
  2531. // 当短信字符数超过70时,短信服务商会分为两部分;
  2532. // 1.将前67个字符为一条短信;
  2533. // 2.将67后的为另一部分,若仍大于70,再次执行1;
  2534. // 3.若短信小于等于70,则为一条短信;
  2535. nNumberOfTextMsg = nWCharLen / 67;
  2536. if (nWCharLen % 67 > 2 ) ++nNumberOfTextMsg;
  2537. // 2.其次解析手机字符串,获取手机数量;(不考虑小灵通,通用使用67字符截断短信)
  2538. int nCountOfMobile = 0;
  2539. int nIndex = 0;
  2540. do
  2541. {
  2542. nIndex = phones.Find(",");
  2543. if (nIndex != -1)
  2544. {
  2545. if ( nIndex == 11 && CheckPhoneType(phones.Left(nIndex)) != -1) // Jeff,CheckPhoneType返回-1表示未知手机类型;
  2546. ++nCountOfMobile;
  2547. phones = phones.Mid(nIndex+1);
  2548. }
  2549. else
  2550. {
  2551. if ( phones.GetLength() == 11 && CheckPhoneType(phones) != -1)
  2552. ++nCountOfMobile;
  2553. }
  2554. } while (nIndex != -1);
  2555. return nNumberOfTextMsg *= nCountOfMobile;
  2556. }
  2557. int GetBalance(CString account)
  2558. {
  2559. CString count1="";
  2560. CString count2="";
  2561. CString count3="";
  2562. try
  2563. {
  2564. CRecordset myset(&g_db);
  2565. #ifdef SQLSERVER_VERSION
  2566. CString sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
  2567. #else
  2568. CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
  2569. #endif
  2570. myset.Open (CRecordset::forwardOnly, sql);
  2571. if(!myset.IsEOF())
  2572. myset.GetFieldValue ("cot", count1);
  2573. myset.Close();
  2574. #ifdef SQLSERVER_VERSION
  2575. sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
  2576. #else
  2577. sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
  2578. #endif
  2579. myset.Open (CRecordset::forwardOnly, sql);
  2580. if(!myset.IsEOF())
  2581. myset.GetFieldValue ("cot", count2);
  2582. myset.Close();
  2583. #ifdef SQLSERVER_VERSION
  2584. sql="select sum(cast([msgcount2] as float)) as cot from sendreg where account='"+account+"'";
  2585. #else
  2586. sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
  2587. #endif
  2588. myset.Open (CRecordset::forwardOnly, sql);
  2589. if(!myset.IsEOF())
  2590. myset.GetFieldValue ("cot", count3);
  2591. myset.Close();
  2592. return atoi(count1)-atoi(count2);
  2593. }
  2594. catch(...)
  2595. {
  2596. return -1;
  2597. }
  2598. }