apidemo_sgip.c
上传用户:xd_1999
上传日期:2007-05-02
资源大小:2286k
文件大小:9k
- #include <stdio.h>
- #include <stdlib.h>
- #include <netinet/in.h>
- #include "proxy_api.h"
- typedef unsigned long ULONG;
- typedef struct tagPureSgipHead
- {
- ULONG nLen;
- ULONG nCmdID;
- ULONG nNodeNum;
- ULONG nTime;
- ULONG nSequenceID;
- }tagPureSgipHead;
- typedef tagPureSgipHead tagSgipHead;
- #define SGIP_DELIVER 0x00000004
- #define SGIP_REPORT 0x00000005
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int ret;
- int i, j;
- /*
- ** 发送短消息所需要的参数
- */
- char psSPNumber[22];
- char psChargeNumber[22];
- unsigned char byUserCount;
- char psUserNumber[2100];
- char psCorpId[6];
- char psServiceType[11];
- unsigned char byFeeType;
- char psFeeValue[7];
- char psGivenValue[7];
- unsigned char byAgentFlag;
- unsigned char byMTFlag;
- unsigned char byPriority;
- char psExpireTime[17];
- char psScheduleTime[17];
- unsigned char byReportFlag;
- unsigned char byTPPID;
- unsigned char byTPUDHI;
- unsigned char byMsgCoding;
- unsigned char byMsgType;
- unsigned int nMsgLen;
- char psMsgContent[161];
- char pReserve[9];
- unsigned char *tmpPsz;
- /*
- ** 消息发送的序列号,用于配对发送消息以及其应答消息, 由应用程序保证其唯一
- */
- unsigned short LID, sLid;
- /*
- ** 接收提交消息的应答消息所需要的缓冲参数
- */
- int iStatus;
- char pSubmitAckReserve[9];
- /*
- ** 接收短消息所需要的缓冲参数
- */
- /*
- char psDeliverUserNumber[22];
- char psDeliverSPNumber[22];
- unsigned char byDeliverTPPID;
- unsigned char byDeliverTPUDHI;
- unsigned char byDeliverMsgCoding;
- unsigned int nDeliverMsgLen;
- char psDeliverMsgContent[161];
- char psDeliverReserve[9];
- */
- /*
- ** 用于状态报告的缓冲区
- */
- unsigned long ulOrgNodeNum;
- unsigned long ulOrgTimeStamp;
- unsigned long ulOrgSequence;
- unsigned char byReportType;
- char psReportUserNum[22];
- unsigned char bystate;
- unsigned char byErrCode;
- char psReportReserve[9];
- char sMsg[2048];
- int nLen;
- 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 ++; /* 应用程序自身的序列号,请自己保证唯一,建议采用++操作 */
- strcpy(psSPNumber, "8888");
- strcpy(psChargeNumber, "13301001234");
- byUserCount = 1;
- strcpy(psUserNumber, "13301001234");
- strcpy(psCorpId, "12345");
- strcpy(psServiceType, "TPCQ");
- byFeeType = 2;
- strcpy(psFeeValue, "20");
- strcpy(psGivenValue, "0");
- byAgentFlag = 0;
- byMTFlag = 0;
- byPriority = 0;
- psExpireTime[0] = 0;
- psScheduleTime[0] = 0;
- byReportFlag = 1;
- byTPPID = 0;
- byTPUDHI = 0;
- byMsgCoding = 8;
- byMsgType = 0;
- strcpy(psMsgContent, "测试短消息12345");
- nMsgLen = strlen(psMsgContent);
-
- /* 保留字段,请填为空 */
- strcpy(pReserve, "");
-
- ret = SGIPSnd(
- psSPNumber,
- psChargeNumber,
- byUserCount,
- psUserNumber,
- psCorpId,
- psServiceType,
- byFeeType,
- psFeeValue,
- psGivenValue,
- byAgentFlag,
- byMTFlag,
- byPriority,
- psExpireTime,
- psScheduleTime,
- byReportFlag,
- byTPPID,
- byTPUDHI,
- byMsgCoding,
- byMsgType,
- nMsgLen,
- psMsgContent,
- pReserve,
- LID);
-
- if( ret == SUCCESS)
- printf("nnSubmit SM Success!");
- else if(ret == FAILURE)
- {
- printf("nSubmit SM Fail!");
- getchar();
- }
- else
- {
- printf("nFatal Error!");
- getchar();
- }
- /*
- ** 接收 CMPP 提交消息的应答
- */
- ret = SGIPGetSndAck( &sLid, /*此值为发送短消息时,应用程序填写的序列号*/
- &ulOrgNodeNum, &ulOrgTimeStamp, &ulOrgSequence,
- &iStatus); /* 此条生消息发送到短消息中心时的状态,0表示成功,其它表示失败 */
- while( ret == SUCCESS ) /* 接收成功 */
- {
- printf("nrecv submit ack:LID = %d", LID);
- printf("nNodeNum:%u, Time:%u, Sequence:%un", ulOrgNodeNum, ulOrgTimeStamp, ulOrgSequence);
- printf("nStatus:%dn", iStatus);
- /* 看是否还有其这的应答消息 */
-
- ret = SGIPGetSndAck( &sLid,
- &ulOrgNodeNum, &ulOrgTimeStamp, &ulOrgSequence,
- &iStatus);
- }
- /*
- ** 接收从短消息中心下发来的短消息
- */
- memset(psUserNumber, 0, sizeof(psUserNumber));
- memset(psSPNumber, 0, sizeof(psSPNumber));
- memset(psMsgContent, 0, sizeof(psMsgContent));
- memset(pReserve, 0, sizeof(pReserve));
- //char sMsg[2048];
- nLen = sizeof(sMsg);
- ret = SGIPRcv(sMsg, &nLen);
- while( ret == SUCCESS)
- {
- tagSgipHead* pHead = (tagSgipHead*)sMsg;
- switch (ntohl(pHead->nCmdID))
- {
- case SGIP_DELIVER:
- getdata_from_sgip_recvsm_frame(sMsg, nLen, psUserNumber, psSPNumber,
- &byTPPID, &byTPUDHI, &byMsgCoding, &nMsgLen,
- psMsgContent, pReserve);
- printf("nnRecv deliver sm Success!");
- printf("nUserNumber:%s", psUserNumber);
- printf("nSpNumber:%s", psSPNumber);
- printf("nTPPID:%d", byTPPID);
- printf("nTPUDHI:%d", byTPUDHI);
- printf("nMsgCoding:%d", byMsgCoding);
- printf("nMsgLen:%d", nMsgLen);
- printf("nReserve:%s", pReserve);
-
- printf("nMsgContent(txt):%s", psMsgContent);
- /*
- ** 短消息内容的16进制显示
- */
- printf("nSM Data Content(hex):");
- tmpPsz = (unsigned char *)psMsgContent;
- while(nMsgLen > 0)
- {
- if(nMsgLen > 16)
- j = 16;
- else
- j = nMsgLen;
-
- for(i = 0; i< j; i++)
- {
- printf("%02x_", *(tmpPsz + i));
- }
- printf("rn");
- nMsgLen -= j;
- tmpPsz += 16;
- }
- break;
- case SGIP_REPORT:
- getdata_from_sgip_rptsm_frame(sMsg, nLen, &ulOrgNodeNum,
- &ulOrgTimeStamp, &ulOrgSequence, &byReportType,
- psUserNumber, &bystate, &byErrCode, pReserve);
- printf("nnRecv report sm Success!");
- printf("nOrgNodeNum:%u", ulOrgNodeNum);
- printf("nOrgTimeStamp:%u", ulOrgTimeStamp);
- printf("nOrgSequence:%u", ulOrgSequence);
- printf("nReportType:%d", byReportType);
- printf("nUserNumber:%s", psUserNumber);
- printf("nState:%d", bystate);
- printf("nErrCode:%d", byErrCode);
- printf("nReserve:%s", pReserve);
- break;
- default:
- printf("nRecv unknown msg, command id:%d", pHead->nCmdID);
- break;
- }
- /*
- ** 看是否还有其它的消息
- */
- memset(psUserNumber, 0, sizeof(psUserNumber));
- memset(psSPNumber, 0, sizeof(psSPNumber));
- memset(psMsgContent, 0, sizeof(psMsgContent));
- memset(pReserve, 0, sizeof(pReserve));
-
- ret = SGIPRcv(sMsg, &nLen);
- }
-
-
- /* 等待3秒 */
- sleep(1);
- /*
- i = getchar();
- */
- }
- }