//mainCtrl.cpp TCHAT_MESSAGE_STRU #include "stdafx.h" /////////////////////////////////////////////////////////////////////////////// #include "mainCtrl.h" #include "mysqldata.h" #include "LYFZSendMsg.h" extern CString g_mainpath; extern CDatabase g_db; CStringArray g_baduserarray; /* 移动: 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; } } BOOL g_bWork=0;