📄 mycmppclient.cpp
字号:
/**
* MyCMPPClient.cpp
*
* CMPP API Demo Application.
*
* Copyright 2003-2006 北京风起水流软件工作室
*
* http://www.zealware.com
*
* princetoad@gmail.com
*
*/
#include "stdafx.h"
#include "MyCMPPClient.h"
MyCMPPClient::MyCMPPClient(CCMPPAPIDemoDlg & _dlg)
:dlg(_dlg)
{
}
MyCMPPClient::~MyCMPPClient()
{
}
//void MyCMPPClient::OnConnectionLogWrite(CMPPConnection & connection, const char * str)
//{
// dlg.ShowLog(str);
//}
void MyCMPPClient::OnLogWrite(const char * pchFmt, ...)
{
try
{
char buffer[1024*2] = "";
va_list arglist;
va_start( arglist, pchFmt );
#if defined(_MSC_VER) && _MSC_VER >= 1400
vsprintf_s( buffer, 1024, pchFmt, arglist );
#else
_vsnprintf( buffer, 1024, pchFmt, arglist );
#endif
va_end(arglist);
dlg.ShowLog( buffer );
}
catch(...)
{
}
return;
}
void MyCMPPClient::DumpStatus(CMPPConnection & connection)
{
dlg.ShowLog("INFO|TOKEN=%s|MT_OK=%u|MT_FAIL=%u|RESP_OK=%u|RESP_FAIL=%u|MO=%u|SR=%u;\n",
connection.GetToken(),
connection.GetSubmitSucceedCount(),
connection.GetSubmitFailedCount(),
connection.GetRespSucceedCount(),
connection.GetRespFailedCount(),
connection.GetDeliverCount(),
connection.GetStatusReportCount());
}
void MyCMPPClient::Release()
{
CMPPClient::Release();
}
BOOL MyCMPPClient::OnConnectionSubmiting(
CMPPConnection & connection,
cmpp_submit _message
)
{
return TRUE;
}
void MyCMPPClient::OnConnectionSubmited(
CMPPConnection & connection,
cmpp_submit _message
)
{
dlg.ShowLog("SUBMIT|SERVICEID:%s|FEETYPE:%s|FEECODE:%s|SRCID:%s|DESTID:%s|MSG:%s;",
_message.sServiceId,
_message.sFeeType,
_message.sFeeCode,
_message.sSrcId,
_message.sDstTerminalId,
_message.sMsgContent
);
CMPPClient::OnConnectionSubmited(connection, _message);
}
void MyCMPPClient::OnConnectionSubmitFailed(
CMPPConnection & connection,
cmpp_submit _message
)
{
CMPPClient::OnConnectionSubmitFailed(connection, _message);
}
void MyCMPPClient::OnReceivedConnectionSubmitResponse(
CMPPConnection & connection,
cmpp_submit_deliver_resp resp
)
{
CString sMsgId = _T("");
sMsgId.Format("%I64u", resp.nMsgid);
dlg.ShowLog(
"SUBMITRESP|SEQID=%u|RESULT=%d|MSGID=%s;",
resp.nSeqId,
resp.nResult,
sMsgId
);
CMPPClient::OnReceivedConnectionSubmitResponse(connection, resp);
}
void MyCMPPClient::OnConnectionCleared(CMPPConnection & connection)
{
//DumpStatus(connection);
return;
}
void MyCMPPClient::OnReceivedConnectionDeliver(
CMPPConnection & connection,
cmpp_deliver deliver
)
{
CString szMsgId = _T("");
szMsgId.Format("%I64u", hton64(deliver.nMsgid));
//CString szDstId = GetSubStr(deliver.sDestid, /*32*/21);
//unsigned bMsgFmt = deliver.uchMsgfmt;
//CString szSrcTerminalId = GetSubStr(deliver.sSrcterminalid, /*32*/21);
CString szMsg = deliver.MO_Msg_Content.sMsgcontent;
if (deliver.uchMsgfmt == 8) {
// 转换UCS2
char sMultiByte[141] = "";
unsigned char uchTmp = 0;
unsigned char pchTmp[1024] = "";
memcpy(pchTmp, deliver.MO_Msg_Content.sMsgcontent, deliver.uchMsglength);
for (int ix=0; ix<deliver.uchMsglength/2; ix++) {
uchTmp = pchTmp[ix*2];
pchTmp[ix*2] = pchTmp[ix*2 + 1];
pchTmp[ix*2 + 1] = uchTmp;
}
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, (LPCWSTR)pchTmp, deliver.uchMsglength/2, sMultiByte, 140, NULL, NULL);
szMsg = sMultiByte;
}
//CString szLinkId = GetSubStr(deliver.sLinkId, 20);
dlg.ShowLog(
"DELIVER|SRCMOBILE:%s|SPNUMBER:%s|MSGFMT:%u|LENGTH:%u|MSG:%s|LINKID:%s;",
deliver.sSrcterminalid,
deliver.sDestid,
deliver.uchMsgfmt,
szMsg.GetLength(),
szMsg,
deliver.sLinkId
);
CMPPClient::OnReceivedConnectionDeliver(connection, deliver);
}
void MyCMPPClient::OnReceivedConnectionStatusReport(
CMPPConnection & connection,
cmpp_deliver sr
)
{
//CString state = GetSubStr(sr.MO_Msg_Content.csr.sStat, 7);
//CString destid = GetSubStr(sr.MO_Msg_Content.csr.sDestTerminalId, /*32*/21);
//CString donetime = GetSubStr(sr.MO_Msg_Content.csr.sDoneTime, 10);
//CString submittime = GetSubStr(sr.MO_Msg_Content.csr.sSubmitTime, 10);
//unsigned smscid = sr.MO_Msg_Content.csr.nSmscSeq;
CString msgid = _T("");
msgid.Format("%I64u", sr.MO_Msg_Content.csr.nMsgid);
cmpp_status_report * preport = &sr.MO_Msg_Content.csr;
dlg.ShowLog(
"REPORT|STATE:%s|DESTTERMINALID:%s|DONETIME:%s|SUBMITTIME:%s|SMSCSEQID:%u|MSGID:%s;",
preport->sStat,
preport->sDestTerminalId,
preport->sDoneTime,
preport->sSubmitTime,
preport->nSmscSeq,
msgid
);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -