apidemo_smgp.c
上传用户:xd_1999
上传日期:2007-05-02
资源大小:2286k
文件大小:12k
- #include <stdio.h>
- #include <stdlib.h>
- #include <netinet/in.h>
- #include "proxy_api.h"
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int ret;
- int i, j;
- /*
- ** 发送短消息所需要的参数
- */
- unsigned char byPkTotal;
- unsigned char byPkNumber;
- unsigned char byRegistered;
- unsigned char byMsgLevel;
- char pServiceID[11];
- unsigned char byFeeUserType;
- char psFeeTerminalID[21];
- unsigned char byTPPID;
- unsigned char byTPUDHI;
- unsigned char byMsgFmt;
- char psMsgSrc[7];
- char psFeeType[3];
- char psFeeCode[7];
- char psFixedFee[7];
- char psValidTime[18];
- char psAtTime[18];
- char psSrcTerminalID[21];
- unsigned char byDestUsrTl;
- char psDestTerminalID[2100];
- unsigned char byMsgLength;
- char pMsgContent[252];
- char pReserve[9];
- unsigned char *tmpPsz;
- /*
- ** 消息发送的序列号,用于配对发送消息以及其应答消息, 由应用程序保证其唯一
- */
- unsigned short LID, sLid;
- /*
- ** 接收提交消息的应答消息所需要的缓冲参数
- */
- /* lizhi mod smgp */
- /*unsigned char sGWMsgID[8]; */
- unsigned char sGWMsgID[21];
- int iStatus;
- /*
- ** 接收短消息所需要的缓冲参数
- */
- /* lizhi mod smgp */
- /*unsigned char pMsgID[8]; */
- unsigned char pMsgID[21];
- char pDestnationID[21], pSrcminalID[21];
- unsigned char byTPID;
- /* lizhi test smgp */
- char pRecvTime[15];
- /*
- ** 用于状态报告的缓冲区
- */
- char sState[8];
- char sSubmitTime[11];
- char sDoneTime[11];
- char sDestAddr[21];
- unsigned long ulSmscSequenceID;
- LID = 0;
- /*
- ** 连接到短消息代理服务器上
- */
- ret = proxy_login(1);
- if(ret == SUCCESS)
- printf("nLogin Success!");
- else if(ret == FAILURE)
- printf("nLogin Fail!");
- else
- printf("nFatal Error!");
- for(;;)
- {
- /******************************************************
- ** 提交短消息
- *******************************************************/
- LID ++; /* 应用程序自身的序列号,请自己保证唯一,建议采用++操作 */
- /* 请设置为1 */
- byPkTotal = 1;
- /* 请设置为1 */
- byPkNumber = 1;
- /* 1:需要状态报告,0:不需要状态报告 */
- byRegistered = 1;
- /* 信息级别 */
- byMsgLevel = 0;
- /* 业务类别 */
- strcpy(pServiceID, "goodnews");
- /* 计费用户类型字段,
- * 0:对目的终端MSISDN计费;
- 1:对源终端MSISDN计费;
- 2:对SP计费;
- 3:表示本字段无效,对谁计费参见psFeeTerminalID参数。
- */
- byFeeUserType = 0;
- /* 被计费用户的号码(如本字节填空,则表示本字段无效,
- 对谁计费参见byFeeUserType字段。本字段与Fee_UserType字段互斥)
- */
- strcpy(psFeeTerminalID, "");
- /*
- GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.9
- 此值请填0
- */
- byTPPID = 0;
- /*
- GSM协议类型。表示是否有头结构,详细是解释请参考GSM03.40中的9.2.3.23,仅使用1位,右对齐
- 请填写为0。
- */
- byTPUDHI = 0;
- /*
- 信息格式 0:ASCII串 3:短信写卡操作 4:二进制信息 8:UCS2编码15:含GB汉字 。。。。。。
- */
- byMsgFmt = 8;
- /* 信息内容来源(SP_ID) */
- strcpy(psMsgSrc, "huawei");
- /* 资费类别 */
- strcpy(psFeeType, "01");
- /* 资费代码(以分为单位)*/
- strcpy(psFeeCode, "999");
- /* 包月费率(以分为单位) */
- strcpy(psFixedFee, "");
- /* 有效期,一般填空 */
- strcpy(psValidTime, "");
- /* 定时发送时间,一般填空 */
- strcpy(psAtTime, "");
- /* 源终端MSISDN号码, 即此短消息的主叫地址*/
- strcpy(psSrcTerminalID, "3333");
- /* 目的地址个数,强制为1,为以后扩展使用 */
- byDestUsrTl = 5;
- /* 目的用户手机号码 */
- strcpy(psDestTerminalID, "13988800001");
- strcpy(psDestTerminalID + 21, "13988800002");
- strcpy(psDestTerminalID + 42, "13988800003");
- strcpy(psDestTerminalID + 63, "13988800004");
- strcpy(psDestTerminalID + 84, "13988800005");
- /* 短消息内容 */
- strcpy(pMsgContent, "提交短消息678901234567890");
- /* 短消息内容的长度 */
- byMsgLength = strlen(pMsgContent);
- /* 保留字段,请填为空 */
- strcpy(pReserve, "");
-
- /* test smgp lizhi */
- /*
- ret = CMPPSnd(
- byPkTotal,
- byPkNumber,
- byRegistered,
- byMsgLevel,
- pServiceID,
- byFeeUserType,
- psFeeTerminalID,
- byTPPID,
- byTPUDHI,
- byMsgFmt,
- psMsgSrc,
- psFeeType,
- psFeeCode,
- psValidTime,
- psAtTime,
- psSrcTerminalID,
- byDestUsrTl,
- psDestTerminalID,
- byMsgLength,
- pMsgContent,
- pReserve,
- LID);
- */
- ret = SMGPSnd(
- 3,
- byRegistered,
- byMsgLevel,
- pServiceID,
- psFeeType,
- psFeeCode,
- "",
- byMsgFmt,
- psValidTime,
- psAtTime,
- psSrcTerminalID,
- psFeeTerminalID,
- byDestUsrTl,
- psDestTerminalID,
- byMsgLength,
- pMsgContent,
- pReserve,
- LID);
-
- if( ret == SUCCESS)
- printf("nnSubmit SM Success!");
- else if(ret == FAILURE)
- {
- printf("nSubmit SM Fail!");
- getchar();
- }
- else
- {
- printf("nFatal Error!");
- getchar();
- }
- /*
- ** 接收 CMPP 提交消息的应答
- */
-
- /* test smgp
- ret = CMPPGetSndAck( &sLid, 此值为发送短消息时,应用程序填写的序列号
- sGWMsgID, 网关返回的消息ID
- &iStatus); 此条生消息发送到短消息中心时的状态,0表示成功,其它表示失败 */
-
- ret = SMGPGetSndAck( &sLid, /*此值为发送短消息时,应用程序填写的序列号*/
- sGWMsgID, /* 网关返回的消息ID */
- &iStatus); /* 此条生消息发送到短消息中心时的状态,0表示成功,其它表示失败 */
- while( ret == SUCCESS ) /* 接收成功 */
- {
- printf("nrecv submit ack:LID = %d", LID);
- printf("nGW Msg ID:");
- for (i = 0; i < 8; i++)
- {
- printf("%02x_", sGWMsgID[i]);
- }
- printf("nStatus:%dn", iStatus);
- /* 看是否还有其这的应答消息 */
-
- /*
- ret = CMPPGetSndAck( &sLid,
- sGWMsgID,
- &iStatus);
- */
- ret = SMGPGetSndAck( &sLid,
- sGWMsgID,
- &iStatus);
- }
- /*
- ** 接收从短消息中心下发来的短消息
- */
- memset(pMsgContent, 0, sizeof(pMsgContent));
- memset(pReserve, 0, sizeof(pReserve));
-
-
- /*ret = CMPPRcv(
- pMsgID, 网关返回的消息ID
- pDestnationID, 目的地址,一般为业务的接入地址码
- pServiceID, 业务类别
- &byTPID,
- &byTPUDHI,
- &byMsgFmt, 信息格式 0:ASCII串 3:短信写卡操作 4:二进制信息 8:UCS2编码15:含GB汉字 。。。。。。
- pSrcminalID, 主叫号码,一般为用户手机号码
- &byRegistered, 1:需要状态报告,0:普通短消息
- &byMsgLength, 短消息的长度
- pMsgContent, 短消息的内容
- pReserve); */
- ret = SMGPRcv(
- &byRegistered, /* 1:需要状态报告,0:普通短消息 */
- pMsgID, /* 网关返回的消息ID */
- &byMsgFmt, /*信息格式 0:ASCII串 3:短信写卡操作 4:二进制信息 8:UCS2编码15:含GB汉字 。。。。。。*/
- pRecvTime,
- pSrcminalID, /* 主叫号码,一般为用户手机号码 */
- pDestnationID, /* 目的地址,一般为业务的接入地址码 */
- &byMsgLength, /* 短消息的长度 */
- pMsgContent, /* 短消息的内容 */
- pReserve);
- while( ret == SUCCESS)
- {
- printf("nnRecv sm Success!");
- printf("npMsgID:");
- for (i = 0; i < 8; i++)
- {
- printf("%02x_", pMsgID[i]);
- };
- printf("npDestnationID:%s", pDestnationID);
- printf("npServiceID:%s", pServiceID);
- printf("nbyTPID:%d", byTPID);
- printf("nbyTPUDHI:%d", byTPUDHI);
- printf("nbyMsgFmt:%d", byMsgFmt);
- printf("npSrcminalID:%s", pSrcminalID);
- printf("nbyRegistered:%d", byRegistered);
- printf("nbyMsgLength:%d", byMsgLength);
- printf("npReserve:%s", pReserve);
- /*
- if (byRegistered == 1) //状态报告消息
- {
- Cmpp_Status_Report *pStatus = (Cmpp_Status_Report *)pMsgContent;
-
- memset(sState, 0, sizeof(sState));
- memset(sSubmitTime, 0, sizeof(sSubmitTime));
- memset(sDoneTime, 0, sizeof(sDoneTime));
- memset(sDestAddr, 0, sizeof(sDestAddr));
- memcpy(sState, pStatus->sState, 7);
- memcpy(sSubmitTime, pStatus->sSubmitTime, 10);
- memcpy(sDoneTime, pStatus->sDoneTime, 10);
- memcpy(sDestAddr, pStatus->sDestAddr, 20);
- ulSmscSequenceID = ntohl(pStatus->ulSmscSequenceID);
- printf("nnpStatus report:");
- printf("npMsgID:");
- for (i = 0; i < 8; i++)
- {
- printf("%02x_", pStatus->byMsgID[i]);
- };
- printf("nsState:%s", sState);
- printf("nsSubmitTime:%s", sSubmitTime);
- printf("nsDoneTime:%s", sDoneTime);
- printf("nsDestAddr:%s", sDestAddr);
- printf("nulSmscSequenceID:%d", ulSmscSequenceID);
- }
- else // 一般的下发短消息
- {
- printf("npMsgContent(txt):%s", pMsgContent);
- }
- */
- printf("npMsgContent(txt):%s", pMsgContent);
-
- /*
- ** 短消息内容的16进制显示
- */
- printf("nSM Data Content(hex):");
- tmpPsz = (unsigned char *)pMsgContent;
- while(byMsgLength > 0)
- {
- if(byMsgLength > 16)
- j = 16;
- else
- j = byMsgLength;
- for(i = 0; i< j; i++)
- {
- printf("%02x_", *(tmpPsz + i));
- }
- printf("rn");
- byMsgLength -= j;
- tmpPsz += 16;
- }
-
- /*
- ** 看是否还有其它的消息
- */
- memset(pMsgContent, 0, sizeof(pMsgContent));
- memset(pReserve, 0, sizeof(pReserve));
-
- /* lizhi test smgp */
- /*
- ret = CMPPRcv(
- pMsgID,
- pDestnationID,
- pServiceID,
- &byTPID,
- &byTPUDHI,
- &byMsgFmt,
- pSrcminalID,
- &byRegistered,
- &byMsgLength,
- pMsgContent,
- pReserve);
- */
- ret = SMGPRcv(
- &byRegistered,
- pMsgID,
- &byMsgFmt,
- pRecvTime,
- pSrcminalID,
- pDestnationID,
- &byMsgLength,
- pMsgContent,
- pReserve);
-
- }
-
-
- /* 等待3秒 */
- sleep(1);
- /*
- i = getchar();
- */
- }
- }