📄 mycmpp3client.cpp
字号:
/**
* MyCMPP3Client.cpp
*
* CMPP3 API Demo Application.
*
* Copyright 2003-2006 北京风起水流软件工作室
*
* http://www.zealware.com
*
* princetoad@gmail.com
*
*/
#include "stdafx.h"
#include "MyCMPP3Client.h"
MyCMPPClient::MyCMPPClient(CCMPP3APIDemoDlg & _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=%u|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 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;
}
dlg.ShowLog("DELIVER|SRCMOBILE:%s|SPNUMBER:%s|MSGFMT:%u|LENGTH:%u|MSG:%s|LINKID:%s;",
/*szSrcTerminalId*/deliver.sSrcterminalid,
/*szDstId*/deliver.sDestid,
/*bMsgFmt*/deliver.uchMsgfmt,
szMsg.GetLength(),
szMsg,
deliver.sLinkId
);
CMPPClient::OnReceivedConnectionDeliver(connection, deliver);
}
void MyCMPPClient::OnReceivedConnectionStatusReport(
CMPPConnection & connection,
cmpp_deliver sr
)
{
cmpp_status_report * preport = &sr.MO_Msg_Content.csr;
CString msgid = _T("");
msgid.Format("%I64u", sr.MO_Msg_Content.csr.nMsgid);
dlg.ShowLog(
"REPORT|STATE:%s|DESTTERMINALID:%s|DONETIME:%s|SUBMITTIME:%s|SMSCSEQID:%u|MSGID:%s;",
/*state*/preport->sStat,
preport->sDestTerminalId,
preport->sDoneTime,
preport->sSubmitTime,
preport->nSmscSeq,
msgid
);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -