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

📄 cmppapi_test.cpp

📁 中国移动通信CMPP2.0开发库,其中包括Demo和Lib库,Demo中有客户端和服务器的代码
💻 CPP
字号:
// cmppapi_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

//包含需要的文件.
#include "md5.h"
#include "cmpp.h"

#pragma comment(lib, "cmppapi.lib")

#define CMPP_IMPORT

//用一全局变量记录SubmitResp中的MsgId,用于测试Cancel命令.
_int64 g_nMsgid = 0;
 
void OnSmgMsg(CMPP_SMGTOSP css)
{
	printf("这是消息处理函数打印出来的:**smg msg,len = %d, cmd = 0x%08x, seq = %d**\n", \
		css.pk_head.nTotalLength, css.pk_head.nCommandId, css.pk_head.nSeqId);

	if (css.pk_head.nCommandId == 0x80000004) {
		g_nMsgid = css.pk_body.pk_submitresp.nMsgid;
	}
	return;
}

void OutProgramInfo()
{
	printf("\n*****************************************************************************\n");
	printf("**软件名称 - <<中国移动通信CMPP2.0短消息网关开发接口库>> V2.00 客户端例程.\n");
	printf("**作者主页 - http://princetoad.xiloo.com\n");
	printf("**联系方式 - Email:princetoad@126.com\n");
	printf("**授权方式 - Used Free,SourceCode On Sale.\n");
	printf("**********************Published By PrinceToad Nov.29.03.*********************\n\n");
}

//标准cmpp方式,MOMT同一连接的演示例程.
int main(int argc, char* argv[])
{
	int nRetCode = 0;
	unsigned int nSeq = 0;

	OutProgramInfo();

	CCmppClient cmpp;

	printf("Press Any To Start CmppClient.\n");
	system("pause");
	//1.启动CMPPCLIENT模块.
	//参数的含义(具体可以参考使用手册):网关地址,网关端口,登陆用户名,口令,版本号(最好填0x12),网关连接类型.
	//网关连接类型(0:标准单连接cmpp方式,如思特奇,华为,标准东软,1:亚信双连接,2:清华声讯双端口)

	//本地测试(由于众所周知的原因,下面真实网关的IP,用户名口令都被屏蔽了,用户可以根据自己的参数进行修改.)
	nRetCode = cmpp.Start("127.0.0.1", 7890, "901234", "password", 0x20, OnSmgMsg, 0);

	//连接思特奇
//	nRetCode = cmpp.Start("127.0.0.1", 8778, "901234", "password", 0x12, OnSmgMsg, 0);
	
	//连接华为
//	nRetCode = cmpp.Start("127.0.0.1", 7890, "901234", "password", 0x12, OnSmgMsg, 0);
	
	//连接东软(标准)
//	nRetCode = cmpp.Start("127.0.0.1", 7890, "901234", "password", 0x12, OnSmgMsg, 0);
	
	//连接亚信
//	nRetCode = cmpp.Start("127.0.0.1", 7890, "901234", "password", 0x12, OnSmgMsg, 1);
	
	//连接清华声讯(需要在调用Start函数之前调用SetDoublePort函数设定MOMT端口号)
//	cmpp.SetDoublePort(7910, 7890);
//	nRetCode = cmpp.Start("127.0.0.1", 7890, "901234", "password", 0x20, OnSmgMsg, 2);

	if (0 != nRetCode) {
		printf("CmppClient Start Failed With Error: %d.\n", nRetCode);
		system("pause");
		return nRetCode;
	}
	else {
		printf("CmppClient Module Start Success,Press Any To Test Submit Command.\n");
		system("pause");
	}
	
	//2.测试SUBMIT命令.
	for (int ix=0; ix<1; ix++) {
		//submit的各参数与cmpp2.0中的submit包内容相对应.
		//这里只负责把submit包发出去,不负责接收submitresp以及可能要求的状态报告,
		//submitresp包和状态报告均须在OnSmgMsg函数中处理.

		//得到submit包的流水号,通过与submitresp的流水号比较,得到submit包的MsgId.
		//与状态报告的MsgId比较可以知道此条消息是否已经发到用户手上.
		nSeq = cmpp.GetSeqId();

		nRetCode = cmpp.Submit(0, 1, 1, \
			0, 3, "1234", \
			0, "13912345678", 0, \
			0, 0, "13912345678", \
			"123", "456", NULL, \
			NULL, "666", 1, \
			"13912345678", 4, "test");
		
		printf("Submit result : %d, SeqId = %d\n", nRetCode, nSeq);
	}

	printf("Press Any To Test Query Command.\n");
	system("pause");

	//3.测试QUERY命令.
	nSeq = cmpp.GetSeqId();

	nRetCode = cmpp.Query("20031120", 0);		//查询总量.
	printf("Query result : %d, SeqId = %d\n", nRetCode, nSeq);

	printf("Press Any To Test Cancel Command.\n");
	system("pause");
	//4.测试CANCEL命令.
	nSeq = cmpp.GetSeqId();

	nRetCode = cmpp.Cancel(g_nMsgid);
	printf("Cancel result : %d, SeqId = %d\n", nRetCode, nSeq);

	printf("Press Any To Test ActiveTest Command.\n");
	system("pause");
	//5.测试ACTIVETEST命令.
	nSeq = cmpp.GetSeqId();

	nRetCode = cmpp.ActiveTest();
	printf("ActiveTest result : %d, SeqId = %d\n", nRetCode, nSeq);

	printf("Press Any To Test Terminate Command And Release CmppClient Module.\n");
	system("pause");
	//6.测试TERMINATE命令.
	cmpp.Release();

	printf("Press Any To Exit This Test Program.\n");
	system("pause");

	return 0;
}

⌨️ 快捷键说明

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