// 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 #include #include #include "mysqldata.h" #include #include //#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; CArrayg_userarray; CArrayg_cominfoarray; CArrayg_lengarray; CArrayg_btnlengarray; CArrayg_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; CArrayg_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>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>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; iGetSize(); 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; im_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'超过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=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;iProcessChatMessageRequest2(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; inPicBmpCount [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'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; iPumpMessage()) 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; im_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'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=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; } }