apidemo_cmpp3.c
上传用户:xd_1999
上传日期:2007-05-02
资源大小:2286k
文件大小:10k
- #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[32];
- unsigned char byFeeTerminalType;
- unsigned char byTPPID;
- unsigned char byTPUDHI;
- unsigned char byMsgFmt;
- char psMsgSrc[7];
- char psFeeType[3];
- char psFeeCode[7];
- char psValidTime[18];
- char psAtTime[18];
- char psSrcTerminalID[21];
- unsigned char byDestUsrTl;
- char psDestTerminalID[3200];
- unsigned char byDestTerminalType;
- unsigned char byMsgLength;
- char pMsgContent[252];
- char pLinkID[20];
- unsigned char *tmpPsz;
- /*
- ** 消息发送的序列号,用于配对发送消息以及其应答消息, 由应用程序保证其唯一
- */
- unsigned short LID, sLid;
- /*
- ** 接收提交消息的应答消息所需要的缓冲参数
- */
- unsigned char sGWMsgID[8];
- int iStatus;
- /*
- ** 接收短消息所需要的缓冲参数
- */
- unsigned char pMsgID[8];
- char pDestnationID[21], pSrcminalID[32];
- unsigned char byTPID;
- unsigned char bySrcTerminalType;
- /*
- ** 用于状态报告的缓冲区
- */
- char sState[8];
- char sSubmitTime[11];
- char sDoneTime[11];
- char sDestAddr[32];
- 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, "");
- byFeeUserType = 0;
- /*
- 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 = 1;
- /* 目的用户手机号码 */
- strcpy(psDestTerminalID, "13988800001");
- /*strcpy(psDestTerminalID + 21, "13988800002");
- strcpy(psDestTerminalID + 42, "13988800003");
- strcpy(psDestTerminalID + 63, "13988800004");
- strcpy(psDestTerminalID + 84, "13988800005");
- */
- byDestTerminalType = 0;
- /* 短消息内容 */
- strcpy(pMsgContent, "提交短消息678901234567890");
- /* 短消息内容的长度 */
- byMsgLength = strlen(pMsgContent);
- /* 保留字段,请填为空 */
- strcpy(pLinkID, "");
-
- ret = CMPP3Snd(
- byPkTotal,
- byPkNumber,
- byRegistered,
- byMsgLevel,
- pServiceID,
- byFeeUserType,
- psFeeTerminalID,
- byFeeUserType,
- byTPPID,
- byTPUDHI,
- byMsgFmt,
- psMsgSrc,
- psFeeType,
- psFeeCode,
- psValidTime,
- psAtTime,
- psSrcTerminalID,
- byDestUsrTl,
- psDestTerminalID,
- byDestTerminalType,
- byMsgLength,
- pMsgContent,
- pLinkID,
- LID);
-
- if( ret == SUCCESS)
- printf("nnSubmit SM Success!");
- else if(ret == FAILURE)
- {
- printf("nSubmit SM Fail!");
- getchar();
- }
- else
- {
- printf("nFatal Error!");
- getchar();
- }
- /*
- ** 接收 CMPP 提交消息的应答
- */
-
-
- ret = CMPP3GetSndAck( &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 = CMPP3GetSndAck( &sLid,
- sGWMsgID,
- &iStatus);
- }
- /*
- ** 接收从短消息中心下发来的短消息
- */
- memset(pMsgContent, 0, sizeof(pMsgContent));
- memset(pLinkID, 0, sizeof(pLinkID));
-
-
- ret = CMPP3Rcv(
- pMsgID,
- pDestnationID,
- pServiceID,
- &byTPID,
- &byTPUDHI,
- &byMsgFmt,
- pSrcminalID,
- &bySrcTerminalType,
- &byRegistered,
- &byMsgLength,
- pMsgContent,
- pLinkID);
- 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("npSrcTerminalType:%d", bySrcTerminalType);
- printf("nbyRegistered:%d", byRegistered);
- printf("nbyMsgLength:%d", byMsgLength);
- printf("npLinkID:%s", pLinkID);
- if (byRegistered == 1)
- {
- Cmpp3_Status_Report *pStatus = (Cmpp3_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, 31);
- 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(pLinkID, 0, sizeof(pLinkID));
-
- ret = CMPP3Rcv(
- pMsgID,
- pDestnationID,
- pServiceID,
- &byTPID,
- &byTPUDHI,
- &byMsgFmt,
- pSrcminalID,
- &bySrcTerminalType,
- &byRegistered,
- &byMsgLength,
- pMsgContent,
- pLinkID);
-
- }
-
-
- /* 等待3秒 */
- sleep(1);
- /*
- i = getchar();
- */
- }
- }