📄 mycmpp3client.cpp
字号:
/**
* MyCMPP3Client.cpp
*
* CMPP3 API Demo Application.
*
* Copyright 2003-2006 北京风起水流软件工作室
*
* http://www.zealware.com
*
* princetoad@gmail.com
*
*/
#include "stdafx.h"
#include "MyCMPP3Client.h"
///**截取字符串
//*/
//CString GetSubStr(void* pchBuf, int nLen)
//{
// CString szValue("");
// char sBuffer[256] = "";
//
// try {
// CopyMemory(sBuffer, pchBuf, nLen > 256 ? 256 : nLen);
//
// szValue.Format("%s", sBuffer);
// }
// catch(...) {
//#ifdef _DEBUG
// AfxMessageBox("EXCEPTIONS|GetSubStr;");
//#endif
// }
//
// return szValue;
//}
MyCMPPClient::MyCMPPClient(CCMPP3APIDemoDlg & _dlg)
:dlg(_dlg)
{
}
MyCMPPClient::~MyCMPPClient()
{
}
void MyCMPPClient::OnConnectionLogWrite(CMPPConnection & connection, const char * str)
{
dlg.ShowLog(str);
}
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;",
GetSubStr(_message.sServiceId, 10),
GetSubStr(_message.sFeeType, 2),
GetSubStr(_message.sFeeCode, 6),
GetSubStr(_message.sSrcId, 21),
GetSubStr(_message.sDstTerminalId, /*32*/LENGTH_OF_MSISDN_IN_MOMT),
_message.sMsgContent);
return CMPPClient::OnConnectionSubmited(connection, _message);
}
void MyCMPPClient::OnConnectionSubmitFailed(
CMPPConnection & connection,
cmpp_submit _message
)
{
return 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);
return 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, 21);
unsigned bMsgFmt = deliver.uchMsgfmt;
CString szSrcTerminalId = GetSubStr(deliver.sSrcterminalid, /*32*/LENGTH_OF_MSISDN_IN_MOMT);
CString szMsg = GetSubStr(deliver.MO_Msg_Content.sMsgcontent, deliver.uchMsglength);
if (bMsgFmt == 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;",
szSrcTerminalId,
szDstId,
bMsgFmt,
szMsg.GetLength(),
szMsg,
szLinkId
);
return 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*/LENGTH_OF_MSISDN_IN_MOMT);
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);
dlg.ShowLog(
"REPORT|STATE:%s|DESTTERMINALID:%s|DONETIME:%s|SUBMITTIME:%s|SMSCSEQID:%u|MSGID:%s;",
state,
destid,
donetime,
submittime,
smscid,
msgid
);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -