📄 api.h
字号:
#ifndef _API_H #define _API_H
#ifdef _WIN32#include <winsock2.h>#endif#include <assert.h>#include <errno.h>#ifdef __cplusplusextern "C"{#endif/******************************************************************************//* 1: 一些数据类型和返回值及其它一些项的定义 , sp对此不必关心 *//*******************************************************************************/#ifdef _WIN32typedef SOCKET dpl_socket_t;#else#define INVALID_SOCKET -1#define closesocket(sock) close(sock)typedef int dpl_socket_t;#endif#define DPL_USEC_PER_SEC 1000000L#ifdef _WIN32#define DPL_INFINITE INFINITE#define strcasecmp _stricmp#else#define DPL_INFINITE -1#endif#define dpl_assert(exp) assert(exp)long base64_encode (char *to, const char *from, unsigned int len);long base64_decode (char *to, const char *from, unsigned int len);typedef unsigned char dpl_uint8_t;typedef unsigned short dpl_uint16_t;typedef unsigned int dpl_uint32_t;typedef signed char dpl_int8_t;typedef signed short dpl_int16_t;typedef signed int dpl_int32_t;#ifdef _WIN32typedef _int64 dpl_int64_t;typedef unsigned _int64 dpl_uint64_t;#elsetypedef long long dpl_int64_t;#endiftypedef unsigned int dpl_size_t;typedef int dpl_second_t;typedef dpl_uint16_t dpl_port_t;typedef dpl_uint16_t dpl_wchar_t;typedef int dpl_status_t;#define DPL_SUCCESS 0#ifdef _WIN32#define DPL_TIMEUP WAIT_TIMEOUT#define EWOULDBLOCK EAGAIN#else#define DPL_TIMEUP ETIMEDOUT#endif#define DPL_EINVAL EINVAL
#define DPL_ENOMEM ENOMEM#define DPL_ERROR_START 1000#define DPL_NETWORK_ERR_START DPL_ERROR_START#define DPL_OS_ERR_START DPL_ERROR_START+500#define DPL_STATU_START DPL_OS_ERR_START+500#define DPL_CMPP30_ERROR DPL_STATU_START+11#define DPL_EOF DPL_STATU_START+1#define DPL_EINVALSOCK DPL_NETWORK_ERR_START+1#define CMPP_API/**************************************************************//* 1: end */ /**************************************************************//***************************************************************//* 2: cmpp30协议的各种消息结构和sp与网关通讯的结构定义,sp要关注这一部分内容 *//***************************************************************/#define CMPP30_ICP_RPT_LEN 69#define CMPP30_MAX_ISMG_ID_LEN 6#define CMPP30_MAX_ICP_ID_LEN 6#define CMPP30_MAX_LOCALE_LEN 4#define CMPP30_AUTH_LEN 16 #define CMPP30_MAX_SVC_LEN 10#define CMPP30_MAX_SVC_ID_LEN 6#define CMPP30_DATETIME_LEN DPL_UTC_LEN#define CMPP30_MAX_DSTS_NUM 100#define CMPP30_MAX_MSGID_LEN 64#define CMPP30_MAX_LINK_LEN 20#define CMPP30_MAX_OUT_MSGID_LEN 18#define CMPP30_MAX_PSEUDO_LEN 32#define CMPP30_MAX_MSISDN_LEN 21#define CMPP30_MAX_SM_LEN 160#define CMPP30_MBS_MAX_BYTES 140#define CMPP30_DATE_TIME_LEN 10#define CMPP30_LOGIN_BODY_LEN 27#define CMPP30_MAX_PRIORITY 9#define CMPP30_MIN_PRIORITY 0#define CMPP30_MAX_FEE_TYPE 99#define CMPP30_MAX_INFO_FEE 999999#define CMPP30_PK_HEAD_SIZE 12#define CMPP30_PK_LEN_SIZE 4#ifndef CMPP30_MIN_PK_SIZE#define CMPP30_MIN_PK_SIZE CMPP30_PK_HEAD_SIZE #endif #define CMPP30_MAX_PK_SIZE 2477 #define CMPP30_MAX_ICPMO_ID_LEN 20#define CMPP30_MAX_ICPMO_PASSWD_LEN 20#define CMPP30_MAX_SERVICES 10#define CMPP30_V11 0x11#define CMPP30_V12 0x12#define CMPP30_OV 0x00#define CMPP30_MAX_VERSION CMPP30_V12#define CMPP30_MAX_FUTYPE 0x03#define CMPP30_MAX_FEETYPE 0x05#define CMPP30_MSGID_LEN 8#define CMPP30_TIME_LEN 17#define CMPP30_RESERVE_LEN 8enum{ CMPP30_LOGIN = 0x00000001L, CMPP30_LOGIN_RESP = 0x80000001L, CMPP30_LOGOUT = 0x00000002L, CMPP30_LOGOUT_RESP = 0x80000002L, CMPP30_SUBMIT = 0x00000004L, CMPP30_SUBMIT_RESP = 0x80000004L, CMPP30_DELIVER = 0x00000005L, CMPP30_DELIVER_RESP = 0x80000005L, CMPP30_QUERY = 0x00000006L, CMPP30_QUERY_RESP = 0x80000006L, CMPP30_CANCEL = 0x00000007L, CMPP30_CANCEL_RESP = 0x80000007L, CMPP30_ACTIVE = 0x00000008L, CMPP30_ACTIVE_RESP = 0x80000008L,};typedef struct cmpp30icp_head cmpp30icp_head;typedef struct cmpp30icp_packet cmpp30icp_packet;typedef struct cmpp30icp_login_resp cmpp30icp_login_resp;typedef struct cmpp30icp_submit_resp cmpp30icp_submit_resp;typedef struct cmpp30icp_deliver_resp cmpp30icp_deliver_resp;typedef struct cmpp30icp_deliver cmpp30icp_deliver;typedef struct cmpp30icp_status_report cmpp30icp_status_report;struct cmpp30icp_head{ dpl_uint32_t pk_len; dpl_uint32_t pk_cmd; dpl_uint32_t pk_seq;};struct cmpp30icp_packet{ cmpp30icp_head pk_head; char pk_body [CMPP30_MAX_PK_SIZE+1];};struct cmpp30icp_login{ char icp_id[CMPP30_MAX_ICP_ID_LEN+1]; /* ICP ID */ char icp_auth[CMPP30_AUTH_LEN+1]; /* MD5加密授权码 */ dpl_uint8_t if_version; /* 版本号 0x12*/ dpl_uint32_t icp_timestamp; /* 时间戳 */};struct cmpp30icp_login_resp{ dpl_uint32_t status; char ismg_auth[CMPP30_AUTH_LEN+1]; /* ISMG MD5 加密授权 */ dpl_uint8_t if_version; /* 最高版本*/};struct cmpp30icp_submit{ dpl_int64_t msg_id; dpl_uint8_t pk_total; dpl_uint8_t pk_number; dpl_uint8_t registered_delivery; dpl_uint8_t msg_level; char svc_type[CMPP30_MAX_SVC_LEN+1]; dpl_uint8_t fee_utype; /* 计费用户类型 0,1,2,3 */ char fee_user [CMPP30_MAX_PSEUDO_LEN+1]; /* 被计费的用户 */ dpl_uint8_t fee_user_type; /* 计费用户类型 0真实;1伪码 */ dpl_uint8_t tp_pid; dpl_uint8_t tp_udhi; dpl_uint8_t data_coding; /* 数据编码 */ char icp_id[CMPP30_MAX_ICP_ID_LEN+1]; /* SP ID */ char fee_type[2+1]; /* 计费类型 */ char fee_code[6+1]; /* 资费代码 */ char validate[CMPP30_TIME_LEN+1]; /* 过期时间 */ char schedule[CMPP30_TIME_LEN+1]; /* 调度时间 */ char src_term_id[CMPP30_MAX_MSISDN_LEN+1]; /* 源终端ID */ dpl_uint8_t du_count; /* 目的数量 */ char *dst_addr; /* 目的用户 */ dpl_uint8_t dst_user_type; /* 目的用户类型,0真实;1伪码 */ dpl_uint8_t sm_len; /* 消息长度 */ char short_msg[CMPP30_MAX_SM_LEN+1]; /* 短消息内容 */ char link_id[CMPP30_MAX_LINK_LEN+1]; /* LINK ID 定购 */};struct cmpp30icp_submit_resp{ dpl_int64_t msg_id; /* 消息标识 */ dpl_uint32_t result; };struct cmpp30icp_deliver{ dpl_int64_t msg_id; /* 消息标识 */ char dst_addr [CMPP30_MAX_MSISDN_LEN+1]; /* 目的用户 */ char svc_type [CMPP30_MAX_SVC_LEN+1]; /* 服务类型 */ dpl_uint8_t tp_pid; dpl_uint8_t tp_udhi; dpl_uint8_t data_coding; /* 数据编码 */ char src_addr [CMPP30_MAX_PSEUDO_LEN+1]; /* 发起用户 */ dpl_uint8_t src_user_type; /* 发起用户类型,0真实;1伪码 */ dpl_uint8_t registered_delivery; dpl_uint8_t sm_len; /* 消息长度 */ char short_msg[CMPP30_MAX_SM_LEN+1]; /* 消息内容 */ char link_id[CMPP30_MAX_LINK_LEN+1]; /* LINK ID 定购 */};struct cmpp30icp_deliver_resp{ dpl_int64_t msg_id; dpl_uint32_t result;};struct cmpp30icp_status_report{ dpl_int64_t msg_id; /* 消息标识 */ char stat [7+1]; char submit_date [CMPP30_DATE_TIME_LEN+1]; /* 提交时间 */ char final_date [CMPP30_DATE_TIME_LEN+1]; /* 完成时间 */ char dest_id [CMPP30_MAX_PSEUDO_LEN+1]; dpl_uint32_t cdr_msg_id;};enum{ CMPP30_TRANS_CS_CLOSED = 0, CMPP30_TRANS_CS_OPEN = 1, CMPP30_TRANS_CS_BIND = 2};typedef struct cmpp30icp_login cmpp30icp_login;typedef struct cmpp30icp_submit cmpp30icp_submit;typedef struct cmpp30icp_deliver_resp cmpp30icp_deliver_rsp;typedef struct cmpp30icp_submit_m cmpp30icp_submit_m;typedef struct cmpp30_icp_trans cmpp30_icp_trans;typedef struct cmpp30_icp_packet cmpp30_icp_packet;enum{ CMPP30_ICP_WAIT_LOGIN , CMPP30_ICP_WAIT_PK , CMPP30_ICP_WAIT_ACTIVE_RSP , CMPP30_ICP_WAIT_DELIV_RSP };struct cmpp30_icp_trans{ dpl_socket_t socket; dpl_uint32_t sequence; dpl_uint32_t icp_seq; dpl_uint8_t mode; dpl_uint8_t status; dpl_uint8_t stat; dpl_uint8_t version; dpl_uint32_t slot; char icp_id[CMPP30_MAX_ICP_ID_LEN+1];};struct cmpp30_icp_packet{ dpl_uint32_t pk_cmd; dpl_uint32_t pk_seq; union{ cmpp30icp_login_resp login_resp_body; cmpp30icp_submit_resp submit_resp_body; cmpp30icp_deliver deliver_body; }pk_data;};/**********************************************************************//* 2:end *//*********************************************************************//********************************************************************//* 3:sp与网关通讯所需要的API接口 *//*******************************************************************//*** * 功能:与网关建立socket连接 * 参数:char *host 网关ip * dpl_port_t port 网关监听端口 * cmpp30_icp_trans *conn 连接描述符结构 * 返回值:0 成功 * 其它 失败 ***/CMPP_API dpl_status_t WINAPI cmpp30_connect_to_ismg(char *host,dpl_port_t port, cmpp30_icp_trans *conn);/*** * 功能:向网关发送login包 * 参数:cmpp30_icp_trans *trans 连接描述符结构 * cmpp30icp_login *login login消息包结构 * 返回值:0 成功 * 其它 失败 ***/CMPP_API dpl_status_t WINAPI cmpp30icp_login_send(cmpp30_icp_trans *trans, cmpp30icp_login *login);/*** * 功能:向网关发送active包 * 参数:cmpp30_icp_trans *trans 连接描述符结构 * 返回值:0 成功 * 其它 失败 ***/CMPP_API dpl_status_t WINAPI cmpp30icp_active(cmpp30_icp_trans *trans);/*** * 功能:在收到网关active包后,调用此函数给网关回active应答包
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -