123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844 |
- // LYFZSendMsg.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "LYFZSendMsg.h"
- #include "ChildFrm.h"
- #include "LYFZSendMsgDoc.h"
- #include "LYFZSendMsgView.h"
- #include "ChoosePhotoSkin.h"
- #include "HttpClient.h"
- #include "Lzari.h"
- #include <tlhelp32.h>
- #include <wincrypt.h>
- #include <Mmsystem.h>
- #include "mysqldata.h"
- #include <afxsock.h>
- #include <process.h>
- //#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
- #include "AnalysisJXTRespond.h"
- #define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
- #define KEYLENGTH 0x00800000
- #define ENCRYPT_ALGORITHM CALG_RC4
- #define ENCRYPT_BLOCK_SIZE 8
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define NEWFORM 1
- extern int g_bSend;
- extern int g_bMsgRoad;
- extern int g_bDebug;
- extern int g_bMsgRoadtemp;
- //---------------------------------------------------------------------------
- typedef char* (__stdcall *FnMongateGetVer)();
- typedef int (__stdcall *FnMongateChangePwd)(int sock, const char* pszAccount,
- const char* pszOldPwd, const char* pszNewPwd);
- typedef int (__stdcall *FnMongateConnect)(const char* pszIP, int iPort, const char* pszAccount,
- const char* pszPwd);
- typedef void (__stdcall *FnMongateDisconnect)(int sock);
- typedef int (__stdcall *FnMongateQueryBalance)(int sock);
- typedef int (__stdcall *FnMongateQueryUsed)(int sock);
- typedef int (__stdcall *FnMongateSendSms)(int sock, const char* pszMobis, const char* pszMsg);
- typedef int (__stdcall *FnMongateConnectSocks4Proxy)(const char* ,int ,const char* ,int ,const char* ,const char* );
- typedef int (__stdcall *FnMongateCsGetSms)(SOCKET , char [500][255]);
- typedef int (__stdcall *FnMongateVasGetSms)(SOCKET , char [500][255]);
- typedef int (__stdcall *FnMongateVasSendSms)(SOCKET , const char* , const char* , const char* , const char* ,const char* , const char* , int );
- typedef int (__stdcall *FnMongateCsSendSmsHttp)(SOCKET , const char* ,const char* , int , char* );
- typedef int (__stdcall *FnMongateTestConn)(SOCKET );
- typedef int (__stdcall *FnMongateCsGetStatusReport)(SOCKET , char [500][255]);
- typedef int (__stdcall *FnMongateCsSendSms)(SOCKET , const char* ,const char* , int , char* );
- typedef int (__stdcall *FnMongateConnectSocks5Proxy)( const char* , int ,const char* ,const char* ,const char* ,int ,const char* ,const char* );
- typedef int (__stdcall *FnMongateConnectHttpProxy)(const char*,int ,const char* ,const char* ,const char* , int , const char* , const char* );
- typedef int (__stdcall *FnMongateTestConnHttp)(int);
- typedef int (__stdcall *FnMongateCsGetSmsHttp)(SOCKET , char [500][255]);
- typedef int (__stdcall *FnMongateCsGetStatusReportHttp)(SOCKET , char [500][255]);
- typedef int (__stdcall *FnMongateConnectHttpProxy)(const char* pszProxyIP,
- int iProxyPort,const char* pszProxyAccount,const char* pszProxyPwd,
- const char* pszIP, int iPort, const char* pszAccount, const char* pszPwd);
- typedef int (__stdcall *FnMongateTestMsgEx)(SOCKET sock,const char* pStrMessage,char *keywords);
- typedef int (__stdcall *FnMongateTestMsgExHttp)(SOCKET sock,const char* pStrMessage,char *keyword);
- typedef int (__stdcall *FnMongateCsSPSendSmsNew)(SOCKET sock, const char* pszMobis,
- const char* pszMsg, int iMobiCount,const char* pszSubPort,char* pszSN);
- int m_hsock=0;
- HMODULE g_hDll=NULL;
- FnMongateGetVer MongateGetVer;
- //tcp/ip method
- FnMongateTestMsgEx MongateTestMsgEx;
- FnMongateTestMsgExHttp MongateTestMsgExHttp;
- FnMongateConnect MongateConnect;
- FnMongateDisconnect MongateDisconnect;
- FnMongateChangePwd MongateChangePwd;
- FnMongateQueryBalance MongateQueryBalance;
- FnMongateQueryUsed MongateQueryUsed;
- FnMongateSendSms MongateSendSms;
- FnMongateCsGetSms MongateCsGetSms;
- FnMongateVasGetSms MongateVasGetSms;
- FnMongateVasSendSms MongateVasSendSms;
- FnMongateTestConn MongateTestConn;
- FnMongateCsGetStatusReport MongateCsGetStatusReport;
- FnMongateCsSendSms MongateCsSendSms;
- FnMongateConnectSocks4Proxy MongateConnectSocks4Proxy;
- FnMongateConnectSocks5Proxy MongateConnectSocks5Proxy;
- //http method
- FnMongateConnect MongateConnectHttp;
- FnMongateQueryBalance MongateQueryBalanceHttp;
- FnMongateQueryUsed MongateQueryUsedHttp;
- FnMongateSendSms MongateSendSmsHttp;
- FnMongateChangePwd MongateChangePwdHttp;
- FnMongateDisconnect MongateDisconnectHttp;
- FnMongateTestConnHttp MongateTestConnHttp;
- FnMongateCsSendSmsHttp MongateCsSendSmsHttp;
- FnMongateConnectHttpProxy MongateConnectHttpProxy;
- FnMongateCsGetSmsHttp MongateCsGetSmsHttp;
- FnMongateCsGetStatusReportHttp MongateCsGetStatusReportHttp;
- FnMongateCsSPSendSmsNew MongateCsSPSendSmsNew;
- //Font *g_BlackFont=NULL;
- CDatabase *g_curdb=NULL;
- CDatabase g_db;
- CDatabase g_db2;
- CDatabase g_db3;
- CString g_date;
- CString g_title;
- CArray<CStringArray, CStringArray>g_userarray;
- CArray<CStringArray, CStringArray>g_cominfoarray;
- CArray<DWORD,DWORD>g_lengarray;
- CArray<DWORD,DWORD>g_btnlengarray;
- CArray<BYTE*,BYTE*>g_pointerarray;
- DWORD g_btnleng[8];
- int g_btnlengpos=-1;
- int g_nYearpos=-1;
- /////////////////////////////////////////////////////////////////////////////
- // CLYFZSendMsgApp
- BOOL g_bShowOK=0;
- BOOL g_bStaffAchievementShow=0;
- USER g_user;
- CString g_mainpath;
- CString g_server;
- CString g_path1;
- CString g_path2;
- CString g_path3;
- CString g_path4;
- DWORD g_ncount;
- CFont g_titlefont;
- DWORD g_nSendCode=0;
- BOOL g_bSendOK=0;
- SENDHEAD g_sendhead;
- CArray<CStringArray, CStringArray>g_hisyeararray;
- extern CFont g_listctrlfont;
- //CMainCtrl g_tMainCtrl;
- #pragma comment(lib, "Transport.lib")
- #pragma comment(lib, "Winmm.lib")
- BEGIN_MESSAGE_MAP(CLYFZSendMsgApp, CWinApp)
- //{{AFX_MSG_MAP(CLYFZSendMsgApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CLYFZSendMsgApp construction
- float g_fscalex;
- float g_fscaley;
- DEVMODE g_dm;
- CLYFZSendMsgApp::CLYFZSendMsgApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- g_dm.dmSize = sizeof(DEVMODE) ;
- EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&g_dm);
- g_fscalex=(float)g_dm.dmPelsWidth/1024.0;
- g_fscaley=(float)g_dm.dmPelsHeight/768.0;
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CLYFZSendMsgApp object
- CLYFZSendMsgApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CLYFZSendMsgApp initialization
- DWORD FindAppProcessID(CString path)
- {
- try
- {
- HANDLE handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
- PROCESSENTRY32 Info;
- Info.dwSize = sizeof(PROCESSENTRY32);
- path.MakeLower ();
- if(::Process32First(handle,&Info))
- {
- do
- {
- CString ss=Info.szExeFile;
- ss.MakeLower ();
- if(ss.Find (path)!=-1 || (!ss.CompareNoCase(path)) )
- {
- ::CloseHandle(handle);
- return Info.th32ProcessID;
- }
- }
- while(::Process32Next(handle,&Info));
- ::CloseHandle(handle);
- }
- return -1;
- }
- catch(...)
- {
- }
- }
- int GetPhoneCount(CString phones)
- {
- int count=0;
- int pos=phones.Find (",");
- if(pos!=-1)
- {
- count++;
- phones=phones.Right (phones.GetLength ()-pos-1);
- pos=phones.Find (",");
- while(pos!=-1)
- {
- count++;
- phones=phones.Right (phones.GetLength ()-pos-1);
- pos=phones.Find (",");
- }
- count++;
- }
- else
- count++;
- return count;
- }
- BOOL MyExecuteSQL(CDatabase *pdb, CString sql)
- {
- // MyLock lock("xiaoaccessdbmsg");
- try
- {
- pdb->ExecuteSQL (sql);
- }
- catch(...)
- {
- return 0;
- }
- return 1;
- }
- void ResetReg(CString id)
- {
- CString sql;
- sql.Format ("update [sendreg] set [msgcount2]='%d' where [autoid]=%d", 0, atol(id));
- MyExecuteSQL(&g_db2, sql);
- }
- BOOL CheckBadWords2(CString str,BOOL bMsg)
- {
- return 1;
- }
- CString g_temp;
- BOOL CheckBadWords(CString str,BOOL bMsg)
- {
- CString badwords[165]={\
- "【call5.me】",\
- "您可拨020",\
- "88btt.com热线400611",\
- "400678165",\
- "海王星",\
- "博天堂",\
- "十八大",\
- "钓鱼岛",\
- "无限次数提款",\
- "广东地和",\
- "利来",\
- "抢劫",\
- "fa lun",\
- "强奸",\
- "dafa",\
- "falun",\
- "SIM卡抽奖",\
- "罢工",\
- "罢课",\
- "暴乱",\
- "婊子",\
- "操你",\
- "操你娘",\
- "蠢猪",\
- "达赖",\
- "打倒",\
- "大法",\
- "大纪元",\
- "弹药",\
- "钓鱼岛",\
- "东突",\
- "东突厥斯坦伊斯兰运动",\
- "发抡",\
- "发仑",\
- "发伦",\
- "发囵",\
- "发沦",\
- "发纶",\
- "发轮",\
- "发论",\
- "法 轮 功",\
- "法.轮.功",\
- "法抡",\
- "法仑",\
- "法伦",\
- "法囵",\
- "法沦",\
- "法纶",\
- "法轮",\
- "法论",\
- "反革命",\
- "反日",\
- "分裂",\
- "干你娘",\
- "功友",\
- "古怪歌",\
- "国研新闻邮件",\
- "黑庄",\
- "宏志",\
- "洪志",\
- "胡锦涛",\
- "鸡巴",\
- "鸡毛信文汇",\
- "妓女",\
- "简鸿章",\
- "江八点",\
- "江独裁",\
- "江泽民",\
- "疆独",\
- "教徒",\
- "锦涛",\
- "靖国神社",\
- "九、评",\
- "九.评",\
- "九码",\
- "九-评",\
- "拉丹",\
- "拉登",\
- "李鹏",\
- "联总之声传单",\
- "灵动卡",\
- "六合彩",\
- "六码",\
- "吕秀莲",\
- "绿色环保手机",\
- "美国之音",\
- "猛料",\
- "迷药",\
- "民运",\
- "民猪",\
- "嫖娼",\
- "迫害",\
- "枪支",\
- "强奸",\
- "窃听器",\
- "人民报",\
- "人民报讯",\
- "人民大众时事参考",\
- "人民内情真相",\
- "人民真实报道",\
- "人权",\
- "日你妈",\
- "日他",\
- "三码",\
- "三陪",\
- "色情",\
- "傻B",\
- "涉日",\
- "十六大",\
- "示威",\
- "他妈的",\
- "台*湾",\
- "特等奖",\
- "天葬",\
- "突厥斯坦",\
- "推翻",\
- "王八蛋",\
- "温家宝",\
- "无能",\
- "香港总部",\
- "小鸡鸡",\
- "新华举报",\
- "新华内情",\
- "新闻封锁",\
- "畜生",\
- "玄`机",\
- "压迫",\
- "淫秽",\
- "银行联合管理局",\
- "印尼伊斯兰祈祷团",\
- "游行",\
- "舆论",\
- "造反",\
- "真善忍",\
- "镇压",\
- "正法",\
- "政变",\
- "政治风波",\
- "中俄边界新约",\
- "中国银联",\
- "中华民国",\
- "中奖",\
- "朱容基",\
- "自焚",\
- "自由运动",\
- "达赖",\
- "套牌",\
- "情妇",\
- "监听",\
- "巴南电信",\
- "合川分公司",\
- "合川电信",\
- "死光",\
- "116114",\
- "北京宝诚",\
- "华盛投资",\
- "名门国际",\
- "利博",\
- "赤橙黄绿",\
- "免佣BJL首发",\
- "洗*码优惠",\
- "【俱乐部】",\
- "18266381922",\
- "回拨卡",\
- "号码百事通推出短信订机票!实时"};
- for(int i=0; i<165; i++)
- {
- g_temp=badwords[i];
- if(str.Find (g_temp)!=-1)
- {
- // AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
- return 0;
- }
- }
- return 1;
- }
- extern int g_iLeft; // Jeff.通过查询短信服务商获得的短信可用的余额;
- extern int g_iUsed;
- extern int g_nQuery;
- int g_bRunOnce=0;
- BOOL IsPlaySound()
- {
- return 0;
- CTime tm=CTime::GetCurrentTime ();
- if( !(tm.GetHour ()>22 && tm.GetHour ()<9) )return 1;
- return 0;
- }
- void Encode(const char *Inbuf, char *Outbuf)
- {
- char table[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- unsigned char c80,c81,c82;
- int i,k;
- int nInLen=strlen(Inbuf);
- // int nOutLen;
- if(strlen(Inbuf)==0) //输入出错了
- exit(-1);
- int IndexOut=0;
- unsigned short tmp1,tmp2;
- k=nInLen/3; ///完整的、可以凑足3倍数的部分
- for(i=0;i<k;i++)
- {
- c80=Inbuf[i*3];
- c81 = Inbuf[i*3+1];
- c82 = Inbuf[i*3+2];
- tmp1=(unsigned short)c80 <<8 | c81 ;
- tmp2=(unsigned short)c81 <<8 | c82;
- tmp1= (tmp1>>4 ) & 0x003f;
- tmp2= (tmp2>>6 ) & 0x003f;
- Outbuf[IndexOut]=table[c80>>2];
- IndexOut++;
- Outbuf[IndexOut]=table[tmp1];
- IndexOut++;
- Outbuf[IndexOut]=table[tmp2];
- IndexOut++;
- Outbuf[IndexOut]=table[c82 & 0x3f];
- IndexOut++;
- }
- if(nInLen%3==0)
- {
- Outbuf[IndexOut]='\0';
- return;
- }
- ////////////////////////剩余的不足整倍数的部分
- k=nInLen%3;
- i=nInLen/3;
- c80=Inbuf[i*3];
- if(k==1)
- {
- Outbuf[IndexOut]=table[(c80 >>2) & 0x3f];
- IndexOut++;
- Outbuf[IndexOut]=table[(c80 <<4) & 0x3f];
- IndexOut++;
- Outbuf[IndexOut]='=';
- IndexOut++;
- Outbuf[IndexOut]='=';
- IndexOut++;
- }
- else
- {
- c81 = Inbuf[i*3+1];
- tmp1=(unsigned short)c80 <<8 | c81;
- tmp1= (tmp1>>4 ) & 0x003f;
- Outbuf[IndexOut]=table[(c80 >>2) & 0x3f];
- IndexOut++;
- Outbuf[IndexOut]=table[tmp1];
- IndexOut++;
- Outbuf[IndexOut]=table[(c81 <<2) & 0x3f];
- IndexOut++;
- Outbuf[IndexOut]='=';
- IndexOut++;
- }
- //end of some more.
- Outbuf[IndexOut]='\0';
- }
- void Decode( char *Inbuf, char *Outbuf)
- {
- int nInLen;
- CString Base64Code("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
- nInLen=strlen(Inbuf);
- if(nInLen%4!=0) //长度有误
- exit(-1);
- int nOutLen=nInLen /4 *3;
- Outbuf=new char[nOutLen +4]; ///////////为输出分配存储空间
- int i=0;
- while(Inbuf[i] != '\0') /////把末尾的“===”转换为0
- if(Inbuf[i]== '=')
- Inbuf[i]=0;
- unsigned short a,b,c,d;
- char tmp;
- for(int LoopValue=0;LoopValue<nInLen/4;LoopValue++) //循环变量
- {
- a= Base64Code.Find(Inbuf[LoopValue*4]);
- b= Base64Code.Find(Inbuf[LoopValue*4 +1]);
- if(Inbuf[LoopValue*4 +2]==0)
- c=0;
- else
- c= Base64Code.Find(Inbuf[LoopValue*4 +2]);
- if(Inbuf[LoopValue*4 +3]==0)
- d=0;
- else
- d= Base64Code.Find(Inbuf[LoopValue*4 +3]);
- tmp= (a <<6) | (b>>4);
- *Outbuf=tmp;
- Outbuf++;
- tmp= (b<<4) | ((c>>2) <<4);
- if(tmp!=0)
- {
- *Outbuf=tmp;
- Outbuf++;
- }
- tmp= (c<<6) | d;
- if(tmp!=0)
- {
- *Outbuf=tmp;
- Outbuf++;
- }
- }
- *Outbuf=0;
- }
- int GetFormBalanceJXT(CString name, CString psw)
- {//http://service.winic.org:8009/webservice/public/remoney.asp?uid=lyfz&pwd=123456
- CHttpClient conn;
- CString value="http://service.winic.org:8009/webservice/public/remoney.asp?";
- CString temp;
- temp.Format ("uid=%s", name);
- value+=temp;
- temp.Format ("&pwd=%s", psw);
- value+=temp;
- value=conn.doGet(value);
- if(value.Find ("-")!=-1)return -1;
- if(value.Find ("null")!=-1)return -1;
- int count=(int)(atof(value)/0.05);
- return count;
- }
- int GetFormBalanceSYT(CString name, CString psw)
- {
- CHttpClient conn;
- CString value="http://www.mb2e.com/ws/SelSum.aspx?";
- CString temp;
- temp.Format ("CorpID=%s", name);
- value+=temp;
- temp.Format ("&Pwd=%s", psw);
- value+=temp;
- value=conn.doGet(value);
- if(value.Find ("-")!=-1)return -1;
- return atoi(value);
- }
- CString GetFormBalanceBeiJing(CString name, CString psw)
- {
- CHttpClient conn;
- CString value="http://121.52.221.108/send/getfee.aspx?";
- CString temp;
- temp.Format ("name=%s", name);
- value+=temp;
- temp.Format ("&pwd=%s", psw);
- value+=temp;
- value=conn.doGet(value);
- int pos=value.Find ("&");
- if(pos==-1)
- {
- return "-1";
- }
- value=value.Left (pos);value.TrimLeft ("id=");
- return value;
- }
- // ----------------------------------------------------------------------------
- // remark by Jeff: 2014-09-17 PM;
- // 函数:
- // 描述:通过账号密码登录指定短信服务商,获取短信可用余额(Money);
- // 参数:
- // name:短信服务账号;
- // psw: 短信服务密码;
- //
- // 通过全局变量g_bMsgRoad来指定短信服务商;
- // 使用的全局变量:g_bMsgRoad 短信服务商, == 0 ??? ; == 1 吉信通; == 2 ???;
- //
- // ----------------------------------------------------------------------------
- int GetFormBalance(CString name, CString psw)
- {
- // return atoi(GetFormBalanceBeiJing("lyfzrj", "lyfzrj123"));
- if(g_bMsgRoad==1)
- {
- return GetFormBalanceJXT( name, psw);
- }
- else if(g_bMsgRoad==2)
- {
- return GetFormBalanceSYT( name, psw);
- }
- CHttpClient conn;
- CString value="http://www2.lansea.com.cn/servlet/UserServiceAPI?";
- CString temp;
- value+="method=getRestMoney";
- temp.Format ("&username=%s", name);
- value+=temp;
- temp.Format ("&password=%s", psw);
- value+=temp;
- value=conn.doGet(value);
- CString finder="gateSmsNum=";
- int pos=value.Find (finder);
- if(pos==-1)return -1;
- value=value.Right (value.GetLength ()-finder.GetLength ()-pos);
- pos=value.Find (";");
- if(pos!=-1)
- {
- value=value.Left(pos);
- }
- return atoi(value);
- }
- // ----------------------------------------------------------------------------
- // Remark by Jeff;
- // 函数:SendFormMsgJXT
- // 描述:使用HTTP方式连接吉信通服务端来发送短信;
- // 参数:
- // 返回:
- //
- // 吉信通返回:
- // 000:发送短信成功;
- // -11:短信内容超长(70个字符); // 经过询问吉信通技术员,该返回值基本没有任何参考价值!
- //
- // HTTP返回格式:
- // -02/Send:1/Consumption:0/Tmoney:0 / sid;
- // 状态码/发送条数/当次消费金额/总体余额/短信编号;
- // ----------------------------------------------------------------------------
- int SendFormMsgJXT(CString name, CString psw, CString phones, CString content, CString &pRtn)
- {
- //http://service.winic.org:8009/sys_port/gateway/?id=lyfz&pwd=123456&to=18666532220&content=hello33
- CHttpClient conn;
- CString value="http://service.winic.org:8009/sys_port/gateway/?";
- CString temp;
- temp.Format ("id=%s", name);
- value+=temp;
- temp.Format ("&pwd=%s", psw);
- value+=temp;
- temp.Format ("&to=%s", phones);
- value+=temp;
- temp.Format ("&content=%s", content);
- value+=temp;
- pRtn=conn.doGet(value);
- if(pRtn.GetLength()<3)return 0;
- if(pRtn.Left(3)=="000")return 1;
- if(pRtn.GetLength()>50)pRtn=pRtn.Left(50);
- return 0;
- }
- void SendFormMsgJXT_01(CString name, CString psw, CString phones, CString content, CString &pRtn)
- {
- //http://service.winic.org:8009/sys_port/gateway/?id=lyfz&pwd=123456&to=18666532220&content=hello33
- CHttpClient conn;
- CString value="http://service.winic.org:8009/sys_port/gateway/?";
- CString temp;
- temp.Format ("id=%s", name);
- value+=temp;
- temp.Format ("&pwd=%s", psw);
- value+=temp;
- temp.Format ("&to=%s", phones);
- value+=temp;
- temp.Format ("&content=%s", content);
- value+=temp;
- pRtn = conn.doGet(value);
- #if 0
- if(pRtn.GetLength()<3)return 0;
- if(pRtn.Left(3)=="000")return 1;
- if(pRtn.GetLength()>50)pRtn=pRtn.Left(50);
- return 0;
- #endif
- }
- CString SendFormMsgBeiJing(CString name, CString psw, CString phones, CString content, CString &pRtn)
- {
- try
- {
- CHttpClient conn;
- CString value="http://121.52.221.108/send/gsend.aspx?";
- value="http://121.52.221.108/send/g70send.aspx?";
- CString temp;
- temp.Format ("name=%s", name);
- value+=temp;
- temp.Format ("&pwd=%s", psw);
- value+=temp;
- temp.Format ("&dst=%s", phones);
- value+=temp;
- temp.Format ("&msg=%s", content);
- value+=temp;
- temp.Format ("&sequeid=%s", "12345");
- value+=temp;
- pRtn=conn.doGet(value);
- }
- catch(...)
- {
- }
- return pRtn;
- }
- int SendFormMsgSYT(CString name, CString psw, CString phones, CString content, CString &pRtn)
- {
- CHttpClient conn;
- CString value="http://www.mb2e.com/ws/Send2.aspx?";
- if(phones.Find (",")!=-1)value="http://www.mb2e.com/ws/BatchSend2.aspx?";
- CString temp;
- temp.Format ("CorpID=%s", name);
- value+=temp;
- temp.Format ("&Pwd=%s", psw);
- value+=temp;
- temp.Format ("&Mobile=%s", phones);
- value+=temp;
- temp.Format ("&Content=%s", content);
- value+=temp;
- pRtn=conn.doGet(value);
- if(atoi(pRtn)>0)return 1;
- return 0;
- }
- // Jeff.SendFormMsg没有被其他任何函数调用;
- //
- int SendFormMsg(CString name, CString psw, CString phones, CString content, CString &pRtn)
- {
- if(g_bMsgRoad==1)
- {
- return SendFormMsgJXT( name, psw, phones, content, pRtn);
- }
- else if(g_bMsgRoad==2)
- {
- return SendFormMsgSYT( name, psw, phones, content, pRtn);
- }
- CHttpClient conn;
- CString value="http://www2.lansea.com.cn/servlet/UserServiceAPI?";
- CString temp;
- value+="method=sendSMS";
- value+="&isLongSms=0";
- temp.Format ("&username=%s", name);
- value+=temp;
- temp.Format ("&password=%s", psw);
- value+=temp;
- value+="&smstype=1";
- temp.Format ("&mobile=%s", phones);
- value+=temp;
- temp.Format ("&content=%s", content);
- value+=temp;
- pRtn=conn.doGet(value);
- CString finder="success";
- int pos=pRtn.Find (finder);
- if(pos==-1)return 0;
- return 1;
- }
- int FindArray(CStringArray *pArray, CString Str)
- {
- for(int i=0; i<pArray->GetSize(); i++)
- {
- if(pArray->ElementAt(i)==Str)
- return i;
- }
- return -1;
- }
- BOOL g_bLoadroad2clientarray=1;
- CStringArray g_road2clientarray;
- CStringArray g_road3clientarray;
- void Loadroad2clientarray()
- {
- if(g_bLoadroad2clientarray)
- {
- g_bLoadroad2clientarray=0;
- g_road2clientarray.RemoveAll();
- g_road3clientarray.RemoveAll();
- CRstClientInfo rsSt;
- rsSt.m_strFilter ="[road]='1'";
- rsSt.m_pDatabase=&g_db2;
- rsSt.Open();
- while(!rsSt.IsEOF())
- {
- g_road2clientarray.Add(rsSt.m_account) ;
- rsSt.MoveNext();
- }
- rsSt.Close();
- rsSt.m_strFilter ="[road]='2'";
- rsSt.m_pDatabase=&g_db2;
- rsSt.Open();
- while(!rsSt.IsEOF())
- {
- g_road3clientarray.Add(rsSt.m_account) ;
- rsSt.MoveNext();
- }
- rsSt.Close();
- }
- }
- int GetLengthEx2(CString str)
- {
- wchar_t wstr[500];
- int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
- return k;
- }
- void FirstLetter(int nCode, CString& strLetter)
- {
- if(nCode >= 1601 && nCode < 1637) strLetter = _T("A");
- if(nCode >= 1637 && nCode < 1833) strLetter = _T("B");
- if(nCode >= 1833 && nCode < 2078) strLetter = _T("C");
- if(nCode >= 2078 && nCode < 2274) strLetter = _T("D");
- if(nCode >= 2274 && nCode < 2302) strLetter = _T("E");
- if(nCode >= 2302 && nCode < 2433) strLetter = _T("F");
- if(nCode >= 2433 && nCode < 2594) strLetter = _T("G");
- if(nCode >= 2594 && nCode < 2787) strLetter = _T("H");
- if(nCode >= 2787 && nCode < 3106) strLetter = _T("J");
- if(nCode >= 3106 && nCode < 3212) strLetter = _T("K");
- if(nCode >= 3212 && nCode < 3472) strLetter = _T("L");
- if(nCode >= 3472 && nCode < 3635) strLetter = _T("M");
- if(nCode >= 3635 && nCode < 3722) strLetter = _T("N");
- if(nCode >= 3722 && nCode < 3730) strLetter = _T("O");
- if(nCode >= 3730 && nCode < 3858) strLetter = _T("P");
- if(nCode >= 3858 && nCode < 4027) strLetter = _T("Q");
- if(nCode >= 4027 && nCode < 4086) strLetter = _T("R");
- if(nCode >= 4086 && nCode < 4390) strLetter = _T("S");
- if(nCode >= 4390 && nCode < 4558) strLetter = _T("T");
- if(nCode >= 4558 && nCode < 4684) strLetter = _T("W");
- if(nCode >= 4684 && nCode < 4925) strLetter = _T("X");
- if(nCode >= 4925 && nCode < 5249) strLetter = _T("Y");
- if(nCode >= 5249 && nCode < 5590) strLetter = _T("Z");
- }
- void GetFirstLetter(CString strName, CString& strFirstLetter)
- {
- try
- {
- TBYTE ucHigh, ucLow;
- int nCode;
- CString strRet;
- strFirstLetter.Empty();
- for (int i=0; i<strName.GetLength(); i++)
- {
- if ( (TBYTE)strName[i] < 0x80 )
- {
- strRet=strName.Mid (i,1);
- strRet.MakeUpper ();
- strFirstLetter += strRet;
- continue;
- }
- ucHigh = (TBYTE)strName[i];
- ucLow = (TBYTE)strName[i+1];
- if ( ucHigh < 0xa1 || ucLow < 0xa1)
- continue;
- else
- // Treat code by section-position as an int type parameter,
- // so make following change to nCode.
- nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;
- FirstLetter(nCode, strRet);
- strFirstLetter += strRet;
- i++;
- }
- }
- catch(...)
- {
- }
- }
- //--------------------------------------------------------------
- //
- //
- //
- //
- //
- //--------------------------------------------------------------
- unsigned __stdcall SendMsgThread(LPVOID lpParam)
- {
- ll: CLYFZSendMsgApp *pDlg=(CLYFZSendMsgApp*)lpParam;
- /*
- pDlg->m_bRunning=false;
- pDlg->m_bTerminate=false;
- _endthreadex( 0 ); pDlg->m_hThread=NULL;
- return 0;
- */
- int bSendTypeUnicom=0;
- int step=0;
- try
- {
- BOOL bServer=1;
- CString account="5500037";
- CString psw="516842";
- char spsw[100];
- Encode(psw, spsw);
- psw=spsw;
- CString account0=account;
- CString psw0=psw;
- while(1)
- {
- if(pDlg->m_bTerminate)break;
- step=0;
- // if(g_bLoadroad2clientarray)Loadroad2clientarray();
- g_bMsgRoad=g_bMsgRoadtemp;
- if(g_bMsgRoad==1)
- {
- account=Global::g_szSMSAccount;
- psw=Global::g_szSMSPassword;
- }
- else if(g_bMsgRoad==2)
- {
- account="test01";
- psw="123456";
- }
- else
- {
- account=account0;
- psw=psw0;
- }
- if(g_nQuery==1)
- {
- // g_iLeft = atoi(GetFormBalanceBeiJing("lyfzrj", "lyfzrj123"));//GetFormBalance(account, psw);
- // g_iUsed= atoi(GetFormBalanceBeiJing("lyfzrj1", "lyfz1234"));
- g_iLeft =GetFormBalance(account, psw); // Jeff 通过查询短信服务商获得的短信可用的余额;
- g_iUsed=0;
- g_nQuery=0;
- }
- // Jeff.g_bSend用来控制线程是否继续操作;
- if(g_bSend==0)
- {
- ::Sleep (1000);
- continue;
- }
- // Jeff remark:
- // g_bRunOnce作用? 用来重置什么?
- // msgcount2 == -2是什么作用?
- if(g_bRunOnce==0)
- {
- CString sql;
- sql.Format ("update [sendreg] set [msgcount2]='%d' where [msgcount2]='%d'", 0, -2);
- if(MyExecuteSQL(&g_db2, sql)==0)
- {
- ::Sleep(100);
- WriteLogin("重置失败!");
- continue;
- }
- }
- g_bRunOnce++;
- if(g_bRunOnce==10)g_bRunOnce=0;
- CString id; // 表自增id;
- CString phones; // 接收短信的手机号;
- CString content; // 短信内容;
- CString timestamp; // 短信生成时间;
- CString log; // 短信日志;
- timestamp=CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
- int timestampleng=timestamp.GetLength ();
- //BOOL bEof=0; // Jeff,这个变量命名使人误会!应该命名为bValid或bValidRecord,有效或有效的记录;
- BOOL bValidRecord = FALSE; // Jeff Modify;
- CString clientaccount;
- // -----------------------------------------------------------------------------------------
- // Remark by Jeff 2014-09-17
- // 每次Open数据集时,打开的永远是符合查询条件的第一条记录;
- // 当线程处理速度赶不上新短信内容插入的速度时,这样会造成短信积压,记录集最底部的记录永远是最后发送的;
- // 如果一直有新短信内容插入数据库表,那么记录集底部的短信就有可能永远不会被发送出去,造成所谓的"短信发不出去".
- // 应该使用MoveLast()移动到最后一条记录,从记录集底部开始发送;
- // -----------------------------------------------------------------------------------------
- if(1)
- {
- step=1;
- RstSendReg rsSt;
- rsSt.m_strFilter ="[msgcount2]='0' and ([log] is null or [log]<>'超过12小时' or [log]='超过12小时重发')";
- rsSt.m_pDatabase=&g_db2;
- rsSt.Open();
- if(!rsSt.IsEOF())
- {
- //bEof=1;
- bValidRecord = TRUE;
- id=rsSt.m_id;
- phones=rsSt.m_phones;
- content=rsSt.m_content;
- timestamp=rsSt.m_timestamp;
- log=rsSt.log;
- rsSt.Close();
- clientaccount=rsSt.m_account;
- if(clientaccount=="453203" && content=="阳光贝贝儿童摄影祝您全家元旦快乐元月6号前办理VIP赠礼品送成长录老会员免 费升级更多优 惠登陆WWW·SXYGBB·COM或3826526")
- {
- RstSendReg rsSt;
- rsSt.m_strFilter.Format("[msgcount2]<>'0' and content='阳光贝贝儿童摄影祝您全家元旦快乐元月6号前办理VIP赠礼品送成长录老会员免 费升级更多优 惠登陆WWW·SXYGBB·COM或3826526' and phones like '%%s%'", phones);
- rsSt.m_pDatabase=&g_db2;
- rsSt.Open();
- BOOL exist=0;
- if(!rsSt.IsEOF())
- {
- exist=1;
- }
- rsSt.Close();
- if(exist)
- {
- CString sql;
- sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s' where [autoid]=%d", 1, "77777777", atol(id));
- MyExecuteSQL(&g_db2, sql);
- continue;
- }
- }
- }
- else
- {
- // WriteLogin("查询无未发信息!");
- rsSt.Close();
- }
- }
- step=2;
- if(g_bMsgRoad==1)
- {
- account=Global::g_szSMSAccount;
- psw=Global::g_szSMSPassword;
- }
- bSendTypeUnicom=0; // 用途???
- // -----------------------------------------------------------------------------------------
- // Remark by Jeff:
- // g_road2clientarray 初始化或插入数据的函数在Loadroad2clientarray(); 但是,整个程序却没有任何一处调用该函数;
- // 唯一调用Loadroad2clientarray()的是在本线程,却被注释掉的;
- // 那么g_road2clientarray为空的数组,FindArray就没有任何意义;
- // 同样g_road3clientarray也是与g_road2clientarray一样的函数初始化和插入数据;
- // 这样导致 bSendTypeUnicom == 2 永久性的;
- // -----------------------------------------------------------------------------------------
- if(-1 != FindArray(&g_road2clientarray, clientaccount))
- bSendTypeUnicom=1;
- if(-1 != FindArray(&g_road3clientarray, clientaccount))
- bSendTypeUnicom=2;
- //if(bEof)
- if( bValidRecord )
- {
- content.TrimLeft();
- content.TrimRight();
- content.Replace("\r", "");
- content.Replace("", "");
- content.Replace("\n", "");
- content.Replace("'", "");
- // content.Replace ("短信", "信");
- // content.Replace ("信息", "信");
- content.Replace ("优惠", "优蕙");
- content.Replace ("询", "讯");
- content.Replace ("免费", "免費");
- content.Replace ("珺", "君");
- content.Replace (",北京", "北-京");
- content.Replace ("拨打", "撥打");
- content.Replace ("销售", "銷售");
- content.Replace ("热线", "专线");
- content.Replace ("抢购", "购买");
- content.Replace ("彧", "或");
- content.Replace ("QQ", "扣扣");
- content.Replace ("第一次", "第1次");
- content.Replace ("兑换", "换取");
- content.Replace ("账户", "帳戶");
- content.Replace ("账号", "帳号");
- content.Replace ("户名", "戶名");
- content.Replace ("刺激", "剌激");
- content.Replace ("集团", "集團");
- content.Replace ("10159", "10158");
- phones.TrimLeft();
- phones.TrimRight();
- CString sql;
- // Jeff:短信内容与strarray数组里任意元素的相同,短信不发送,但仍收费;
- CStringArray strarray;
- strarray.Add ("!");
- strarray.Add ("!!");
- strarray.Add ("!!!");
- strarray.Add ("!");
- strarray.Add ("!!");
- strarray.Add ("!!!");
- strarray.Add (".");
- strarray.Add ("..");
- strarray.Add ("...");
- strarray.Add ("。");
- strarray.Add ("。。");
- strarray.Add ("。。。");
- strarray.Add ("上");
- BOOL bSend=1;
- for(int y=0; y<strarray.GetSize(); y++)
- {
- if(content==strarray.ElementAt(y))
- {
- bSend=0;
- break;
- }
- }
- step=3;
- if(!bSend) // 针对上面strarray==content的情况;
- {
- sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s' where [autoid]=%d", 1, "88888888", atol(id));
- MyExecuteSQL(&g_db2, sql);
- continue;
- }
- // 查询条件:"[msgcount2]='0' and ([log] is null or [log]<>'超过12小时' or [log]='超过12小时重发')"
- // log != 超过12小时重发 && ([log] is null or [log]<>'超过12小时')
- if(timestamp.GetLength()==14 && log != "超过12小时重发")
- {
- if(timestamp.Left(2)=="20")
- {
- 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)));
- CTime tm2=CTime::GetCurrentTime ();
- CTimeSpan dt=tm2-tm;
- if(dt.GetDays()>1)
- {
- // timestamp+="超";
- sql.Format ("update sendreg set [msgcount2]='%d',[log]='%s',[timestamp]='%s' where [autoid]=%d", 0, "超过12小时", timestamp,atol(id));
- MyExecuteSQL(&g_db2, sql);
- continue;
- }
- }
- }
- step=4;
- sql.Format ("update [sendreg] set [msgcount2]='%d' where [autoid]=%d", -2, atol(id));
- if(MyExecuteSQL(&g_db2, sql)==0)
- {
- WriteLogin("保存发送中失败!");
- ::Sleep (100);
- continue;
- }
- step=5;
- ////////////////////连接
- int count=GetPhoneCount(phones);
- step=6;
- CString pRtn;
- int nRet;
- #if 0
- /* if(bSendTypeUnicom==0)//北京
- {
- SendFormMsgBeiJing("lyfzrj", "lyfzrj123", phones, content, pRtn);
- step=7;
- CString strRes1;
- GetFirstLetter(pRtn, strRes1); step=8;
- pRtn=strRes1;
- if(pRtn.GetLength ()>250)
- {
- pRtn=pRtn.Left (250);
- }
- }
- else if(bSendTypeUnicom==1)//北京
- {
- SendFormMsgBeiJing("lyfzrj1", "lyfz1234", phones, content, pRtn);
- step=9;
- CString strRes1;
- GetFirstLetter(pRtn, strRes1);
- step=10;
- pRtn=strRes1;
- if(pRtn.GetLength ()>250)
- {
- pRtn=pRtn.Left (250);
- }
- }
- else*/
- {
- SendFormMsgJXT("lyfz", "lyfz0752", phones, content, pRtn);
- CString strRes1;
- GetFirstLetter(pRtn, strRes1);
- pRtn=strRes1;
- if(pRtn.GetLength ()>250)
- {
- pRtn=pRtn.Left (250);
- }
- }
- step=11;
- pRtn.MakeLower();
- CString log=pRtn;
- 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) );
- if(MyExecuteSQL(&g_db2, sql)==0)
- {
- // if(bSendTypeUnicom!=2)//北京维那
- // WriteLogin("保存发送记录失败北京维那!");
- // else
- WriteLogin("保存发送记录失败2!");
- }
- step=12;
- ::Sleep (100);
- #else
- SendFormMsgJXT_01(Global::g_szSMSAccount, Global::g_szSMSPassword, phones, content, pRtn);
- if ( pRtn == "")
- {
- // 短信发往运营商服务平台返回异常;
- // 认为没有发送,不处理,不扣费;
- // 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) );
- }
- else
- {
- AnalysisJXTRespond AnalysisRespond;
- pRtn.MakeLower();
- if ( AnalysisRespond.AnalysisRespondString(pRtn) != 0 /*0xF*/ ) // 0xF表示返回的结果是正常的;
- {
- //CString log=pRtn;
- // Jeff,假如AnalysisRespond.nStatus=0,最好在这里更新msgcount的值:如果原来的值小于当前值,则update;
- // SQL:update sendreg set [msgcount]=case when [msgcount]< nSendCount then nSendCount else [msgcount],msgcount2=nSendCount,log="",sendtime="" where autoid=""
- sql.Format("update sendreg set [msgcount]=case when [msgcount] < '%d' then '%d' else [msgcount] end,[msgcount2]='%d',[log]='%s',[sendtime]='%s' where [autoid]=%d",
- AnalysisRespond.nSendCount,AnalysisRespond.nSendCount,AnalysisRespond.nSendCount, pRtn, CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"), atol(id));
- //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) );
- }
- else
- {
- // 返回其他值,表示有异常。此处只处理返回0的结果;
- // 扣费正常执行,不修改msgcount的值;
- log = pRtn;
- 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) );
- }
- step=11;
- if(MyExecuteSQL(&g_db2, sql)==0)
- {
- WriteLogin("保存发送记录失败2!");
- }
- step=12;
- ::Sleep (100);
- }
- #endif
- }
- else
- {
- ::Sleep (6000);
- }
- }
- }
- catch(...)
- {
- CString str;
- str.Format("step:%d", step);
- /* if(bSendTypeUnicom!=2)
- WriteLogin("发送出错,北京维那!"+str);
- else*/
- WriteLogin("发送出错!"+str);
- goto ll;
- }
- pDlg->m_bRunning=false;
- pDlg->m_bTerminate=false;
- _endthreadex( 0 ); // Jeff.调用了_endthreadex(0)退出后,下面的代码就不会执行;
- pDlg->m_hThread=NULL;
- return 0;
- }
- void BakData(CString savedir)
- {
- char server[50];
- DWORD leng=50;
- memset(server, 0, 50);
- ::GetComputerName (server, &leng);
- CString localname=server;
- CDatabase g_masterdb;
- try
- {
- CString strCon;
- if (Global::g_dwDBServerPort != 0)
- {
- if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
- strCon.Format(DB_SW_CONN_WITH_PORT, Global::g_szDBSource, Global::g_dwDBServerPort,_T("master"));
- else
- strCon.Format(DB_SS_CONN_WITH_PORT,Global::g_szDBSource, Global::g_dwDBServerPort, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
- }
- else
- {
- if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
- strCon.Format(DB_SW_CONN_WITHOUT_PORT, Global::g_szDBSource, _T("master"));
- else
- strCon.Format(DB_SS_CONN_WITHOUT_PORT,Global::g_szDBSource, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
- }
- g_masterdb.OpenEx(strCon,CDatabase::noOdbcDialog);
- }
- catch(CDBException * e)
- {
- }
- try
- {
- CTime tm=CTime::GetCurrentTime ();
- CTimeSpan dt(1, 0, 0, 0);
- CTime tm2;
- tm2=tm;
- CString savepath;
- savepath.Format("%s\\%s(sql).bak", savedir, tm2.Format ("%Y%m%d") );
- BOOL bBak=0;
- BOOL bBak2=0;
- if(::PathFileExists (savepath)==0)
- {
- g_masterdb.SetQueryTimeout(600);
- {
- CString sql;
- sql.Format("BACKUP DATABASE dbmsg TO DISK='%s' WITH FORMAT", savepath);
- try
- {
- g_masterdb.ExecuteSQL (sql);
- bBak=1;
- }
- catch(CDBException * e)
- {
- WriteLogin(e->m_strError);
- WriteLogin("备份失败!");
- }
- }
- g_masterdb.SetQueryTimeout(10);
- }
- if(bBak)
- {
- CTimeSpan dt2(15, 0, 0, 0);
- CTimeSpan dt3(365, 0, 0, 0);
- CTime tm3=tm-dt2;
- CTime tm4=tm-dt3;
- while(tm3>tm4)
- {
- savepath.Format("%s\\%s.bak", savedir, tm3.Format ("%Y%m%d") );
- #ifdef SQLSERVER_VERSION
- savepath.Format("%s\\%s(sql).bak", savedir, tm3.Format ("%Y%m%d") );
- #endif
- if(!::PathFileExists (savepath))
- break;
- ::DeleteFile (savepath);
- tm3-=dt;
- }
- }
- }
- catch(...)
- {
- WriteLogin("出错在函数BakData2中");
- }
- g_masterdb.Close ();
- }
- BOOL CLYFZSendMsgApp::InitInstance()
- {
- HANDLE hObject = CreateMutex(NULL,FALSE,_T("CLYFZSendMxxsgAppxiao2"));
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- WriteLogin("已存在进程");
- return false;
- }
- char path[MAX_PATH];
- ::GetModuleFileName (NULL, path, MAX_PATH);
- g_mainpath=path;
- g_mainpath=g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bRunning=true;
- WriteLogin("开始启动");
- AfxEnableControlContainer();
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- //g_listctrlfont.CreatePointFont (110, _T("System"));
- g_listctrlfont.CreatePointFont (110, _T("System"));
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- SetRegistryKey(_T("LYFZ-MSGSend"));
- // 1.设定使用的短信服务商;
- CString version = _T ("Version 1.0");
- g_bMsgRoad=GetProfileInt (version, "msgroad", 1);
- g_bMsgRoad=1;//吉信通
- g_bMsgRoadtemp=g_bMsgRoad;
- g_bDebug=GetProfileInt (version, "debug", 0);
- if(g_bDebug==0)
- {
- CString autorunpath=g_mainpath+"\\AutoRun2.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_SHOWNORMAL);
- CString sendpath=g_mainpath+"\\AutoRun3.exe";
- ShellExecute(NULL, _T("open"), sendpath, NULL, NULL, SW_SHOWNORMAL);
- }
- // 2.连接数据库;
- BOOL bMasterDb=0;
- BOOL bUserDb=0;
- char server[50];
- DWORD leng=50;
- memset(server, 0, 50);
- ::GetComputerName (server, &leng);
- CString localname=server;
- Global::GetIniInfo();
- CDatabase g_masterdb;
- ll: try
- {
- CString strCon;
- if (Global::g_dwDBServerPort != 0)
- {
- if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
- strCon.Format(DB_SW_CONN_WITH_PORT, Global::g_szDBSource, Global::g_dwDBServerPort,_T("master"));
- else
- strCon.Format(DB_SS_CONN_WITH_PORT,Global::g_szDBSource, Global::g_dwDBServerPort, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
- }
- else
- {
- if ( _tcscmp(Global::g_szDBAccount, _T("")) == 0 )
- strCon.Format(DB_SW_CONN_WITHOUT_PORT, Global::g_szDBSource, _T("master"));
- else
- strCon.Format(DB_SS_CONN_WITHOUT_PORT,Global::g_szDBSource, _T("master"), Global::g_szDBAccount, Global::g_szDBPassWord);
- }
- g_masterdb.OpenEx(strCon,CDatabase::noOdbcDialog);
- bMasterDb=1;
- }
- catch(CDBException * e)
- {
- }
- if(bMasterDb==0)
- {
- WriteLogin("sql数据库未启动!");
- ::Sleep (1000);
- goto ll;
- }
- try
- {
- g_db.OpenEx(Global::g_szConnectString,CDatabase::noOdbcDialog);
- bUserDb=1;
- g_curdb=&g_db;
- g_masterdb.Close();
- char server[50];
- DWORD leng=50;
- memset(server, 0, 50);
- ::GetComputerName (server, &leng);
- CString localname=server;
- CString savedir="\\\\"+localname+"\\短信平台备份";
- BakData(savedir);
- savedir=g_mainpath+"\\短信客户资料备份";
- if(!::PathFileExists (savedir))
- ::CreateDirectory (savedir, NULL);
- BakData(savedir);
- }
- catch(CDBException * e)
- {
- WriteLogin("数据库连接失败-"+e->m_strError);
- e->Delete();
- ::Sleep (1000);
- goto ll;
- }
- try
- {
- g_db2.OpenEx(Global::g_szConnectString,CDatabase::noOdbcDialog);
- }
- catch(CDBException * e)
- {
- WriteLogin("数据库连接失败-"+e->m_strError);
- e->Delete();
- ::Sleep (1000);
- goto ll;
- }
- try
- {
- g_db3.OpenEx(Global::g_szConnectString,CDatabase::noOdbcDialog);
- }
- catch(CDBException * e)
- {
- WriteLogin("数据库连接失败-"+e->m_strError);
- e->Delete();
- ::Sleep (1000);
- goto ll;
- }
- g_db.SetQueryTimeout(60*2);
- g_db2.SetQueryTimeout(60*2);
- g_db3.SetQueryTimeout(60*2);
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
- if(g_bMsgRoad==0)
- {
- g_hDll = ::LoadLibrary(g_mainpath+"\\LYFZGateway.dll");
- if (NULL == g_hDll)
- {
- WriteLogin("加载dll失败");
- return 0;
- }
- MongateChangePwd = (FnMongateChangePwd)::GetProcAddress(g_hDll, "MongateChangePwd");
- MongateConnect = (FnMongateConnect)::GetProcAddress(g_hDll, "MongateConnect");
- MongateDisconnect = (FnMongateDisconnect)::GetProcAddress(g_hDll, "MongateDisconnect");
- MongateCsGetSms = (FnMongateCsGetSms)::GetProcAddress(g_hDll, "MongateCsGetSms");
- MongateVasGetSms = (FnMongateVasGetSms)::GetProcAddress(g_hDll, "MongateVasGetSms");
- MongateGetVer = (FnMongateGetVer)::GetProcAddress(g_hDll, "MongateGetVer");
- MongateTestConn = (FnMongateTestConn)::GetProcAddress(g_hDll, "MongateTestConn");
- MongateQueryBalance = (FnMongateQueryBalance)::GetProcAddress(g_hDll, "MongateQueryBalance");
- MongateVasSendSms = (FnMongateVasSendSms)::GetProcAddress(g_hDll, "MongateVasSendSms");
- MongateSendSms = (FnMongateSendSms)::GetProcAddress(g_hDll, "MongateSendSms");
- MongateQueryUsed = (FnMongateQueryUsed)::GetProcAddress(g_hDll, "MongateQueryUsed");
- MongateCsSendSms = (FnMongateCsSendSms)::GetProcAddress(g_hDll, "MongateCsSendSms");
- MongateCsGetStatusReport = (FnMongateCsGetStatusReport)::GetProcAddress(g_hDll, "MongateCsGetStatusReport");
- MongateConnectSocks4Proxy = (FnMongateConnectSocks4Proxy)::GetProcAddress(g_hDll, "MongateConnectSocks4Proxy");
- MongateConnectSocks5Proxy = (FnMongateConnectSocks5Proxy)::GetProcAddress(g_hDll, "MongateConnectSocks5Proxy");
- MongateConnectHttpProxy = (FnMongateConnectHttpProxy)::GetProcAddress(g_hDll, "MongateConnectHttpProxy");
- MongateTestMsgEx = (FnMongateTestMsgEx)::GetProcAddress(g_hDll, "MongateTestMsgEx");
- MongateTestMsgExHttp =(FnMongateTestMsgExHttp)::GetProcAddress(g_hDll, "MongateTestMsgExHttp");
- MongateQueryBalanceHttp = (FnMongateQueryBalance)::GetProcAddress(g_hDll, "MongateQueryBalanceHttp");
- MongateQueryUsedHttp = (FnMongateQueryUsed)::GetProcAddress(g_hDll, "MongateQueryUsedHttp");
- MongateConnectHttp = (FnMongateConnect)::GetProcAddress(g_hDll, "MongateConnectHttp");
- MongateCsSendSmsHttp = (FnMongateCsSendSms)::GetProcAddress(g_hDll, "MongateCsSendSmsHttp");
- MongateCsGetSmsHttp = (FnMongateCsGetSmsHttp)::GetProcAddress(g_hDll, "MongateCsGetSmsHttp");
- MongateCsGetStatusReportHttp = (FnMongateCsGetStatusReport)::GetProcAddress(g_hDll, "MongateCsGetStatusReportHttp");
- MongateChangePwdHttp = (FnMongateChangePwd)::GetProcAddress(g_hDll, "MongateChangePwdHttp");
- MongateTestConnHttp = (FnMongateTestConnHttp)::GetProcAddress(g_hDll, "MongateTestConnHttp");
- MongateConnectHttpProxy = (FnMongateConnectHttpProxy)::GetProcAddress(g_hDll, "MongateConnectHttpProxy");
- MongateCsSPSendSmsNew = (FnMongateCsSPSendSmsNew)::GetProcAddress(g_hDll, "MongateCsSPSendSmsNew");
- }
- g_titlefont.CreatePointFont (160, _T("宋体"));
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_MAINFRAME,
- NULL,
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CLYFZSendMsgView));
- AddDocTemplate(pDocTemplate);
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- {
- WriteLogin("窗口初始化失败");
- return FALSE;
- }
- m_pMainWnd = pMainFrame;
- if(g_bMsgRoad==0)
- m_pMainWnd->SetWindowText ("利亚方舟短信发送管理系统--南海短信");
- else if(g_bMsgRoad==1)
- m_pMainWnd->SetWindowText ("利亚方舟短信发送管理系统--吉信通");
- else if(g_bMsgRoad==2)
- m_pMainWnd->SetWindowText ("利亚方舟短信发送管理系统--商务通");
- m_pMainWnd->UpdateWindow();
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- // No message handlers
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // App command to run the dialog
- void CLYFZSendMsgApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CLYFZSendMsgApp message handlers
- CString newGUID()
- {
- CString str;
- GUID guid;
- CoInitialize(NULL);
- if (S_OK == ::CoCreateGuid(&guid))
- {
- str.Format (
- "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
- guid.Data1,
- guid.Data2,
- guid.Data3,
- guid.Data4[0], guid.Data4[1],
- guid.Data4[2], guid.Data4[3],
- guid.Data4[4], guid.Data4[5],
- guid.Data4[6], guid.Data4[7]);
- }
- CoUninitialize();
- return str.Left (28);
- }
- void ConvertToPrice(CString &str)
- {
- if(str.Find ('.')==-1)return;
- str.TrimRight ('0');
- str.TrimRight ('.');
- }
- BOOL IsHasRights(int pos)
- {return 1;
- if(g_user.rights.GetLength ()>pos)
- {
- BOOL ret=atoi(g_user.rights.Mid (pos,1));
- if(ret==0)AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
- return ret;
- }
- AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
- return 0;
- }
- BOOL IsHasRights2(int pos)
- {return 1;
- if(g_user.rights.GetLength ()>pos)
- {
- BOOL ret=atoi(g_user.rights.Mid (pos,1));
- return ret;
- }
- return 0;
- }
- BOOL IsHasRightsnew(int pos)
- {
- if(g_user.rights.GetLength ()>pos)
- {
- BOOL ret=atoi(g_user.rights.Mid (pos,1));
- if(ret==0)AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
- return ret;
- }
- AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
- return 0;
- }
- BOOL IsHasRights2new(int pos)
- {
- if(g_user.rights.GetLength ()>pos)
- {
- BOOL ret=atoi(g_user.rights.Mid (pos,1));
- return ret;
- }
- return 0;
- }
- int CLYFZSendMsgApp::ExitInstance()
- {
- // TODO: Add your specialized code here and/or call the base class
- if (m_hsock != 0)
- MongateDisconnect(m_hsock);
- if(g_hDll)
- ::FreeLibrary (g_hDll);
- try
- {
- g_db.Close ();
- return CWinApp::ExitInstance();
- }
- catch(...)
- {
- }
- //g_tMainCtrl.StopServer();
- //Transport_UnInit();
- return CWinApp::ExitInstance();
- }
- void LoadImageFromBuf(Bitmap **img, BYTE *pData, DWORD leng)
- {
- try
- {
- if(pData==NULL)return;
- if(*img)delete *img;
- *img=NULL;
- // Allocate global memory on which to create stream
- HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
- if(m_hMem==NULL)return;
- BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
- memcpy(pmem,pData,leng);
- IStream* pstm;
- CreateStreamOnHGlobal(m_hMem,TRUE,&pstm);
- // load from stream
- *img=Gdiplus::Bitmap::FromStream(pstm);
- // free/release stuff
- GlobalUnlock(m_hMem);
- pstm->Release();
- }
- catch(...)
- {
- }
- }
- void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)
- {
- try
- {
- if(pData==NULL)return;
- if(*img)delete *img;
- *img=NULL;
- // Allocate global memory on which to create stream
- HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
- if(m_hMem==NULL)return;
- BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
- memcpy(pmem,pData,leng);
- IStream* pstm;
- CreateStreamOnHGlobal(m_hMem,TRUE,&pstm);
- // load from stream
- *img=Gdiplus::Image::FromStream(pstm);
- // free/release stuff
- GlobalUnlock(m_hMem);
- pstm->Release();
- }
- catch(...)
- {
- }
- }
- void LoadImageFromBuf(Image **img, CString path)
- {
- try
- {
- CFile fp;
- if(fp.Open (path, CFile::modeRead))
- {
- DWORD leng=fp.GetLength ();
- BYTE *pData=new BYTE[leng];
- fp.Read (pData, leng);
- fp.Close ();
- LoadImageFromBuf(img, pData, leng);
- delete []pData;
- }
- }
- catch(...)
- {
- }
- }
- void LoadImageFromBuf(Bitmap **img, CString path)
- {
- try
- {
- CFile fp;
- if(fp.Open (path, CFile::modeRead))
- {
- DWORD leng=fp.GetLength ();
- BYTE *pData=new BYTE[leng];
- fp.Read (pData, leng);
- fp.Close ();
- LoadImageFromBuf(img, pData, leng);
- delete []pData;
- }
- }
- catch(...)
- {
- }
- }
- int GetType(CString str)
- {
- BOOL bDigit=1;
- BOOL bAlpha=1;
- for(int i=0; i<str.GetLength (); i++)
- {
- // if(!::isdigit (str.GetAt (i)))
- if(! ((str.GetAt (i)<=0 && str.GetAt (i)>=9) ))
- bDigit=0;
- if(! ((str.GetAt (i)<='z' && str.GetAt (i)>='a') || (str.GetAt (i)<='Z' && str.GetAt (i)>='A')))
- //else if(!::isalpha ( ((unsigned char)str.GetAt (i))))
- bAlpha=0;
- if(bDigit==0 && bAlpha==0)return 0;
- }
- if(bDigit)
- {
- return 1;
- }
- else if(bAlpha)
- {
- return 2;
- }
- else
- return 0;
- }
- void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
- {
- try
- {
- HGLOBAL hGlobal = NULL;
- HRSRC hSource = NULL;
- LPVOID lpVoid = NULL;
- int nSize = 0;
- BOOL bResult=FALSE;
- hSource = FindResource(NULL, lpszResourceName, ResourceType);
- if(hSource == NULL)return;
- hGlobal = LoadResource(NULL, hSource);
- if(hGlobal == NULL)return;
- lpVoid = LockResource(hGlobal);
- if(lpVoid == NULL)return;
- nSize = (UINT)SizeofResource(NULL, hSource);
- LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
- UnlockResource(hGlobal); // 16Bit Windows Needs This
- FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
- }
- catch(...)
- {
- }
- }
- CString FilterBZ(CString &bz)
- {
- bz.Replace ("'", "");
- /* int i=bz.GetLength ()-1;
- char c;
- for(;i>=0;i--)
- {
- c=bz.GetAt (i);
- if(c<32)// && c!=10 && c!=13)
- bz.Delete (i);
- }*/
- if(bz.GetLength ()>1023)
- {
- AfxMessageBox("文字太长, 字符串将被截取!", MB_ICONSTOP);
- bz=bz.Left (1023);
- }
- return bz;
- }
- BOOL GIsHalfHZ(const CString &str)
- {
- int len=str.GetLength();
- BOOL IsHalf=FALSE;
- for(int i=0;i<len;i++)
- {
- if(str.GetAt(i) < 0) IsHalf=!IsHalf;
- }
- return IsHalf;
- }
- void RectFitDes(int width, int height, CRect &rc)
- {
- try
- {
- if(width==0 || height==0)return;
- float fscale=(float)width/(float)height;
- float rcscale=((float)rc.Width ())/((float)rc.Height ());
- int rcwid=rc.Width ();
- int rchei=rc.Height ();
- int dt=0;
- if(rcscale<fscale)
- {
- dt=(rchei-rcwid/fscale)/2;
- rc.top+=dt;
- rc.bottom-=dt;
- }
- else
- {
- dt=(rcwid-rchei*fscale)/2;
- rc.left +=dt;
- rc.right-=dt;
- }
- }
- catch(...)
- {
- }
- }
- int GetPos(DWORD leng)
- {
- if(g_lengarray.GetSize()==0)
- {
- g_sendhead.bsql=0;
- g_sendhead.code[0]=105;
- g_sendhead.tabcount=1;
- g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return -1;
- DWORD leng;
- DWORD readbytes=0;
- memcpy(&leng, g_pData+readbytes, sizeof(DWORD));
- readbytes+=sizeof(DWORD);
- {
- CMemFile memfile;
- memfile.Attach (g_pData+readbytes, leng);
- readbytes+=leng;
- CArchive ar(&memfile, CArchive::load);
- g_lengarray.Serialize (ar);
- ar.Close();
- memfile.Detach ();
- }
- memcpy(&leng, g_pData+readbytes, sizeof(DWORD));
- readbytes+=sizeof(DWORD);
- {
- CMemFile memfile;
- memfile.Attach (g_pData+readbytes, leng);
- readbytes+=leng;
- CArchive ar(&memfile, CArchive::load);
- g_btnlengarray.Serialize (ar);
- ar.Close();
- memfile.Detach ();
- }
- memcpy(&leng, g_pData+readbytes, sizeof(DWORD));
- readbytes+=sizeof(DWORD);
- int count=leng/sizeof(RESDATA2);
- for(int i=0; i<count; i++)
- {
- BYTE *pData=new BYTE[sizeof(RESDATA2)];
- memcpy(pData, g_pData+readbytes, sizeof(RESDATA2));
- readbytes+=sizeof(RESDATA2);
- g_pointerarray.Add(pData);
- /* RESDATA2 *pRes=(RESDATA2*)pData;
- CString str;
- str.Format ("%d", pRes->nPicBmpCount [0]);
- AfxMessageBox(str);
- str.Format ("%d", pRes->nPicBmpCount [1]);
- AfxMessageBox(str);
- str.Format ("%d", pRes->nPicBmpCount [2]);
- AfxMessageBox(str);
- str.Format ("%d", pRes->nPicBmpCount [3]);
- AfxMessageBox(str);
- str.Format ("%d", pRes->nPicBmpCount [4]);
- AfxMessageBox(str);
- str.Format ("%d", pRes->nPicBmpCount [5]);
- AfxMessageBox(str);*/
- }
- }
- for(int i=0; i<g_lengarray.GetSize (); i++)
- {
- if(leng==g_lengarray.ElementAt (i))
- {
- return i;
- }
- }
- return -1;
- }
- extern RESDATA2 g_resdata2;
- BOOL LoadLia(CString path, BYTE **pData, BYTE **pDataBegin, Image **pBk, HWND hwnd)
- {
- return 0;
- }
- BOOL CheckDateOK(CString str)
- {
- if(str.IsEmpty ())return 1;
- CString tip;
- int i;
- CString demo=CTime::GetCurrentTime ().Format ("%Y-%m-%d");
- if(str.GetLength ()!=demo.GetLength ())
- goto ll;
- //2009-01-01
- if(str.GetAt (4)!='-')
- goto ll;
- if(str.GetAt (7)!='-')
- goto ll;
- for( i=0; i<str.GetLength (); i++)
- {
- if(i==4 || i==7)continue;
- if(str.GetAt (i)<'0' || str.GetAt (i)>'9')
- goto ll;
- }
- return 1;
- ll:
- tip.Format ("日期:%s格式错误!\r\n样板:%s", str, demo);
- AfxMessageBox(tip, MB_ICONSTOP);
- return 0;
- }
- int GetOrientation(Image *image)
- {
- if(image )
- {
- UINT totalBufferSize;
- UINT numProperties;
- image->GetPropertySize(&totalBufferSize, &numProperties);
- // Allocate the buffer that will receive the property items.
- PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
- // Fill the buffer.
- image->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
- // Print the id data member of each property item.
- for(UINT j = 0; j < numProperties; ++j)
- {
- if(PropertyTagOrientation==pAllItems[j].id)
- {
- short* ptrLong = (short*)(pAllItems[j].value);
- int ret=(int)*ptrLong;
- free(pAllItems);
- return ret;
- //str.Format("%d", *ptrLong);
- //MessageBox(str);
- }
- }
- free(pAllItems);
- }
- return 1;
- }
- int CLYFZSendMsgApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
- {
- // TODO: Add your specialized code here and/or call the base class
- return CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
- }
- void WriteLogin(CString str)
- {
- CStdioFile fp;
- CString path=g_mainpath+"\\短信平台日志.txt";
- if(::PathFileExists (path))
- {
- fp.Open (path, CFile::modeWrite);
- int length=fp.GetLength ();
- if(length>1024*1024)
- {
- fp.Close ();
- ::DeleteFile (path);
- return;
- }
- fp.SeekToEnd ();
- }
- else
- fp.Open (path, CFile::modeCreate|CFile::modeWrite);
- fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
- fp.Close ();
- }
- void WriteLogin2(CString str)
- {
- CStdioFile fp;
- CString path=g_mainpath+"\\短信平台日志2.txt";
- if(::PathFileExists (path))
- {
- fp.Open (path, CFile::modeWrite);
- int length=fp.GetLength ();
- if(length>1024*1024)
- {
- fp.Close ();
- ::DeleteFile (path);
- return;
- }
- fp.SeekToEnd ();
- }
- else
- fp.Open (path, CFile::modeCreate|CFile::modeWrite);
- fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
- fp.Close ();
- }
- BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword)
- {
- try
- {
- HCRYPTPROV hCryptProv;
- HCRYPTKEY hKey;
- HCRYPTHASH hHash;
- PBYTE pbBuffer;
- DWORD dwBlockLen;
- DWORD dwBufferLen;
- DWORD dwCount;
- //以下获得一个CSP句柄
- if(CryptAcquireContext(
- &hCryptProv,
- NULL, //NULL表示使用默认密钥容器,默认密钥容器名为用户登陆名
- NULL,
- PROV_RSA_FULL,
- 0))
- {
- printf("A cryptographic provider has been acquired. \n");
- }
- else//密钥容器不存在
- {
- if(CryptAcquireContext(
- &hCryptProv,
- NULL,
- NULL,
- PROV_RSA_FULL,
- CRYPT_NEWKEYSET))//创建密钥容器
- {
- //创建密钥容器成功,并得到CSP句柄
- printf("A new key container has been created.\n");
- }
- else
- {
- return 0;
- }
- }
- //--------------------------------------------------------------------
- // 创建一个会话密钥(session key)
- // 会话密钥也叫对称密钥,用于对称加密算法。
- // (注: 一个Session是指从调用函数CryptAcquireContext到调用函数
- // CryptReleaseContext 期间的阶段。)
- //--------------------------------------------------------------------
- // Create a hash object.
- if(CryptCreateHash(
- hCryptProv,
- CALG_MD5,
- 0,
- 0,
- &hHash))
- {
- printf("A hash object has been created. \n");
- }
- else
- {
- return 0;
- }
- //--------------------------------------------------------------------
- // 用输入的密码产生一个散列
- if(CryptHashData(
- hHash,
- (BYTE *)szPassword,
- strlen(szPassword),
- 0))
- {
- printf("The password has been added to the hash. \n");
- }
- else
- {
- return 0;
- }
- //--------------------------------------------------------------------
- // 通过散列生成会话密钥(session key)
- if(CryptDeriveKey(
- hCryptProv,
- ENCRYPT_ALGORITHM,
- hHash,
- KEYLENGTH,
- &hKey))
- {
- printf("An encryption key is derived from the password hash. \n");
- }
- else
- {
- return 0;
- }
- //--------------------------------------------------------------------
- // Destroy the hash object.
- CryptDestroyHash(hHash);
- hHash = NULL;
- //--------------------------------------------------------------------
- // The session key is now ready.
- //--------------------------------------------------------------------
- // 因为加密算法是按ENCRYPT_BLOCK_SIZE 大小的块加密的,所以被加密的
- // 数据长度必须是ENCRYPT_BLOCK_SIZE 的整数倍。下面计算一次加密的
- // 数据长度。
- dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
- //--------------------------------------------------------------------
- // Determine the block size. If a block cipher is used,
- // it must have room for an extra block.
- if(ENCRYPT_BLOCK_SIZE > 1)
- dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
- else
- dwBufferLen = dwBlockLen;
- dwCount=dwBufferLen;
- //--------------------------------------------------------------------
- // In a do loop, encrypt the source file and write to the source file.
- int count;
- // if(leng%dwBlockLen==0)
- count=leng/dwBufferLen;
- // else
- // count=leng/dwBlockLen+1;
- int i;
- for( i=0; i<count; i++)
- {
- pbBuffer=buffer+i*dwBufferLen;
- // 加密数据
- if(!CryptEncrypt(
- hKey, //密钥
- 0, //如果数据同时进行散列和加密,这里传入一个散列对象
- 0, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE.
- //这里通过判断是否到文件尾来决定是否为最后一块。
- 0, //保留
- pbBuffer, //输入被加密数据,输出加密后的数据
- &dwCount, //输入被加密数据实际长度,输出加密后数据长度
- dwBufferLen)) //pbBuffer的大小。
- {
- return 0;
- }
- }
- if(leng%dwBlockLen)
- {
- pbBuffer=buffer+i*dwBufferLen;
- dwCount=leng-i*dwBufferLen;
- if(!CryptEncrypt(
- hKey, //密钥
- 0, //如果数据同时进行散列和加密,这里传入一个散列对象
- TRUE, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE.
- //这里通过判断是否到文件尾来决定是否为最后一块。
- 0, //保留
- pbBuffer, //输入被加密数据,输出加密后的数据
- &dwCount, //输入被加密数据实际长度,输出加密后数据长度
- dwBufferLen)) //pbBuffer的大小。
- {
- return 0;
- }
- }
- //--------------------------------------------------------------------
- // Destroy session key.
- if(hKey)
- CryptDestroyKey(hKey);
- //--------------------------------------------------------------------
- // Destroy hash object.
- if(hHash)
- CryptDestroyHash(hHash);
- //--------------------------------------------------------------------
- // Release provider handle.
- if(hCryptProv)
- CryptReleaseContext(hCryptProv, 0);
- return(TRUE);
- }
- catch(...)
- {
- }
- }
- BOOL CLYFZSendMsgApp::TerminateThread()
- {
- try
- {
- if ( !m_bRunning )
- return TRUE;
- m_bTerminate=true;
- for(int i=0; i<10; i++)
- {
- if(m_bRunning==0)break;
- ::Sleep (1000);
- }
- if(m_hThread)
- {
- ::TerminateThread (m_hThread, 0);
- ::CloseHandle(m_hThread);
- }
- /* for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
- break;
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread); */
- m_bRunning=false;
- return TRUE;
- }
- catch(...)
- {
- WriteLogin("出错在函数TerminateThread中");
- }
- try
- {
- if ( !m_bRunning2 )
- return TRUE;
- m_bTerminate2=true;
- for(int i=0; i<10; i++)
- {
- if(m_bRunning2==0)break;
- ::Sleep (1000);
- }
- if(m_hThread2)
- {
- ::TerminateThread (m_hThread2, 0);
- ::CloseHandle(m_hThread2);
- }
- m_bRunning2=false;
- return TRUE;
- }
- catch(...)
- {
- WriteLogin("出错在函数TerminateThread2中");
- }
- }
- //把utf8转成unicode,再转成cstring
- void ConvertUTF8ToANSI(char* strUTF8,CString &strANSI) //
- {
- int nLen = ::MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,(LPCTSTR)strUTF8,-1,NULL,0); //返回需要的unicode长度
- WCHAR * wszANSI = new WCHAR[nLen+1];
- memset(wszANSI, 0, nLen * 2 + 2);
- nLen = MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUTF8, -1, wszANSI, nLen); //把utf8转成unicode
- nLen = WideCharToMultiByte(CP_ACP, 0, wszANSI, -1, NULL, 0, NULL, NULL); //得到要的ansi长度
- char *szANSI=new char[nLen + 1];
- memset(szANSI, 0, nLen + 1);
- WideCharToMultiByte (CP_ACP, 0, wszANSI, -1, szANSI, nLen, NULL,NULL); //把unicode转成ansi
- strANSI = szANSI;
- delete wszANSI;
- delete szANSI;
- }
- BOOL g_bReceiveRoad2=1;
- CString GetReceiveMsg()
- {
- CHttpClient conn;
- CString value="http://121.52.221.108/send/readxmlsmsconfig.aspx?name=lyfzrj&pwd=lyfzrj123";
- if(g_bReceiveRoad2)
- value="http://121.52.221.108/send/readxmlsmsconfig.aspx?name=lyfzrj1&pwd=lyfz1234";
- return conn.doGet(value);
- }
- BOOL IsExistReceiveMsg(CString id)
- {
- CRecordset myset(&g_db3);
- CString sql="select count(*) as cot from receivemsg where id='"+id+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- myset.GetFieldValue ("cot", sql);
- myset.Close();
- return atoi(sql);
- }
- void DelExistReceiveMsg(CString id)
- {
- CHttpClient conn;
- CString value="http://121.52.221.108/send/configupsms.aspx?name=lyfzrj&pwd=lyfzrj123&ids="+id;
- if(g_bReceiveRoad2)
- value="http://121.52.221.108/send/configupsms.aspx?name=lyfzrj1&pwd=lyfz1234&ids="+id;
- conn.doGet(value);
- }
- // 接收短信内容线程;
- unsigned __stdcall ReceiveMsgThread(LPVOID lpParam)
- {
- CLYFZSendMsgApp *pDlg=(CLYFZSendMsgApp*)lpParam;
- try
- {
- CString sql,str,id,phone,content,datetime,delid,strbak;
- str="&";
- int leng=str.GetLength ();
- str="2013-04-12 11:35:28";
- int leng2=str.GetLength ();
- int pos;
- while(1)
- {
- // WriteLogin("查回复!");
- CRecordset myset(&g_db3);
- myset.Open (CRecordset::forwardOnly, "SELECT phone FROM [dbmsg].[dbo].[receivemsg] where account is null");
- while(!myset.IsEOF())
- {
- myset.GetFieldValue ("phone", str);
- sql.Format("update [receivemsg] set account=(select top 1 account from sendreg where [phones] like '%s' order by [timestamp2] desc\
- ) where [phone]='%s'", "%"+str+"%", str);
- MyExecuteSQL(&g_db3, sql);
- sql.Format("update [receivemsg] set account='未找到' where [phone]='%s' and account is null", str);
- MyExecuteSQL(&g_db3, sql);
- myset.MoveNext();
- }
- myset.Close();
- str="";
- g_bReceiveRoad2=!g_bReceiveRoad2;
- str=GetReceiveMsg();
- if(str.Find("||||")==-1)
- {
- WriteLogin("回复返回");
- ::Sleep (10000);
- continue;
- }
- str.TrimRight ();
- CString finder="||||";
- if(str.Right (finder.GetLength ())==finder)str=str.Left (str.GetLength ()-finder.GetLength ());
- CStringArray strarray;
- pos=str.Find (finder);
- if(pos==-1)
- {
- strarray.Add (str);
- }
- else
- {
- while(pos!=-1)
- {
- strarray.Add ( str.Left (pos));
- str=str.Right (str.GetLength ()-pos-finder.GetLength ());
- pos=str.Find (finder);
- }
- strarray.Add (str);
- }
- delid="";
- for(int i=0; i<strarray.GetSize (); i++)
- {
- if(delid!="")
- {
- if(delid.Right (1)==";")
- delid=delid.Left (delid.GetLength ()-1);
- DelExistReceiveMsg(delid);delid="";
- }
- str=strarray.ElementAt (i);
- str.Replace("&sequeid=12345", "");
- strbak=str;
- // WriteLogin("开始:"+str);
- pos=str.Find ("&");
- if(pos==-1)
- {
- ::Sleep (5000);WriteLogin("回复返回2:"+strbak);
- continue;
- }
- id=str.Left (pos);id.TrimLeft ("id=");
- id.TrimLeft ();
- delid+=id+";";
- str=str.Right (str.GetLength ()-pos-leng);
- pos=str.Find ("&");
- if(pos==-1)
- {
- ::Sleep (5000);WriteLogin("回复返回3:"+strbak);
- continue;
- }
- str=str.Right (str.GetLength ()-pos-leng);
- pos=str.Find ("&");
- if(pos==-1)
- {
- ::Sleep (5000);WriteLogin("回复返回4:"+strbak);
- continue;
- }
- phone=str.Left (pos);phone.TrimLeft ("src=");
- str=str.Right (str.GetLength ()-pos-leng);
- pos=str.Find ("&");
- if(pos==-1)
- {
- ::Sleep (5000);WriteLogin("回复返回5:"+strbak);
- continue;
- }
- content=str.Left (pos);content.TrimLeft ("msg=");
- str=str.Right (str.GetLength ()-pos-leng);
- pos=str.ReverseFind ('&');
- if(pos==-1)
- {
- ::Sleep (5000);WriteLogin("回复返回6:"+strbak);
- continue;
- }
- datetime=str.Right (str.GetLength ()-pos-leng);datetime.TrimLeft ("time=");
- datetime.TrimRight ();
- if(datetime.GetLength ()!=leng2)
- { WriteLogin("回复返回7"+datetime+strbak);
- ::Sleep (5000);
- continue;
- }
- if(IsExistReceiveMsg(id))
- {
- WriteLogin("回复返回8:"+strbak);
- if(delid!="")
- {
- if(delid.Right (1)==";")
- delid=delid.Left (delid.GetLength ()-1);
- DelExistReceiveMsg(delid);delid="";
- }
- continue;
- }
- content.Replace ("'", "");
- content.Replace ("^", "");
- str="insert into receivemsg([id],[phone],[content],[datetime]) values('"+id+"','"+phone+"','"+content+"','"+datetime+"')";
- if(MyExecuteSQL(&g_db3, str)==0)
- {
- WriteLogin("保存回复记录失败!");
- ::Sleep (5000);
- continue;
- }::Sleep (5000);
- if(delid!="")
- {
- if(delid.Right (1)==";")
- delid=delid.Left (delid.GetLength ()-1);
- DelExistReceiveMsg(delid);delid="";
- }
- }
- //删除
- if(delid!="")
- {
- if(delid.Right (1)==";")
- delid=delid.Left (delid.GetLength ()-1);
- DelExistReceiveMsg(delid);
- }
- ::Sleep (5000);
- }
- }
- catch(...)
- {
- }
- pDlg->m_bRunning2=false;
- pDlg->m_bTerminate2=false;
- _endthreadex( 0 ); pDlg->m_hThread2=NULL;
- WriteLogin("回复线程关闭!");
- return 0;
- }
- void CLYFZSendMsgApp::RunThread()
- {
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bRunning=true;
- m_hThread = (HANDLE)_beginthreadex(NULL,0, SendMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
- return;
- m_bTerminate2=false;
- m_bRunning2=false;
- m_hThread2 = NULL;
- m_bRunning2=true;
- m_hThread2 = (HANDLE)_beginthreadex(NULL,0, ReceiveMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
- }
- //发送出错
- /*
- 移动:
- 139,138,137,136,135,134,159,158,152,151,150,157,188,187,144
- 联通:
- 130,131,132,155,156,186,185
- 电信:
- 133,153,189,180
- */
- //------------------------------------------------------------------------------
- // Remark by Jeff;
- // 函数:CheckPhoneType
- // 描述:判断手机号属于哪个运营商的;
- // 参数:
- // phoneno: 欲判断的手机号;
- //
- // 返回:返回0表示移动; 1表示联通; 2表示电信; 3表示小灵通; -1表示未知的;
- //
- // 注意:
- //
- //------------------------------------------------------------------------------
- int CheckPhoneType(CString phoneno)
- {
- int i;
- if(phoneno.IsEmpty ())return -1;
- for( i=0; i<phoneno.GetLength (); i++)
- {
- if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
- }
- if(phoneno.GetAt (0)=='1')
- {
- if(phoneno.GetLength ()!=11)
- return -1;
- int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144,182,147,183,184,178};
- int unicom[]={130,131,132,155,156,186,185,176};
- int telecom[]={133,153,189,180,181,177};
- for(i=0; i<sizeof(mobile)/sizeof(int); i++)
- {
- if(mobile[i]==atoi(phoneno.Left (3)))
- {
- return 0;
- }
- }
- for(i=0; i<sizeof(unicom)/sizeof(int); i++)
- {
- if(unicom[i]==atoi(phoneno.Left (3)))
- {
- return 1;
- }
- }
- for(i=0; i<sizeof(telecom)/sizeof(int); i++)
- {
- if(telecom[i]==atoi(phoneno.Left (3)))
- {
- return 2;
- }
- }
- return -1;
- }
- /* else if(phoneno.GetAt (0)=='0')
- {
- if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
- {
- return 3;
- }
- }*/
- return -1;
- }
- //------------------------------------------------------------------------------------------
- // Remark by Jeff: 2014.09.21
- // 函数:GetCount
- // 描述:指定短信内容和手机号,计算出要发送的短信条数;
- // 参数:
- // phones: 以逗号分隔的手机号串;
- // content: 短信内容;
- //
- // 返回:短信条数;
- //
- // 注意:
- //
- //------------------------------------------------------------------------------------------
- int GetCount(CString phones, CString content)
- {
- // 1.首先分析出短信内容会被拆分成多少条短信发送;
- int nNumberOfTextMsg = 0; // 短信条数;
- int nWCharLen = ::MultiByteToWideChar(CP_ACP,0,content,-1,NULL,0); // Jeff.无论constent是否空,MultiByteToWideChar返回结果都>=1;
- // 魔数MSG_LENGTH = 67:
- // 当短信字符数超过70时,短信服务商会分为两部分;
- // 1.将前67个字符为一条短信;
- // 2.将67后的为另一部分,若仍大于70,再次执行1;
- // 3.若短信小于等于70,则为一条短信;
- nNumberOfTextMsg = nWCharLen / 67;
- if (nWCharLen % 67 > 2 ) ++nNumberOfTextMsg;
- // 2.其次解析手机字符串,获取手机数量;(不考虑小灵通,通用使用67字符截断短信)
- int nCountOfMobile = 0;
- int nIndex = 0;
- do
- {
- nIndex = phones.Find(",");
- if (nIndex != -1)
- {
- if ( nIndex == 11 && CheckPhoneType(phones.Left(nIndex)) != -1) // Jeff,CheckPhoneType返回-1表示未知手机类型;
- ++nCountOfMobile;
- phones = phones.Mid(nIndex+1);
- }
- else
- {
- if ( phones.GetLength() == 11 && CheckPhoneType(phones) != -1)
- ++nCountOfMobile;
- }
- } while (nIndex != -1);
- return nNumberOfTextMsg *= nCountOfMobile;
- }
- int GetBalance(CString account)
- {
- CString count1="";
- CString count2="";
- CString count3="";
- try
- {
- CRecordset myset(&g_db);
- #ifdef SQLSERVER_VERSION
- CString sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
- #else
- CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count1);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count2);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount2] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count3);
- myset.Close();
- return atoi(count1)-atoi(count2);
- }
- catch(...)
- {
- return -1;
- }
- }
|