📄 mosmgplistenwnd.cpp
字号:
// CMOSmgpListenWnd.cpp : 实现文件
//
#include "stdafx.h"
#include "MOSmgpService.h"
#include "MOSmgpListenWnd.h"
//#include "mosmgplistenwnd.h"
//#include "Customize.h"
// CMOSmgpListenWnd
static CADODatabase *mo_db=NULL;
using namespace SMS;
static CString strEnterprise_Code="918034";//企业代码要修改为小灵通
IMPLEMENT_DYNAMIC(CMOSmgpListenWnd, CWnd)
CMOSmgpListenWnd::CMOSmgpListenWnd()
{
}
CMOSmgpListenWnd::~CMOSmgpListenWnd()
{
if(mo_db){
mo_db->Close();
delete mo_db;
mo_db=NULL;
}
}
void SocketTraceMO(CString str){
//#ifdef _DEBUG
str+= "\r\n";
CString strFilename = "c:\\mosmgp.txt";
CFileStatus status;
if(CFile::GetStatus(strFilename,status)){
CFile f(strFilename,CFile::modeReadWrite|CFile::modeNoTruncate);
f.SeekToEnd();
f.Write(str.GetBuffer(0),str.GetLength());
f.Close();
}
else{
CFile f(strFilename,CFile::modeCreate|CFile::modeWrite);
f.Write(str.GetBuffer(0),str.GetLength());
f.Close();
}
//#endif
}
void MOMessageLog(CString str){
//#ifdef _DEBUG
//MOTrace("INPUT momessagelog");
CString strFilename;
CFileStatus status;
try
{
str+= "\r\n";
CString timelog;
CTime timeS = CTime::GetCurrentTime();
timelog.Format("小灵通%02d_%02dMO日志",
timeS.GetMonth(),timeS.GetDay());
timelog="d:\\newlifesms\\LOG SMS MO\\"+timelog+".txt";
strFilename =timelog;// "c:\\YDMOService.txt";
}catch (...) {
SocketTraceMO("momessagelog ERROR");
}
CString strTime;
CTime time = CTime::GetCurrentTime();
strTime.Format("*******%04d-%02d-%02d %02d:%02d:%02d ****",
time.GetYear(),time.GetMonth(),time.GetDay(),
time.GetHour(),time.GetMinute(),time.GetSecond());
if(CFile::GetStatus(strFilename,status)){
CFile f(strFilename,CFile::modeReadWrite|CFile::modeNoTruncate);
f.SeekToEnd();
//f.Write(strTime.GetBuffer(0),strTime.GetLength());
f.Write(str.GetBuffer(0),str.GetLength());
f.Close();
}
else{
CFile f(strFilename,CFile::modeCreate|CFile::modeWrite);
//f.Write(strTime.GetBuffer(0),strTime.GetLength());
f.Write(str.GetBuffer(0),str.GetLength());
f.Close();
}
//#endif
}
void SocketTraceMOreport(CString str){
//#ifdef _DEBUG
str+= "\r\n";
CString strFilename = "c:\\MOreport.txt";
CFileStatus status;
if(CFile::GetStatus(strFilename,status)){
CFile f(strFilename,CFile::modeReadWrite|CFile::modeNoTruncate);
f.SeekToEnd();
f.Write(str.GetBuffer(0),str.GetLength());
f.Close();
}
else{
CFile f(strFilename,CFile::modeCreate|CFile::modeWrite);
f.Write(str.GetBuffer(0),str.GetLength());
f.Close();
}
//#endif
}
BEGIN_MESSAGE_MAP(CMOSmgpListenWnd, CWnd)
ON_MESSAGE(WM_SMGP_MO,OnSmgpMO)
ON_MESSAGE(WM_SMGP_REPORT,OnSmgpReport)
END_MESSAGE_MAP()
// CMOSmgpListenWnd 消息处理程序
BOOL CMOSmgpListenWnd::Create(CWnd * pParent)
{
//SocketTraceMO("IN PUT CREATE>>>>>>>>>>>>>>>>>>");
CString strWndClass = ::AfxRegisterWndClass(0,NULL,NULL,NULL);
//////////////////////////////////////////////////////////////????????????????????????????????????????????
mo_db =new CADODatabase();
mo_db->OpenSQLServerDirect(MyReg::GetDBIP(),MyReg::GetDBUserID(),MyReg::GetDBPassword(),MyReg::GetDBName());
return CWnd::CreateEx(0,strWndClass,"SMSListener",0,CRect(0,0,0,0),pParent,0,NULL);
}
////////////////////////////////////////////////////////////////////////////////////
//
//MO消息处理程序,在此将信息添加到MO信息表sms_mo_input和系统日志表sms_log表中
//
////////////////////////////////////////////////////////////////////////////////////
HRESULT CMOSmgpListenWnd::OnSmgpMO(WPARAM wPar, LPARAM lPar)
{
SocketTraceMO("IN PUT ONSMGPMO MESSAGE FUNTCTION!!<<<<<<<<<<<<<<<<<<<<<<<");
CString strMsg;
try
{
CADORecordset rs(mo_db);
CADORecordset rslog(mo_db);
LPSMGP_MO_MESSAGE lpMsg = (LPSMGP_MO_MESSAGE)lPar;
if(!lpMsg) {
SocketTraceMO("Receive MO Message null");
return 0;
}
//else
//{
SocketTraceMO("Receive MO Message not null>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
/* strMsg.Format("MOmsg mobile:%s spcode:%s msg:%s length:%d \r\n",lpMsg->tcMobileFrom,lpMsg->Dest_ID,lpMsg->pMessage,lpMsg->iMessageLength);
SocketTraceMO(strMsg)*/;
////m_strMoMsg.Format("%s%s",m_strMoMsg,strMsg);
//}
//主控制,DEMO可以考虑将以下程序单独写一个方法
if(strlen(lpMsg->tSrcTermID)<=0)return 0;
CMOSmgpMessage msg(*lpMsg);
CString strCommand = msg.GetCommand();
//SocketTraceMO(strCommand);
CString strSpNumber=msg.m_strSpCode;//.Mid(3,msg.m_strSpCode.GetLength-3);
//SocketTraceMO(strSpNumber);
strSpNumber=strSpNumber.Mid(3,strSpNumber.GetLength()-3);
///SocketTraceMO(strSpNumber);
CString strClientPhone=msg.m_strPhonecode;
//SocketTraceMO(strClientPhone);
MOMessageLog(strCommand+" "+strSpNumber+" "+strClientPhone);
if(!mo_db->IsOpen())mo_db->OpenSQLServerDirect(MyReg::GetDBIP(),MyReg::GetDBUserID(),MyReg::GetDBPassword(),MyReg::GetDBName());
//将信息添加到MO信息表中
SocketTraceMO("DataInput sms_mo_input is begin");
try
{
rs.Open("select * from sms_mo_input where 1=0");
rs.AddNew();
rs.SetFieldValue("SPCode",strSpNumber);
rs.SetFieldValue("MobileCode",strClientPhone);
rs.SetFieldValue("SMS_Msg",strCommand);
rs.Update();
rs.Close();
SocketTraceMO("DataInput sms_mo_input is end");
}
catch (...) {
SocketTraceMO("DataInput sms_mo_input 异常");
}
//添加到日志表中
try
{
SocketTraceMO("DataInput sms_log is begin");
rslog.Open("select * from sms_log_new where 1=0");
rslog.AddNew();
rslog.SetFieldValue("PhoneSrc",strClientPhone);
rslog.SetFieldValue("PhoneDesc",strSpNumber);
rslog.SetFieldValue("SmsMsg",strCommand);
rslog.Update();
rslog.Close();
SocketTraceMO("DataInput sms_log is end");
}
catch (...) {
SocketTraceMO("DataInput sms log 异常");
}
return 0;
}
catch(...)
{
return 0;
}
}
HRESULT CMOSmgpListenWnd::OnSmgpReport(WPARAM wPar,LPARAM lPar)//SMGP_REPORT,* LPSMGP_RESPORT;
{
SocketTraceMOreport("IN PUT ONSMGPREPORT PROCESSED");
try
{
CADORecordset rslog(mo_db);
CString strSql="";
LPSMGP_RESPORT lpReport=(LPSMGP_RESPORT)lPar;
/* CString strMobile(lpReport->);*/
CString strReportStatus(lpReport->tStat);
INT64 MSGID=0;
MSGID=atoi(lpReport->tMsgID);
//在此处添加日志信息,表sms_log
if(!mo_db->IsOpen())mo_db->OpenSQLServerDirect(MyReg::GetDBIP(),MyReg::GetDBUserID(),MyReg::GetDBPassword(),MyReg::GetDBName());
try
{
//strSql.Format("update SMS_LOG_NEW SET ReportStatus='%s' Where Msg_ID='%I64u' and phoneDesc='%s'",strReportStatus,MSGID,strMobile);
strSql.Format("update SMS_LOG_NEW SET ReportStatus='%s' Where Msg_ID='%I64u'",strReportStatus,MSGID);
//MOTrace(strSql);
rslog.Open(strSql);
rslog.Close();
}
catch(...){
}
try
{
//strSql.Format("insert into SMS_LOG_REPORT(mobile,statue,errcode,msgid) values('%s','%d','%s','%I64u')",strMobile,0,strReportStatus,MSGID);
strSql.Format("insert into SMS_LOG_REPORT(statue,errcode,msgid) values('%d','%s','%I64u')",0,strReportStatus,MSGID);
rslog.Open(strSql);
rslog.Close();
}
catch(...){
}
}
catch(...){
}
return 0;
// SocketTraceMO("IN PUT ONSMGPREPORT <<<<<<<<<<<<<<<<<<<<<<");
// LPSMGP_RESPORT lpReport=(LPSMGP_RESPORT)lPar;
// CString strMsg;
// strMsg.Format("ReprotMSG msgid:%s errcode:%s status:%s submittime:%s donetime:%s \r\n",lpReport->tMsgID,lpReport->ErrCode,lpReport->tStat,lpReport->tSubmit_date,lpReport->tDone_date);
// /*m_strMoMsg.Format("%s%s",m_strMoMsg,strMsg);*/
// SocketTraceMO(strMsg);
// UpdateData(FALSE);
// //AfxMessageBox(strMsg);
return 0;
}
static BOOL _splite(CString strSrc,CStringArray * arData,CString strFilter){
arData->RemoveAll();
while(!strSrc.IsEmpty()){
int iPos = strSrc.Find(strFilter);
if(iPos<0){
arData->Add(strSrc);
strSrc.Empty();
continue;
return false;
}
arData->Add(strSrc.Left(iPos));
strSrc = strSrc.Right(strSrc.GetLength()-iPos-strFilter.GetLength());
}
return true;
}
CMOSmgpMessage::CMOSmgpMessage(SMGP_MO_MESSAGE msg){
SocketTraceMO("INPUT CMOMESSAGE FUNCTION!!!!");
this->m_strPhonecode = CString(msg.tSrcTermID);
this->m_strSpCode=CString(msg.tDestTermID);
CString strMsg(msg.cMessageContent);
// SocketTraceMO(m_strPhonecode+"/////////////////"+m_strSpCode+";;;;;;"+strMsg);
CStringArray ar;
//SocketTraceMO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
this->m_testMsg=strMsg; //by liu for test
this->m_strCommand=strMsg;
SocketTraceMO("this->m_strCommand=strMsg;");
SocketTraceMO(strMsg);
// SocketTraceMO("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
//if(_splite(strMsg,&ar,"@@"))
//{
// SocketTraceMO("@@@@");
// // MOTrace0("enter cmomessage");
// if(ar.GetCount()>0)this->m_strCommand = ar[0].MakeLower();//得到m_strCommand
// if(ar.GetCount()>1){
// for(int i=1;i<ar.GetCount();i++){
// this->m_arParam.Add(ar[i]);
// if(!this->m_strParam.IsEmpty())this->m_strParam+=" ";
// this->m_strParam += ar[i];
// }
// }
//}
//else
//{
// SocketTraceMO("else__else__else");
// this->m_strCommand=strMsg;
// SocketTraceMO("this->m_strCommand=strMsg;");
// this->m_strParam="";
//}
//if (!ar.IsEmpty())
// SocketTraceMO("ar.IsEmpty()");
// ar.RemoveAll();
//this->m_strPhonecode = CString(msg.tcMobileFrom);
//this->m_strSpCode=CString(msg.Dest_ID);
//CString strMsg(msg.pMessage);
//CStringArray ar;
//this->m_testMsg=strMsg; //by liu for test
//if(_splite(strMsg,&ar,"@@"))
//{
// // MOTrace0("enter cmomessage");
// if(ar.GetCount()>0)this->m_strCommand = ar[0].MakeLower();//得到m_strCommand
// if(ar.GetCount()>1){
// for(int i=1;i<ar.GetCount();i++){
// this->m_arParam.Add(ar[i]);
// if(!this->m_strParam.IsEmpty())this->m_strParam+=" ";
// this->m_strParam += ar[i];
// }
// }
//}
//else
//{
// this->m_strCommand=strMsg;
// this->m_strParam="";
//}
//if (!ar.IsEmpty())
// ar.RemoveAll();
//}
CMOSmgpMessage::~CMOSmgpMessage(){}
BOOL CMOSmgpMessage::IsValid(){
if(this->m_strPhonecode.IsEmpty())return FALSE;
if(this->m_strCommand.IsEmpty())return FALSE;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -