/********************************************************************/ /* */ /* CONNECTSOCKET.CPP */ /* */ /* Implementation of the Connect Socket. */ /* This class is a part of the CConnectThread which handles */ /* socket connections. Incomming data is processed in OnReceive */ /* */ /* Programmed by LYFZ van der Meer */ /* Based partially on and inspired by FileZilla Server. */ /* */ /* http://www.LYFZvandermeer.nl */ /* */ /* Last updated: 15 july 2002 */ /* */ /********************************************************************/ //在ConnectSocket.cpp文件中实现连接套接字的创建,该类是CConnectThread类的 //一部分,收到数据由函数OnReceive()完成处理。 net_Send #include "stdafx.h" #include "LYFZReceiveMsgApp.h" #include "LYFZReceiveMsg.h" #include "ConnectSocket.h" #include "ConnectThread.h" #include "ApplicationDlg.h" #include "DataSocket.h" #include "mysqldata.h" #include "./include/netMain.h" #include "./include/protocolhdr.h" #include "./include/struct_def.h" #include "MyLock.h" extern CLYFZReceiveMsg theServer; extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword); #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CLYFZReceiveMsg *g_pWndServer; CStringArray g_baduserarray; ////////////////////////////////////////insert into BOOL BadUser(CString account) { for(int 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; } BOOL MyExecuteSQL(CDatabase *pdb, CString sql) { // MyLock lock("xiaoaccessdbmsg"); try { pdb->ExecuteSQL (sql); } catch(CDBException * e) { WriteError(sql+"操作数据库失败"+e->m_strError); return 0; } return 1; } void ReCalAccount(CString account, CDatabase *pDb) { CString sql; if(1) { // MyLock lock("xiaoaccessdbmsg"); CRecordset myset(pDb); CString count1,count2,count3; #ifdef SQLSERVER_VERSION sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'"; #else 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(); sql="select count(*) as cot from receivemsg where [account]='"+account+"' and [replyok]='1'"; myset.Open (CRecordset::forwardOnly, sql); if(!myset.IsEOF()) myset.GetFieldValue ("cot", count3); myset.Close(); // sql.Format ("update clientinfo set balance='%d' where account='%s'", atoi(count1)-min(atoi(count2),atoi(count3)), account); sql.Format ("update clientinfo set balance='%d' where account='%s'", (atoi(count1)-atoi(count2))-atoi(count3), account); } MyExecuteSQL(pDb, sql); } /* 移动: 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 */ extern void WriteLogin(CString str); //------------------------------------------------------------------------------------------ // Remark by Jeff; 2014-09-21 // 函数:GetBalance // 描述:通过Select Sum SQL语句,获取数据库指定条件值的总和; // 参数: // account: 短信账号; // pDB: 连接的数据库实例对象指针; // // 返回:查询失败返回-1;成功返回其他值; // // 注意: // 1.如果[sendreg].[msgcount]值不对的话,那么会造成很严重的后果,不仅返回给客户的值不对,扣费也错乱甚至造成亏本; // // //------------------------------------------------------------------------------------------ int GetBalance(CString account, CDatabase *pDb) { CString count1=""; // 该账号充值的短信数量,[recharge]表; (应该不是剩余数量,这个充值的值应该是在下一次充值时才会改变) CString count2=""; // 短信发送成功的扣费总和,[sendreg]表; CString count3=""; // 短信接收成功的扣费总和,[receivemsg]表; try { CRecordset myset(pDb); #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(); sql="select count(*) as cot from receivemsg where [account]='"+account+"' and [replyok]='1'"; myset.Open (CRecordset::forwardOnly, sql); if(!myset.IsEOF()) myset.GetFieldValue ("cot", count3); myset.Close(); return (atoi(count1)-atoi(count2))-atoi(count3); } catch(...) { return -1; } } int GetLengthEx(CString str) // Jeff:获取多字节对应的宽字符数; { #if 0 // Jeff delete; wchar_t wstr[500]; int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500); return k; #else return ::MultiByteToWideChar(CP_ACP,0,str,-1,NULL,0);// Jeff.无论constent是否空,MultiByteToWideChar返回结果都>=1; #endif } //------------------------------------------------------------------------------------------ // Remark by Jeff; 2014-09-21 // 函数:GetBalanceUsed // 描述:获取账号可用剩余短信数,并更新到数据库表记录中; // 参数: // account: 短信账号; // pDB: 连接的数据库实例对象指针; // ret1: 账号可用的剩余短信数量; // ret2: 账号已用的短信总数; // // 返回:查询失败返回-1;成功返回其他值; // // //------------------------------------------------------------------------------------------ void GetBalanceUsed(CString account, int &ret1,int &ret2, CDatabase *pDb) { CString count1=""; // 该账号充值的短信数量,[recharge]表; (应该不是剩余数量,这个充值的值应该是在下一次充值时才会改变) CString count2=""; // 短信发送成功的扣费总和,[sendreg]表; CString count3=""; // 短信接收成功的扣费总和,[receivemsg]表; ret1=0; ret2=0; try { CRecordset myset(pDb); #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(); sql="select count(*) as cot from receivemsg where [account]='"+account+"' and [replyok]='1'"; myset.Open (CRecordset::forwardOnly, sql); if(!myset.IsEOF()) myset.GetFieldValue ("cot", count3); myset.Close(); ret2 = atoi(count2)+atoi(count3) ; ret1 = atoi(count1)-ret2; sql.Format ("update clientinfo set balance='%d' where account='%s'", ret1, account); MyExecuteSQL(pDb, sql); } catch(...) { } } //------------------------------------------------------------------------------------------ // Remark by Jeff: 2014.09.21 // 函数:GetCount // 描述:指定短信内容和手机号,计算出要发送的短信条数; // 参数: // phones: 以逗号分隔的手机号串; // content: 短信内容; // // 返回:短信条数; // // 注意: // //------------------------------------------------------------------------------------------ int GetCount(CString phones, CString content) { #if 0 // Jeff delete; int count=0; int leng=GetLengthEx(content); int m_nMobile=0; // Jeff:移动联通电信手机数; int m_nPhone=0; // Jeff:小灵通手机数; CStringArray phonearray; int pos=phones.Find (","); if(pos!=-1) { phonearray.Add(phones.Left (pos)); phones=phones.Right (phones.GetLength ()-pos-1); pos=phones.Find (","); while(pos!=-1) { phonearray.Add (phones.Left (pos)); phones=phones.Right (phones.GetLength ()-pos-1); pos=phones.Find (","); } phonearray.Add (phones); } else phonearray.Add (phones); for(int i=0; i=1; // 魔数MSG_LENGTH = 67: // 当短信字符数超过70时,短信服务商会分为两部分; // 1.将前67个字符为一条短信; // 2.将67后的为另一部分,若仍大于70,再次执行1; // 3.若短信小于等于70,则为一条短信; nNumberOfTextMsg = nWCharLen / 67; if (nWCharLen % 67 > 2 ) ++nNumberOfTextMsg; //if (nWCharLen % 67 ) ++nNumberOfTextMsg; // 如果 nWCharLen%67 不大于2,会多扣客户一条短信费用; // 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; #endif } //--------------------------------------------------------------------------------------------- // Remark by Jeff; // 函数:IsExist // 描述:查询指定的短信账号要发送的【目标内容+手机+时间戳】是否存在; // 参数: // account: 短信账号; // phones: 接收短信的手机串; // content: 短信内容; // timestamp: 发送时间; // pDb: 连接数据库的对象指针; // // 返回:存在返回TRUE; // //--------------------------------------------------------------------------------------------- BOOL IsExist(CString account, CString phones, CString content, CString timestamp, CDatabase *pDb) { //已保存此条记录, 不再保存, 否则重复 // MyLock lock("xiaoaccessdbmsg"); CRecordset myset(pDb); CString sql="select count(*) as cot from sendreg where [account]='"+account+"' and [content]='"+content+"' and [phones]='"+phones+"' and [timestamp]='"+timestamp+"'"; myset.Open (CRecordset::forwardOnly, sql); if(!myset.IsEOF()) { myset.GetFieldValue ("cot", sql); if(atoi(sql)) return 1; else return 0; } else return 0; } void WriteLog(CString account, CString str) { } /********************************************************************/ /* */ /* Function name : CConnectSocket::CConnectSocket */ /* Description : Constructor */ /* */ /********************************************************************/ CConnectSocket::CConnectSocket() { m_bLoggedon = FALSE; m_bRenameFile = FALSE; m_pDataSocket = NULL; m_nRemotePort = -1; m_dwRestartOffset = 0; m_bPassiveMode = FALSE; m_reved=0; m_dateleng=0; m_pRevBuf=NULL; } /********************************************************************/ /* */ /* Function name : CConnectSocket::~CConnectSocket */ /* Description : Destructor */ /* */ /********************************************************************/ CConnectSocket::~CConnectSocket() { DestroyDataConnection(); // tell our thread we have been closed AfxGetThread()->PostThreadMessage(WM_QUIT,0,0); TRACE0("CConnectSocket destroyed.\n"); if(m_pRevBuf)delete []m_pRevBuf; } // Do not edit the following lines, which are needed by ClassWizard. #if 0 BEGIN_MESSAGE_MAP(CConnectSocket, CSocket) //{{AFX_MSG_MAP(CConnectSocket) //}}AFX_MSG_MAP END_MESSAGE_MAP() #endif // 0 /********************************************************************/ /* */ /* Function name : OnClose */ /* Description : Send WM_QUIT message to the thread containing */ /* the socket to shutdown once the connection is */ /* closed. */ /* */ /********************************************************************/ void CConnectSocket::OnClose(int nErrorCode) { try { Close(); // destroy connection m_pThread->PostThreadMessage(WM_THREADMSG, 1, 0); TRACE("CConnectSocket() OnClose()\n"); CSocket::OnClose(nErrorCode); } catch(...) { } } #define BUFFERSIZE 4096 /********************************************************************/ /* */ /* Function name : OnReceive */ /* Description : Called by the framework to notify this socket */ /* that there is data in the buffer. */ /* */ /********************************************************************/ //由主窗口调用通知套接字缓冲区中有数据要接收 void CConnectSocket::OnReceive(int nErrorCode) { TCHAR buff[BUFFERSIZE]; //接收数据并放到缓冲区 int nRead = Receive(buff, BUFFERSIZE); switch (nRead) { case 0: Close(); break; case SOCKET_ERROR: if (GetLastError() != WSAEWOULDBLOCK) { // TCHAR szError[256]; // wsprintf(szError, "OnReceive error: %d", GetLastError()); // AfxMessageBox (szError); } break; default: if (nRead != SOCKET_ERROR && nRead != 0) { ((CConnectThread *)AfxGetThread())->IncReceivedBytes(nRead); TMessageHeader *pMessageHeader = (TMessageHeader *)buff; /*网络字节顺序的转换*/ ntohs(pMessageHeader->wHeaderFlag); ntohs(pMessageHeader->wMessageId); ntohs(pMessageHeader->wMessageSubId); ntohl(pMessageHeader->dwDataLen); ntohs(pMessageHeader->wCheckSum); ntohl(pMessageHeader->wReserve); if(pMessageHeader->wMessageId ==MSG_LOGIN_REQ) { WORD wMessageId = MSG_LOGIN_RESP; LOGIN_RESULT_STRU tLoginResult = {0}; tLoginResult.tCommonMsg.dwConnectionID = 0; tLoginResult.tCommonMsg.wMessageId = wMessageId; tLoginResult.byResult = LOGIN_RESULT_SUC; tLoginResult.dwUserID = 0; tLoginResult.byStatus = USER_STATUS_ONLINE ; DWORD dwDataLen = sizeof(LOGIN_RESULT_STRU); TMessageHeader tHeader = {0}; tHeader.wMessageId = wMessageId; tHeader.dwDataLen = dwDataLen; net_Send(&tHeader, (void *)&tLoginResult, dwDataLen); } else //if(pMessageHeader->wMessageId ==MSG_CHATMESSAGE_REQ) { /* char *pDataBuf = (char *)buff + MESSAGE_HEADER_LEN; TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf; DWORD dwConnectionID = pChatMessage->tCommonMsg.dwConnectionID; processChatMessageRequest((void *)pChatMessage);*/ // 结束字符串 if(pMessageHeader->wHeaderFlag==MESSAGE_HEADER_FLAG && pMessageHeader->wMessageId ==MSG_CHATMESSAGE_REQ) { if(m_pRevBuf)delete []m_pRevBuf; m_pRevBuf=NULL; m_reved=0; m_dateleng=0; m_dateleng=pMessageHeader->dwDataLen+MESSAGE_HEADER_LEN; m_pRevBuf=new BYTE[m_dateleng]; //WriteLogin("开始接收"); } if(m_dateleng==0) return; ::memcpy(m_pRevBuf+m_reved, buff, min(nRead, m_dateleng-m_reved)); m_reved+=min(nRead, m_dateleng-m_reved); // CString ss; // ss.Format ("接收:%d/%d", m_reved, m_dateleng); // WriteLogin(ss); if(m_reved>=m_dateleng) { // WriteLogin("接收完成"); char *pDataBuf = (char *)m_pRevBuf + MESSAGE_HEADER_LEN; TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf; m_reved=0;m_dateleng=0; processChatMessageRequest((void *)pChatMessage); } } } break; } CSocket::OnReceive(nErrorCode); } /********************************************************************/ /* */ /* Function name: GetRxCommand */ /* Description : Get command from receiver buffer. */ /* */ /********************************************************************/ //从接收缓冲区获得命令 BOOL CConnectSocket::GetRxCommand(CString &strCommand, CString &strArguments) { return FALSE; } /********************************************************************/ /* */ /* Function name: GetRxLine */ /* Description : Parse complete command line */ /* */ /********************************************************************/ //解析整个命令行 void CConnectSocket::GetRxLine() { } /********************************************************************/ /* */ /* Function name: OnConnect */ /* Description : Called by the framework to notify this connecting */ /* socket that its connection attempt is completed. */ /* */ /********************************************************************/ void CConnectSocket::OnConnect(int nErrorCode) { CSocket::OnConnect(nErrorCode); } /********************************************************************/ /* */ /* Function name: HasConnectionDropped */ /* Description : Check if connection has been dropped. */ /* Used to detect if client has crashed. */ /* */ /********************************************************************/ BOOL CConnectSocket::HasConnectionDropped(void) { try { BOOL bConnDropped = FALSE; INT iRet = 0; BOOL bOK = TRUE; if (m_hSocket == INVALID_SOCKET) return TRUE; struct timeval timeout = { 0, 0 }; fd_set readSocketSet; FD_ZERO(&readSocketSet); FD_SET(m_hSocket, &readSocketSet); iRet = ::select(0, &readSocketSet, NULL, NULL, &timeout); bOK = (iRet > 0); if(bOK) { bOK = FD_ISSET(m_hSocket, &readSocketSet); } if(bOK) { CHAR szBuffer[1] = ""; iRet = ::recv(m_hSocket, szBuffer, 1, MSG_PEEK); bOK = (iRet > 0); if(!bOK) { INT iError = ::WSAGetLastError(); bConnDropped = (( iError == WSAENETRESET) || (iError == WSAECONNABORTED) || (iError == WSAECONNRESET) || (iError == WSAEINVAL) || (iRet == 0)); } } return(bConnDropped); } catch(...) { } return 1; } /********************************************************************/ /* */ /* Function name: SendResponse */ /* Description : Send response to client. */ /* */ /********************************************************************/ //发送响应给客户端 BOOL CConnectSocket::SendResponse(LPCTSTR pstrFormat, ...) { return TRUE; } //从客户端解析并执行命令 void CConnectSocket::ParseCommand() { } /********************************************************************/ /* */ /* Function name: FireStatusMessage */ /* Description : Fire status message. */ /* */ /********************************************************************/ void CConnectSocket::FireStatusMessage(LPCTSTR lpszStatus, int nType) { try { g_pWndServer->AddTraceLine(nType, "[%d] %s", m_pThread->m_nThreadID, lpszStatus); } catch(...) { } } /********************************************************************/ /* */ /* Function name: CreateDataConnection */ /* Description : Create data transfer connection. */ /* */ /********************************************************************/ BOOL CConnectSocket::CreateDataConnection(int nTransferType, LPCTSTR lpszData) { return TRUE; } /********************************************************************/ /* */ /* Function name: DestroyDataConnection */ /* Description : Close data transfer connection. */ /* */ /********************************************************************/ void CConnectSocket::DestroyDataConnection() { } unsigned long CConnectSocket::net_Send(IN void *pHeader, IN void *pMessage, IN unsigned long ulDataLen) { try { unsigned long ulSendLen = 0; unsigned long ulBufLen = 0; TMessageHeader *pSendHeader = (TMessageHeader *)pHeader; ulBufLen = MESSAGE_HEADER_LEN + ulDataLen; char *pSendBuf = new char[ulBufLen]; memset(pSendBuf, 0, ulBufLen); TMessageHeader *pMessageHeader = (TMessageHeader *)pSendBuf; pMessageHeader->byVersion = 101; pMessageHeader->wHeaderFlag = MESSAGE_HEADER_FLAG; pMessageHeader->wMessageId = pSendHeader->wMessageId; pMessageHeader->wMessageSubId = pSendHeader->wMessageSubId; pMessageHeader->dwDataLen = ulDataLen; pMessageHeader->wReserve = 0; memcpy((void *)(pSendBuf+MESSAGE_HEADER_LEN), pMessage, ulDataLen); // convert network word htons(pMessageHeader->wHeaderFlag); htons(pMessageHeader->wMessageId); htons(pMessageHeader->wMessageSubId); htonl(pMessageHeader->dwDataLen); htons(pMessageHeader->wCheckSum); htonl(pMessageHeader->wReserve); //Send the message // ulSendLen = CTransportImpl::net_Send(hSocket, (void *)pSendBuf, ulBufLen); //判断连接是否在活动状态 if (HasConnectionDropped()) { FireStatusMessage("Could not send reply, disconnected.", 2); Close(); // 通知线程已经停止,关闭连接 m_pThread->PostThreadMessage(WM_THREADMSG, 1, 0); return FALSE; } int nBytes = CSocket::Send((void *)pSendBuf, ulBufLen); if (nBytes == SOCKET_ERROR) { Close(); FireStatusMessage("Could not send reply, disconnected.", 2); //通知线程连接已经关闭 m_pThread->PostThreadMessage(WM_THREADMSG, 1, 0); return FALSE; } ((CConnectThread *)AfxGetThread())->IncSentBytes(nBytes); delete [] pSendBuf; pSendBuf = NULL; return nBytes; } catch(...) { } return 0; } BOOL g_bWork=0; extern int FindArray2(CStringArray *pArray, CString Str); extern CStringArray g_ipnoallowarray; void AddIP(CString ip) { MyLock lock("IsIPAddressAllowed"); if(::FindArray2 (&g_ipnoallowarray, ip)!=-1)return; g_ipnoallowarray.Add (ip); WriteUnallowIP(ip); } void CConnectSocket::processChatMessageRequest(void *pChatMsg) { int pos = 0; CString str; CString g_ret; try { g_bWork=1; if( NULL == pChatMsg ) { g_bWork=0; return; } TCHAT_MESSAGE_STRU *ptChatMessage = (TCHAT_MESSAGE_STRU *)pChatMsg; DWORD dwUserID = ptChatMessage->tCommonMsg.dwConnectionID; if(ptChatMessage->length[98]!=987123768) { WriteLogin("987123768"); g_bWork=0; return; } int nMessageLen = ptChatMessage->wMessageLen; if( nMessageLen > 3 ) { // MyLock lock("msgaccessdbsendreg"); DWORD dwToUserID = ptChatMessage->dwToUserID; if(dwToUserID!=9)//企业版分店权限设置 { char *szChatMessage; szChatMessage = new char[nMessageLen+1]; memset(szChatMessage, 0x00, nMessageLen+1); memcpy(szChatMessage, ptChatMessage->byFileContent, nMessageLen); EncryptFile2((BYTE*)szChatMessage, nMessageLen, "888666333"); str=szChatMessage;delete []szChatMessage; } else str.Empty (); BYTE *pBranchData=NULL; DWORD nBranchDataLeng=0; int nBranchArraySize=0; CString name; CString phone; CString signname; int nRoadType; // 解析过程; if(dwToUserID==0) { //MyLock lock("msgaccessdbsendreg"); //WriteLogin("开始"); WriteLogin(str); g_ret=str; // 短信账号、账号密码、手机串、短信内容、短信指定的发送时间; CString account,psw,phones,content,timestamp; pos=str.Find ("\r\n"); if(pos==-1) { g_bWork=0;WriteLogin("返回1"); return; } account=str.Left (pos); str.Delete (0, pos+2); pos=str.Find ("\r\n"); if(pos==-1) { g_bWork=0;WriteLogin("返回2"); return; } psw=str.Left (pos); str.Delete (0, pos+2); pos=str.Find ("\r\n"); if(pos==-1) { g_bWork=0;WriteLogin("返回3"); return; } phones=str.Left (pos); str.Delete (0, pos+2); pos=str.ReverseFind ('\r'); if(pos==-1) { g_bWork=0;WriteLogin("返回4"); return; } content=str.Left (pos); str.Delete (0, pos+2); timestamp=str; if(BadUser(account)) { g_bWork=0;WriteLogin("返回5"); return; } // CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType); // if(account!="105828")//1)// if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0) { // str="服务暂停!"; str="账户或密码错误!"; WritePswWrong(account+"\\"+psw+"\\"+name+"\\"+phone); WriteLogin(str); AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost); } else // Jeff: 账号密码正确; { // 1.获取该账号的剩余短信数量; content += signname; int nMaxPhones = 100; if(content.Find ("财报:收:")!=-1) // Jeff:这是发给谁的? nMaxPhones=1; CString sql; int balance = GetBalance(account, m_pConndb); // Jeff:获取剩余短信数;(该函数计数非安全,造成结果值不对的原因是【msgcount】字段值不是100%正确) int count = GetCount(phones,content); // Jeff:返回发送到全部手机号的短信条数; if(0)//nMaxPhones!=1 && phones.Find (",")!=-1) { str="群发服务暂停!"; } else { CString scount; scount.Format ("%d", count); if(balance<0 || count>balance) { str="发送信息失败! 余额不足!"; WriteLogin(str); WriteNullBalance(account+"\\"+name+"\\"+phone); AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost); } else { // Jeff Remark; // 1.如果短信内容转化为宽字符后的字符总数大于500,分割成每组500宽字符; CStringArray contentarray; // int leng[1]={70}; int leng[1]={500}; // Jeff:500的作用? CStringArray *pArray[1]={&contentarray}; for(int a=0; a<1; a++) // 为什么使用循环1次? { CString contenttemp = content; if(GetLengthEx(contenttemp) > leng[a]) { while(GetLengthEx(contenttemp) > leng[a]) { for( pos=leng[a]; posAdd (contenttemp); contenttemp.Empty (); break; } else { pArray[a]->Add (contenttemp.Left (pos)); contenttemp=contenttemp.Right (contenttemp.GetLength ()-pos); } } if(!contenttemp.IsEmpty ()) pArray[a]->Add (contenttemp); } else pArray[a]->Add (content); } g_ret+="\rstep1"; // 2.解析手机串; CStringArray phonearray; pos=phones.Find (","); if(pos!=-1) { phonearray.Add(phones.Left (pos)); phones=phones.Right (phones.GetLength ()-pos-1); pos=phones.Find (","); while(pos!=-1) { phonearray.Add (phones.Left (pos)); if(phones.IsEmpty ()==0) phones=phones.Right (phones.GetLength ()-pos-1); pos=phones.Find (","); } phones.TrimLeft (","); if(phones.IsEmpty ()==0) phonearray.Add (phones); } else phonearray.Add (phones); g_ret+="\rstep2"; // 3. 1,2,3,4分别为移动、联通、电信、小灵通; int phonearraysize1,phonearraysize2,phonearraysize3,phonearraysize4; CArraymultiphonearray1; CArraymultiphonearray2; CArraymultiphonearray3; CArraymultiphonearray4; phonearraysize1=phonearraysize2=phonearraysize3=phonearraysize4=1; multiphonearray1.SetSize(phonearraysize1, 1);multiphonearray1.ElementAt (0).RemoveAll(); multiphonearray2.SetSize(phonearraysize2, 1);multiphonearray2.ElementAt (0).RemoveAll(); multiphonearray3.SetSize(phonearraysize3, 1);multiphonearray3.ElementAt (0).RemoveAll(); multiphonearray4.SetSize(phonearraysize4, 1);multiphonearray4.ElementAt (0).RemoveAll(); int size[4]={1,1,1,1}; CArray *pPhoneArray[4]={&multiphonearray1,&multiphonearray2,&multiphonearray3,&multiphonearray4}; int i ; for( i=0; iElementAt (size[pos]-1).GetSize()>=nMaxPhones) { size[pos]++; pPhoneArray[pos]->SetSize(size[pos], 1); pPhoneArray[pos]->ElementAt (size[pos]-1).RemoveAll(); pPhoneArray[pos]->ElementAt (size[pos]-1).Add (phones); } else { pPhoneArray[pos]->ElementAt (size[pos]-1).Add (phones); } } g_ret+="\rstep3"; // 4.根据手机运营商,重新生成对应运营商的手机串; CString timestamp2,msgpos; CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(0,0,0,1); BOOL exist=0; for(i=0; i<4; i++) { for(int j=0; jGetSize(); j++) { if(!pPhoneArray[i]->ElementAt(j).GetSize())continue; phones.Empty(); for(int n=0; nElementAt(j).GetSize(); n++) { phones+=pPhoneArray[i]->ElementAt(j).ElementAt(n); phones+=","; } phones.TrimRight(","); if(i<3) // Jeff i < 3 :去除小灵通; { for(int m=0; mm_strRemoteHost); } else { WriteLog(account, "查询发送记录"); str.Empty (); // MyLock lock("xiaoaccessdbmsg"); for(int i=0; im_strRemoteHost); } else { if(nRoadType==2) str="未启用"; else { WriteLog(account, "查询客人回复记录"); str.Empty (); CString temp; ReceiveMsgForm rsSt; rsSt.m_pDatabase=m_pConndb; rsSt.m_strFilter = "[account]='"+account+"' and replyok is null"; rsSt.Open(); while(!rsSt.IsEOF()) { temp=rsSt.m_phone; temp+="'"; temp+=rsSt.m_content; temp+="'"; temp+=rsSt.m_datetime; temp+="'"; temp+=rsSt.m_autoid; rsSt.MoveNext(); str+=temp; str+="^"; } rsSt.Close(); if(str=="") str="无回复"; } } } else if(dwToUserID==21)//更改回复状态,已收到 { CString account,psw,sids; int pos=str.Find ("\r\n"); if(pos==-1) { g_bWork=0; return; } account=str.Left (pos); str.Delete (0, pos+2); pos=str.Find ("\r\n"); if(pos==-1) { g_bWork=0; return; } psw=str.Left (pos); str.Delete (0, pos+2); sids=str; if(BadUser(account)) { g_bWork=0; return; } if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0) { str="账户或密码错误!"; WritePswWrong(account+"\\"+psw+"\\"+name+"\\"+phone);AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost); } else { str.Format ("update receivemsg set replyok=1 where %s", sids); MyExecuteSQL(m_pConndb, str); str="ok"; } } else if(dwToUserID==5)//查询余额 { CString account,psw,newpsw; int pos=str.Find ("\r\n"); if(pos==-1) { g_bWork=0; return; } account=str.Left (pos); str.Delete (0, pos+2); psw=str; if(BadUser(account)) { g_bWork=0; return; } // ReCalAccount(account,m_pConndb); if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0) { str="账户或密码错误!"; } else { // CString count1=""; // CString count2=""; int ncount1=0; int ncount2=0; GetBalanceUsed(account, ncount1, ncount2, m_pConndb); // ncount1=atoi(count1)- atoi(count2); // ncount2= atoi(count2) ; str.Format ("%d/%d", ncount1, ncount2); } //WriteLogin("查询余额:"+str); } else if(dwToUserID==6)//登记客人IP { } else if(dwToUserID==7)//查询客人IP { } else if(dwToUserID==8)//企业版客人查询企业资料 { } else if(dwToUserID==9)//企业版分店权限设置 { } else if(dwToUserID==10)//登记客人IP { } else if(dwToUserID==11)//查询客人IP { } else if(dwToUserID==12)//执行sql { m_pConndb->ExecuteSQL (str);str="ok"; } else if(dwToUserID==13)//查询sql { } DWORD dwFromUserID = dwUserID; WORD wMessageId = MSG_CHATMESSAGE_RESP; DWORD dwDataLen; BYTE *pSendData; TCHAT_MESSAGE_STRU *pChatMessage; if(str.IsEmpty ())str="OK"; int nDataLen=str.GetLength (); if(nBranchDataLeng) { nDataLen=nBranchDataLeng; g_sendhead.count[0]=nBranchArraySize; } dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen ; TMessageHeader tHeader = {0}; tHeader.wMessageId = wMessageId; tHeader.dwDataLen = dwDataLen; pSendData = new BYTE[dwDataLen]; pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData; memset(pChatMessage, 0x00, dwDataLen); memcpy(pSendData, &g_sendhead, sizeof(g_sendhead)); pChatMessage->tCommonMsg.dwConnectionID = dwFromUserID; pChatMessage->tCommonMsg.wMessageId = wMessageId; pChatMessage->dwFromUserID = dwFromUserID; pChatMessage->dwToUserID = dwToUserID; pChatMessage->wMessageLen = nDataLen; if(nBranchDataLeng) { memcpy(pChatMessage->byFileContent, pBranchData, nDataLen); delete []pBranchData; } else { memcpy(pChatMessage->byFileContent, str.GetBuffer (0), nDataLen); str.ReleaseBuffer (); } net_Send(&tHeader, (void *)pChatMessage, dwDataLen); delete [] pSendData; } } catch(...) { WriteLogin("发送过程中出错:"+g_ret); } g_bWork=0; } void Test() { } //密码错误