📄 protocol.h
字号:
/***************************************************************************
Copyright : 2003
Program : PROTOCOL.H
Version : 1.1
***************************************************************************/
#include <deque>
#ifndef _PROTOCOL_CMPP_SGIP_H_
#define _PROTOCOL_CMPP_SGIP_H_
using namespace std;
typedef unsigned char u_char;
////////////////////////////////////////////////////////////////////////////////////////////////////////
/************************* CMPP名字空间 *****************************/
////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace CMPP{
//定义消息COMMAND_ID
#define CMPP_CONNECT 0x00000001
#define CMPP_CONNECT_RESP 0x80000001
#define CMPP_TERMINATE 0x00000002
#define CMPP_TERMINATE_RESP 0x80000002
#define CMPP_SUBMIT 0x00000004
#define CMPP_SUBMIT_RESP 0x80000004
#define CMPP_DELIVER 0x00000005
#define CMPP_DELIVER_RESP 0x80000005
#define CMPP_QUERY 0x00000006
#define CMPP_QUERY_RESP 0x80000006
#define CMPP_CANCEL 0x00000007
#define CMPP_CANCEL_RESP 0x80000007
#define CMPP_ACTIVE_TEST 0x00000008
#define CMPP_ACTIVE_TEST_RESP 0x80000008
//定义常量
#define MSG_FORMAT_ASCII 0 // ASCII串
#define MSG_FORMAT_WRITE_CARD 3 // 短信写卡操作
#define MSG_FORMAT_BINARY 4 // 二进制信息
#define MSG_FORMAT_UCS2 8 // UCS2信息
#define MSG_FORMAT_GB 15 // 含GB汉字
#define SUBMIT_FEE_USERTYPE_TRM 0 // 对目标 MSISDN 计费
#define SUBMIT_FEE_USERTYPE_SRC 1 // 对源 MSISDN 计费
#define SUBMIT_FEE_USERTYPE_SP 2 // 对 SP 计费
#define SUBMIT_FEE_USERTYPE_NULL 3 // 本字段无效
#define SUBMIT REG_NOREPORT 0 // 不需要状态确认报告
#define SUBMIT_REG_REPORT 1 // 需要状态确认报告
#define SUBMIT_REG_SMC 2 // 产生SMC话单
#define SUBMIT_REP_OK 0 // 正确
#define SUBMIT_REP_ERR_STRU 1 // 消息结构错
#define SUBMIT_REP_ERR_CMD 2 // 命令字错
#define SUBMIT_REP_ERR_DUPSEQ 3 // 消息序号重复
#define SUBMIT_REP_ERR_MSGLEN 4 // 消息长度错
#define SUBMIT_REP_ERR_FEECODE 5 // 资费代码错
#define SUBMIT_REP_ERR_OVERLEN 6 // 超过最大信息长
#define SUBMIT_REP_ERR_SERVICE 7 // 业务代码错
#define SUBMIT_REP_ERR_FLOWCTL 8 // 流量控制错
#define SUBMIT_REP_ERR_OTHERS 9 // 其他错误
#define QUERY_TOTAL 0 // 总数查询
#define QUERY_BY_CODE 1 // 按业务代码查询
#define DELIVER_REG_NOREPORT 0 // 非应答消息
#define DELIVER_REG_REPORT 1 // 状态报告
#define DELIVER_REP_OK 0 // 正确
#define DELIVER_REP_ERR_STRU 0 // 消息结构错
#define DELIVER_REP_ERR_CMD 2 // 命令字错
#define DELIVER_REP_ERR_DUPSEQ 3 // 消息序号重复
#define DELIVER_REP_ERR_MSGLEN 4 // 消息长度错
#define DELIVER_REP_ERR_FEECODE 5 // 资费代码错
#define DELIVER_REP_ERR_OVERLEN 6 // 超过最大信息长
#define DELIVER_REP_ERR_SERVICE 7 // 业务代码错
#define DELIVER_REP_ERR_FLOWCTL 8 // 流量控制错
#define DELIVER_REP_ERR_OTHERS 9 // 其他错误
#define MacMaxBufferLen 4096 // 最大缓冲长度
#define MacMaxSmContentLen 159 // 最大短信长度
#define MacMaxMsgLenTotal 4096 // 最大信息长度
#define MacMaxMsgLenAscii 159 // 信息格式为ASCII时最大长度
#define MacMaxMsgLenOther 140 // 短信缺省最大长度
//消息头格式
typedef struct
{
UINT nTotalLen;
UINT nCommandID;
UINT nSequenceID;
}MessageHeader;
//连接消息格式
typedef struct
{
char sSrcAddr[ 6 ];
char sAuthSp[ 16 ];
char cVersion;
UINT nTimeStamp;
}SConnect;
//连接返回消息格式
typedef struct
{
u_char ucStatus;
char sAuthIsmg[ 16 ];
char cVersion;
}SConnectResp;
//SUBMIT消息格式
typedef struct
{
char sMsgId[ 8 ];
char cPkTotal;
char cPkNumber;
char cRegister;
char cMsgLevel;
char sServiceId[ 10 ];
char cFeeUserType;
char sFeeTermId[ 21 ];
char cTpPid;
char cTpUdhi;
char cMsgFmt;
char sMsgSrc[ 6 ];
char sFeeType[ 2 ];
char sFeeCode[ 6 ];
char sValidTime[ 17 ];
char sAtTime[ 17 ];
char sSrcTermId[ 21 ];
char cDestUsrTl;
char sDstTermId[ 21 ];
u_char ucMsgLen;
// char sMsgContent[ 160 ];
// char sReserve[ 8 ];
}SSubmit;
//SUBMIT返回消息格式
typedef struct
{
unsigned __int64 sMsgId;
u_char ucResult;
}SSubmitResp;
/*typedef struct
{
char sMsgId[ 8 ];
char sDstAddr[ 21 ];
char sServiceId[ 10 ];
u_char ucTpPid;
u_char ucTpUdhi;
u_char ucMsgFmt;
char sSrcAddr[ 21 ];
u_char ucRegister;
u_char ucMsgLen;
char sMsgContent[ 256 ];
char sReserve[ 8 ];
}SDeliver;
*/
//状态报告消息格式
typedef struct
{
unsigned __int64 sMsgId;
char sStat[ 7 ];
char sSubmitTime[ 10 ];
char sDoneTime[ 10 ];
char sDstAddr[ 21 ];
UINT nSmscSeqId;
}SReport;
//状态报告返回消息格式
typedef struct
{
char sMsgId[ 8 ];
u_char ucResult;
}SDeliverResp;
//查询消息格式
typedef struct
{
char sTime[ 8 ];
u_char ucQueryType;
char sQueryCode[ 10 ];
char sReserve[ 8 ];
}SQuery;
//查询返回消息格式
typedef struct
{
char sTime[ 8 ];
u_char ucQueryType;
char sQueryCode[ 10 ];
UINT nMtTlMsg;
UINT nMtTlUsr;
UINT nMtScs;
UINT nMtWt;
UINT nMtFl;
UINT nMoScs;
UINT nMoWt;
UINT nMoFl;
}SQueryResp;
//取消消息格式
typedef struct
{
char sMsgId[ 8 ];
}SCancel;
//取消返回消息格式
typedef struct
{
u_char cSuccId;
}SCancelResp;
//ACTIVETEST返回消息格式
typedef struct
{
u_char cSuccId;
}SActiveTestResp;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/************************** SGIP名字空间 *********************************/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace SGIP{
//定义消息COMMAND_ID
#define SGIP_BIND 0x00000001
#define SGIP_BIND_RESP 0x80000001
#define SGIP_UNBIND 0x00000002
#define SGIP_UNBIND_RESP 0x80000002
#define SGIP_SUBMIT 0x00000003
#define SGIP_SUBMIT_RESP 0x80000003
#define SGIP_DELIVER 0x00000004
#define SGIP_DELIVER_RESP 0x80000004
#define SGIP_REPORT 0x00000005
#define SGIP_REPORT_RESP 0x80000005
#define SGIP_TRACE 0x00001000
#define SGIP_TRACE_RESP 0x80001000
#define SGIP_ACTIVE_TEST 0x10000001
#define SGIP_ACTIVE_TEST_RESP 0x10000010
//消息头格式
typedef struct
{
UINT nTotalLen;
UINT nCommandID;
UINT nSeqNumber[3];
}MessageHeader;
//连接消息格式
typedef struct
{
u_char nLoginType;
char sLoginName[16];
char sLoginPass[16];
char sReserve[8];
}SBind;
//连接返回消息格式
typedef struct
{
u_char nResult;
char sReserve[8];
}SBindResp;
//SUBMIT消息格式
typedef struct
{
char sSPNumber[21];
char sChargeNumber[21];
u_char nUserCount;
char sUserNumber[21];
char sCorpId[5];
char sServiceType[10];
u_char nFeeType;
char sFeeValue[6];
char sGivenValue[6];
u_char nAgentFlag;
u_char nMorelatetoMTFlag;
u_char nPriority;
char sExpireTime[16];
char sScheduleTime[16];
u_char nReportFlag;
u_char nTP_pid;
u_char nTP_udhi;
u_char nMessageCoding;
u_char nMessageType;
UINT nMessageLen;
// char sMessageContent[7];
// char sReserve[8];
}SSubmit;
//SUBMIT返回消息格式
typedef struct
{
u_char nResult;
char sReserve[8];
}SSubmitResp;
/*typedef struct
{
char sUserNumber[21];
char sSPNumber[21];
u_char nTP_pid;
u_char nTP_udhi;
u_char nMessageCoding;
UINT MessageLen;
char SMessageContent[160];
char sReserve[ 8 ];
}SDeliver;
*/
//DELIVER返回消息格式
typedef struct
{
u_char nResult;
char sReserve[ 8 ];
}SDeliverResp;
//状态报告消息格式
typedef struct
{
UINT sSubmitSeqNumber[3];
u_char nReportType;
char sUserNumber[21];
u_char nState;
u_char nErrorCode;
char sReserve[8];
}SReport;
//状态报告返回消息格式
typedef struct
{
u_char nResult;
char sReserve[ 8 ];
}SReportResp;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/************************************ 消息结构 *******************/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class CMessage
{
public:
//缺省构造函数
CMessage()
{
nRecID = 0;
strcpy(sMobileNum,"");
strcpy(sMsg,"");
strcpy(sChargeNumber, "");
sFeeType = 0;
strcpy(sFeeCode,"");
strcpy(sDatetime,"");
strcpy(sSrcMobile,"");
strcpy(sServiceID,"");
sMsgFmt = -1;
nSendCount = 0;
nMsgID = 0;
memset(sLinkID, 0, 9);
}
//带参数构造函数
CMessage(int RecID, char *pMobileNum ,char *pChargeNumber, char *pMsg, char pFeeType, char *pFeeCode, char*pDateTime, char*pSrcMobile, char*pServiceID, char MsgFmt, char*pLinkID)
{
nRecID = RecID;
strcpy(sMobileNum,pMobileNum);
strcpy(sMsg,pMsg);
strcpy(sChargeNumber, pChargeNumber);
sFeeType = pFeeType;
strcpy(sFeeCode,pFeeCode);
strcpy(sDatetime,pDateTime);
strcpy(sSrcMobile,pSrcMobile);
strcpy(sServiceID,pServiceID);
sMsgFmt = MsgFmt;
nSendCount = 0;
nMsgID = 0;
memset(sLinkID, 0, 9);
memcpy(sLinkID, pLinkID, 8);
}
int nRecID; //消息ID
char sMobileNum[22]; //目标手机号
char sMsg[160]; //信息内容
char sChargeNumber[22]; //付费号码
char sFeeType; //资费类型
char sFeeCode[7]; //资费值
char sDatetime[13]; //日期
char sSrcMobile[22]; //源号码
char sServiceID[11]; //业务代码
char sMsgFmt; //信息编码
short nSendCount; //发送次数
unsigned __int64 nMsgID;//消息的MSGID
char sLinkID[9]; //LinkID
};
typedef deque<CMessage> Queue; //消息队列
typedef deque<CString > MsgQueue; //信息队列
#endif /* end of _PROTOCOL_CMPP_SGIP_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -