⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysmgp3client.cpp

📁 SMAL是short message abstract library的缩写,是由风起水流软件工作室(www.zealware.com)开发的一个支持短信网关系统开发的C++底层抽象接口库
💻 CPP
字号:
/**
*	MySMGP3Client.cpp
*	
*	SMGP3 API Demo Application.
*
*	Copyright 2003-2007	北京风起水流软件工作室
*	
*	http://www.zealware.com
*	
*	princetoad@gmail.com princetoad@zealware.com
*
*/

#include "stdafx.h"

#include "MySMGP3Client.h"

MySMGPClient::MySMGPClient(CSMGP3APIDemoDlg & _dlg)
:dlg(_dlg)
{
}

MySMGPClient::~MySMGPClient()
{
}

void MySMGPClient::OnConnectionLogWrite(SMGPConnection & connection, const char * str)
{
	dlg.ShowLog(str);
}

void MySMGPClient::DumpStatus(SMGPConnection & 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 MySMGPClient::Release()
{
	SMGPClient::Release();
}

BOOL MySMGPClient::OnConnectionSubmiting(
	SMGPConnection & connection,
	smgp_submit _message
	)
{
	return TRUE;
}

void MySMGPClient::OnConnectionSubmited(
										SMGPConnection & connection, 
										smgp_submit _message
										)
{
	dlg.ShowLog(
		"SUBMIT|SERVICEID:%s|FEETYPE:%s|FEECODE:%s|SRCID:%s|DESTID:%s|MSG:%s|SUBMITMSGTYPE:%d|LINKID:%s;",
		_message.sServiceId,
		_message.sFeeType,
		_message.sFeeCode,
		_message.sSrcId,
		_message.sDstTerminalId,
		_message.sMsgContent,
		(int)_message.tlvSubmitMsgType,
		_message.tlvLinkID
		);

	SMGPClient::OnConnectionSubmited(connection, _message);
}

void MySMGPClient::OnConnectionSubmitFailed(
	SMGPConnection & connection, 
	smgp_submit _message 
	)
{
	SMGPClient::OnConnectionSubmitFailed(connection, _message);
}

void MySMGPClient::OnReceivedConnectionSubmitResponse(
	SMGPConnection & connection, 
	smgp_submit_deliver_resp resp
	)
{
	char sTemp[MAX_PATH] = "";
	ConvertMsgId( sTemp, (unsigned char *)resp.sMsgid );

	dlg.ShowLog(
		"SUBMITRESP|SEQID=%u|RESULT=%d|MSGID=%s;",
		resp.nSeqId,
		resp.nResult,
		sTemp
		);

	SMGPClient::OnReceivedConnectionSubmitResponse(connection, resp);
}

void MySMGPClient::OnConnectionCleared(SMGPConnection & connection)
{
	//DumpStatus(connection);

	return;
}

void MySMGPClient::OnReceivedConnectionDeliver(
	SMGPConnection & connection, 
	smgp_deliver deliver
	)
{
	char szMsgId[MAX_PATH] = "";
	char szMsg[MAX_PATH] = "";

	unsigned nMsgLen = deliver.uchMsglength;

	ConvertMsgId( szMsgId, (unsigned char *)deliver.sMsgid );
	memcpy( szMsg, (const char *)(deliver.MO_Msg_Content.sMsgcontent), nMsgLen > MAX_PATH ? MAX_PATH : nMsgLen);

	if ( deliver.uchMsgfmt == 8 ) {
		// 转换UCS2
		char  sMultiByte[141] = "";
		unsigned char uchTmp = 0;
		unsigned char pchTmp[1024] = "";
		memcpy(pchTmp, deliver.MO_Msg_Content.sMsgcontent, nMsgLen);
		// 高低字节转换
		for (int ix=0; ix<nMsgLen/2; ix++) {
			uchTmp = pchTmp[ix*2];				// 低
			pchTmp[ix*2] = pchTmp[ix*2 + 1];	// 低 = 高
			pchTmp[ix*2 + 1] = uchTmp;			// 高 = 低
		}
		int nRet = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, (LPCWSTR)pchTmp, nMsgLen/2, sMultiByte, 140, NULL, NULL);	
		if ( strlen(sMultiByte) > 0 )
			memcpy( szMsg, sMultiByte, strlen(sMultiByte) );
	}

	dlg.ShowLog("DELIVER|SRCMOBILE:%s|SPNUMBER:%s|MSGFMT:%u|LENGTH:%u|MSG:%s|LINKID:%s|SUBMITMSGTYPE:%d;", 
		deliver.sSrcterminalid, 
		deliver.sDestid, 
		(int)deliver.uchMsgfmt, 
		strlen(szMsg),
		szMsg,
		deliver.tlvLinkID.value,
		(int)deliver.tlvSubmitMsgType.value
		);	

	SMGPClient::OnReceivedConnectionDeliver(connection, deliver);
}


void MySMGPClient::OnReceivedConnectionStatusReport(
	SMGPConnection & connection, 
	smgp_deliver sr
	)
{
	smgp_status_report * preport = &sr.MO_Msg_Content.csr;
	char msgid[MAX_PATH] = "";
	ConvertMsgId( msgid, (unsigned char*)preport->SR_id );

	dlg.ShowLog(
		"REPORT|STATE:%s|DONETIME:%s|SUBMITTIME:%s|MSGID:%s;",
		preport->SR_state,
		preport->SR_donedate,
		preport->SR_submitdate,
		msgid
		);

	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -