📄 cmpp.h
字号:
#ifndef _CMPP_H_
#define _CMPP_H_
#ifdef _WIN32
#ifndef __PROC_C__
#include <winsock2.h>
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#pragma comment(lib, "ws2_32.lib")
#endif
#ifdef __cplusplus
extern "C" {
#endif
#else
#ifndef __PROC_C__
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#include <signal.h>
#include <iconv.h>
#endif
#ifndef SOCKET
#define SOCKET int
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR (-1)
#define closesocket close
#endif
#endif
/* 消息ID值定义, 所有宏定义前均加上CMPP_前缀. */
#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 CMPP_FWD 0x00000009
#define CMPP_FWD_RESP 0x80000009
#define CMPP_MT_ROUTE 0x00000010
#define CMPP_MT_ROUTE_RESP 0x80000010
#define CMPP_MO_ROUTE 0x00000011
#define CMPP_MO_ROUTE_RESP 0x80000011
#define CMPP_GET_ROUTE 0x00000012
#define CMPP_GET_ROUTE_RESP 0x80000012
#define CMPP_MT_ROUTE_UPDATE 0x00000013
#define CMPP_MT_ROUTE_UPDATE_RESP 0x80000013
#define CMPP_MO_ROUTE_UPDATE 0x00000014
#define CMPP_MO_ROUTE_UPDATE_RESP 0x80000014
#define CMPP_PUSH_MT_ROUTE_UPDATE 0x00000015
#define CMPP_PUSH_MT_ROUTE_UPDATE_RESP 0x80000015
#define CMPP_PUSH_MO_ROUTE_UPDATE 0x00000016
#define CMPP_PUSH_MO_ROUTE_UPDATE_RESP 0x80000016
/* CMPP包的最大大小 */
#define CMPP_PDU_SIZE 2408
/* CMPP协议的各种包体定义 */
typedef struct _CMPP_BODY_CONNECT {
char Source_Addr[6 + 1];
char AuthenticatorSource[16 + 1];
unsigned char Version;
unsigned long Timestamp;
} CMPP_BODY_CONNECT, *PCMPP_BODY_CONNECT;
typedef struct _CMPP_BODY_CONNECT_RESP {
unsigned char Status;
char AuthenticatorISMG[16 + 1];
unsigned char Version;
} CMPP_BODY_CONNECT_RESP, *PCMPP_BODY_CONNECT_RESP;
typedef struct _CMPP_BODY_SUBMIT {
unsigned long Msg_Id1;
unsigned long Msg_Id2;
unsigned char Pk_total;
unsigned char Pk_number;
unsigned char Registered_Delivery;
unsigned char Msg_level;
char Service_Id[10 + 1];
unsigned char Fee_UserType;
char Fee_terminal_Id[21 + 1];
unsigned char TP_pid;
unsigned char TP_udhi;
unsigned char Msg_Fmt;
char Msg_src[6 + 1];
char FeeType[2 + 1];
char FeeCode[6 + 1];
char Valid_Time[17 + 1];
char At_Time[17 + 1];
char Src_Id[21 + 1];
unsigned char DestUsr_tl;
char Dest_terminal_Id[100][21 + 1];
unsigned char Msg_Length;
char Msg_Content[160 + 1];
char Reserve[8 + 1];
} CMPP_BODY_SUBMIT, *PCMPP_BODY_SUBMIT;
typedef struct _CMPP_BODY_SUBMIT_RESP {
unsigned long Msg_Id1;
unsigned long Msg_Id2;
unsigned char Result;
} CMPP_BODY_SUBMIT_RESP, *PCMPP_BODY_SUBMIT_RESP;
typedef struct _CMPP_BODY_DELIVER {
unsigned long Msg_Id1;
unsigned long Msg_Id2;
char Dest_Id[21 + 1];
char Service_Id[10 + 1];
unsigned char TP_pid;
unsigned char TP_udhi;
unsigned char Msg_Fmt;
char Src_terminal_Id[21 + 1];
unsigned char Registered_Delivery;
unsigned char Msg_Length;
char Msg_Content[160 + 1];
char Reserve[8 + 1];
} CMPP_BODY_DELIVER, *PCMPP_BODY_DELIVER;
typedef struct _CMPP_BODY_DELIVER_RESP {
unsigned long Msg_Id1;
unsigned long Msg_Id2;
unsigned char Result;
} CMPP_BODY_DELIVER_RESP, *PCMPP_BODY_DELIVER_RESP;
typedef struct _CMPP_BODY_QUERY {
char Time[8 + 1];
unsigned char Query_Type;
char Query_Code[10 + 1];
char Reserve[8 + 1];
} CMPP_BODY_QUERY, *PCMPP_BODY_QUERY;
typedef struct _CMPP_BODY_QUERY_RESP {
char Time[8 + 1];
unsigned char Query_Type;
char Query_Code[10 + 1];
unsigned long MT_TLMsg;
unsigned long MT_Tlusr;
unsigned long MT_Scs;
unsigned long MT_WT;
unsigned long MT_FL;
unsigned long MO_Scs;
unsigned long MO_WT;
unsigned long MO_FL;
} CMPP_BODY_QUERY_RESP, *PCMPP_BODY_QUERY_RESP;
typedef struct _CMPP_BODY_CANCEL {
unsigned long Msg_Id1;
unsigned long Msg_Id2;
} CMPP_BODY_CANCEL, *PCMPP_BODY_CANCEL;
typedef struct _CMPP_BODY_CANCEL_RESP {
unsigned char Success_Id;
} CMPP_BODY_CANCEL_RESP, *PCMPP_BODY_CANCEL_RESP;
typedef struct _CMPP_BODY_ACTIVE_TEST_RESP {
unsigned char Reserve;
} CMPP_BODY_ACTIVE_TEST_RESP, *PCMPP_BODY_ACTIVE_TEST_RESP;
/* CMPP协议包体联合 */
typedef union _CMPP_BODY {
CMPP_BODY_CONNECT connect;
CMPP_BODY_CONNECT_RESP connect_resp;
CMPP_BODY_SUBMIT submit;
CMPP_BODY_SUBMIT_RESP submit_resp;
CMPP_BODY_DELIVER deliver;
CMPP_BODY_DELIVER_RESP deliver_resp;
CMPP_BODY_QUERY query;
CMPP_BODY_QUERY_RESP query_resp;
CMPP_BODY_CANCEL cancel;
CMPP_BODY_CANCEL_RESP cancel_resp;
CMPP_BODY_ACTIVE_TEST_RESP active_test_resp;
} CMPP_BODY, *PCMPP_BODY;
/* CMPP协议包 */
typedef struct _CMPP_MSG {
unsigned long Total_Length;
unsigned long Command_Id;
unsigned long Sequence_Id;
CMPP_BODY body;
} CMPP_MSG, *PCMPP_MSG;
/* 协议公共接口函数 */
/* 打包发送 */
int cmppConnect(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_CONNECT *pBody);
int cmppConnectResp(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_CONNECT_RESP *pBody);
int cmppTerminate(SOCKET sockfd,
const unsigned long Sequence_Id);
int cmppTerminateResp(SOCKET sockfd,
const unsigned long Sequence_Id);
int cmppSubmit(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_SUBMIT *pBody);
int cmppSubmitResp(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_SUBMIT_RESP *pBody);
int cmppDeliver(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_DELIVER *pBody);
int cmppDeliverResp(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_DELIVER_RESP *pBody);
int cmppQuery(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_QUERY *pBody);
int cmppQueryResp(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_QUERY_RESP *pBody);
int cmppCancel(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_CANCEL *pBody);
int cmppCancelResp(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_CANCEL_RESP *pBody);
int cmppActiveTest(SOCKET sockfd,
const unsigned long Sequence_Id);
int cmppActiveTestResp(SOCKET sockfd,
const unsigned long Sequence_Id, const CMPP_BODY_ACTIVE_TEST_RESP *pBody);
/* 解包 */
int cmppDecode(const char *pszPDU, CMPP_MSG *pMsg);
/* 通用SOCKET函数 */
SOCKET sockConnect(const char *host, unsigned short port);
SOCKET sockListen(unsigned short port);
#ifdef _WIN32
#ifdef __cplusplus
}
#endif
#endif
#endif /* _CMPP_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -