Documentation
¶
Index ¶
- Constants
- Variables
- func ParseMsgContent(msgFmt uint8, data []byte) (string, error)
- type ActiveTest
- type ActiveTestResp
- type Cancel
- type CancelResp
- type Connect
- type ConnectResp
- type Deliver
- type DeliverResp
- type Header
- type LongTextMessage
- type MsgContentSegment
- type OctetString
- type Operation
- type Pdu
- type Query
- type QueryResp
- type Report
- type Submit
- type SubmitResp
- type Terminate
- type TerminateResp
Constants ¶
const ( CMPP_CONNECT = 0x00000001 CMPP_TERMINATE = 0x00000002 )
Command_Id定义
const ( CMPP_SUBMIT = 0x00000004 + iota CMPP_DELIVER CMPP_QUERY CMPP_CANCEL CMPP_ACTIVE_TEST )
const ( CMPP_CONNECT_RESP = 0x80000001 CMPP_TERMINATE_RESP = 0x80000002 )
const ( CMPP_SUBMIT_RESP = 0x80000004 + iota CMPP_DELIVER_RESP CMPP_QUERY_RESP CMPP_CANCEL_RESP CMPP_ACTIVE_TEST_RESP )
const ( ASCII = 0 // ASCII编码 BINARY = 4 // 二进制短消息 UCS2 = 8 // UCS2编码 GB18030 = 15 // GB18030编码 )
信息格式
0:ASCII串 3:短信写卡操作 4:二进制信息 8:UCS2编码 15:含GB汉字
const ( NO_NEED_REPORT = 0 NEED_REPORT = 1 )
是否要求返回状态报告
const ( NOT_REPORT = 0 IS_REPORT = 1 )
是否为状态报告
const (
OK = 0
)
Status/Result OK
const ( // 高位4bit表示主版本号,低位4bit表示次版本号 VERSION uint8 = 20 )
Variables ¶
var (
LongtextPrefixBS = []byte{0x05, 0x00, 0x03}
)
Functions ¶
Types ¶
type ActiveTest ¶
type ActiveTest struct {
*Header
}
链路检测(CMPP_ACTIVE_TEST)操作
func NewActiveTest ¶
func NewActiveTest(sequenceID uint32) (*ActiveTest, error)
func ParseActiveTest ¶
func ParseActiveTest(hdr *Header, data []byte) (*ActiveTest, error)
func (*ActiveTest) Ok ¶
func (op *ActiveTest) Ok() error
func (*ActiveTest) Serialize ¶
func (op *ActiveTest) Serialize() []byte
func (*ActiveTest) String ¶
func (op *ActiveTest) String() string
type ActiveTestResp ¶
func NewActiveTestResp ¶
func NewActiveTestResp(sequenceID uint32) (*ActiveTestResp, error)
func ParseActiveTestResp ¶
func ParseActiveTestResp(hdr *Header, data []byte) (*ActiveTestResp, error)
func (*ActiveTestResp) Ok ¶
func (op *ActiveTestResp) Ok() error
func (*ActiveTestResp) Serialize ¶
func (op *ActiveTestResp) Serialize() []byte
func (*ActiveTestResp) String ¶
func (op *ActiveTestResp) String() string
type Cancel ¶
SP向ISMG发起删除短信(CMPP_CANCEL)操作
CMPP_CANCEL操作的目的是SP通过此操作可以将 已经提交给ISMG的短信删除,ISMG将以CMPP_CANCEL_RESP 回应删除操作的结果。
type CancelResp ¶
func NewCancelResp ¶
func NewCancelResp(sequenceID uint32, successId uint8) (*CancelResp, error)
func ParseCancelResp ¶
func ParseCancelResp(hdr *Header, data []byte) (*CancelResp, error)
func (*CancelResp) Ok ¶
func (op *CancelResp) Ok() (err error)
func (*CancelResp) Serialize ¶
func (op *CancelResp) Serialize() []byte
func (*CancelResp) String ¶
func (op *CancelResp) String() string
type Connect ¶
type Connect struct {
*Header
// 源地址,此处为SP_Id,即SP的企业代码
SourceAddr *OctetString
// 用于鉴别源地址
AuthenticatorSource *OctetString
// 双方协商的版本号(高位4bit表示主版本号,
// 低位4bit表示次版本号)
Version uint8
// 时间戳的明文,由客户端产生,格式为MMDDHHMMSS,
// 即月日时分秒,10位数字的整型,右对齐 。
Timestamp uint32
}
SP请求连接到ISMG(CMPP_CONNECT)操作
CMPP_CONNECT操作的目的是SP向ISMG注册作为一个合法SP身份, 若注册成功后即建立了应用层的连接,此后SP可以通过此ISMG 接收和发送短信。 ISMG以CMPP_CONNECT_RESP消息响应SP的请求。
func NewConnect ¶
type ConnectResp ¶
type ConnectResp struct {
*Header
// 状态
Status uint8
// ISMG认证码,用于鉴别ISMG
AuthenticatorISMG *OctetString
// 服务器支持的最高版本号
Version uint8
}
func NewConnectResp ¶
func NewConnectResp( sequenceID uint32, status uint8, authISMG string, ) (*ConnectResp, error)
func ParseConnectResp ¶
func ParseConnectResp(hdr *Header, data []byte) (*ConnectResp, error)
func (*ConnectResp) Ok ¶
func (op *ConnectResp) Ok() (err error)
func (*ConnectResp) Serialize ¶
func (op *ConnectResp) Serialize() []byte
func (*ConnectResp) String ¶
func (op *ConnectResp) String() string
type Deliver ¶
type Deliver struct {
*Header
// Body
MsgId uint64 // 信息标识
DestId *OctetString // 目的号码
ServiceId *OctetString // 业务类型,是数字、字母和符号的组合
TP_pid uint8
TP_udhi uint8
MsgFmt uint8
SrcTerminalId *OctetString
// 是否为状态报告
// 0:非状态报告
// 1:状态报告
RegisteredDelivery uint8
MsgLength uint8
MsgContent []byte
Reserved *OctetString
}
ISMG向SP送交短信(CMPP_DELIVER)操作
CMPP_DELIVER操作的目的是ISMG把从短信中心 或其它ISMG转发来的短信送交SP,SP以CMPP_DELIVER_RESP消息回应
func NewDeliver ¶
func (*Deliver) GetStatReport ¶
type DeliverResp ¶
func NewDeliverResp ¶
func NewDeliverResp( sequenceID uint32, msgId uint64, result uint8) (*DeliverResp, error)
func ParseDeliverResp ¶
func ParseDeliverResp(hdr *Header, data []byte) (*DeliverResp, error)
func (*DeliverResp) Ok ¶
func (op *DeliverResp) Ok() (err error)
func (*DeliverResp) Serialize ¶
func (op *DeliverResp) Serialize() []byte
func (*DeliverResp) String ¶
func (op *DeliverResp) String() string
type Header ¶
type Header struct {
// 消息总长度(含消息头及消息体)
Total_Length uint32
// 命令或响应类型
Command_Id uint32
// 消息流水号,顺序累加,步长为1,循环使用(一对请求和应答消息的流水号必须相同)
Sequence_Id uint32
}
Message Header
func ParseHeader ¶
type LongTextMessage ¶
func SplitLongText ¶
func SplitLongText(content string) *LongTextMessage
type MsgContentSegment ¶
func ParseMsgContentSegment ¶
func ParseMsgContentSegment(msgFmt uint8, data []byte) (*MsgContentSegment, error)
type OctetString ¶
不强制以0x00结尾的定长字符串。 当位数不足时,在不明确注明的 情况下, 应左对齐,右补0x00
type Operation ¶
type Operation interface {
//Header returns the Operation header, decoded. Header fields
// can be updated before reserialzing .
GetHeader() *Header
// SerializeTo encodes Operation to it's binary form,
// include the header and body
Serialize() []byte
// String
String() string
// if status/result not ok, return error
Ok() error
}
func ParseOperation ¶
type Query ¶
type Query struct {
*Header
// Body
// 时间YYYYMMDD(精确至日)
Time *OctetString
// 查询类别
// 0:总数查询
// 1:按业务类型查询
Query_Type uint8
// 查询码
// 当Query_Type为0时,此项无效;
// 当Query_Type为1时,此项填写业务类型Service_Id.
Query_Code *OctetString
Reserve *OctetString
}
SP向ISMG查询发送短信状态(CMPP_QUERY)操作
CMPP_QUERY操作的目的是SP向ISMG查询某时间的 业务统计情况,可以按总数或按业务代码查询。 ISMG以CMPP_QUERY_RESP应答。
type QueryResp ¶
type QueryResp struct {
*Header
// Body
// 时间YYYYMMDD(精确至日)
Time *OctetString
// 查询类别
// 0:总数查询
// 1:按业务类型查询
Query_Type uint8
// 查询码
// 当Query_Type为0时,此项无效;
// 当Query_Type为1时,此项填写业务类型Service_Id.
Query_Code *OctetString
MT_TLMsg uint32 // 从SP接收信息总数
MT_Tlusr uint32 // 从SP接收用户总数
MT_Scs uint32 // 成功转发数量
MT_WT uint32 // 待转发数量
MT_FL uint32 // 转发失败数量
MO_Scs uint32 // 向SP成功送达数量
MO_WT uint32 // 向SP待送达数量
MO_FL uint32 // 向SP送达失败数量
}
func NewQueryResp ¶
type Report ¶
type Report struct {
// SP提交短信(CMPP_SUBMIT)操作时,
// 与SP相连的ISMG产生的Msg_Id
MsgId uint64
Stat *OctetString // 发送短信的应答结果
SubmitTime *OctetString
DoneTime *OctetString
DestTerminalId *OctetString
SMSCSequence uint32
}
状态报告
func ParseReport ¶
type Submit ¶
type Submit struct {
*Header
// Body
// 信息标识,由SP侧短信网关本身产生,本处填空。
MsgId uint64
// 相同Msg_Id的信息总条数,从1开始
PkTotal uint8
// 相同Msg_Id的信息序号,从1开始
PkNumber uint8
// 是否要求返回状态确认报告. 0:不需要 1:需要
RegisteredDelivery uint8
// 信息级别
MsgLevel uint8
// 业务类型,是数字、字母和符号的组合
ServiceId *OctetString
// 计费用户类型字段
// 0:对目的终端MSISDN计费;
// 1:对源终端MSISDN计费;
// 2:对SP计费;
// 3:表示本字段无效,对谁计费参见Fee_terminal_Id字段
FeeUserType uint8
// 被计费用户的号码(如本字节填空,则表示本字段无效,
// 对谁计费参见Fee_UserType字段,本字段与Fee_UserType字段互斥)
FeeTerminalId *OctetString
TP_pid uint8
TP_udhi uint8
MsgFmt uint8
// 信息内容来源(SP_Id)
MsgSrc *OctetString
// 资费类别
// 01:对“计费用户号码”免费
// 02:对“计费用户号码”按条计信息费
// 03:对“计费用户号码”按包月收取信息费
// 04:对“计费用户号码”的信息费封顶
// 05:对“计费用户号码”的收费是由SP实现
FeeType *OctetString
// 资费代码(以分为单位)
FeeCode *OctetString
// 存活有效期,格式遵循SMPP3.3协议
ValidTime *OctetString
// 定时发送时间,格式遵循SMPP3.3协议
AtTime *OctetString
// 源号码
SrcId *OctetString
// 接收信息的用户数量(小于100个用户)
DestUsrTl uint8
// 接收短信的MSISDN号码
DestTerminalId []*OctetString
MsgLength uint8
// 信息长度(Msg_Fmt值为0时:<160个字节;其它<=140个字节)
MsgContent []byte
Reserve *OctetString
}
SP向ISMG提交短信(CMPP_SUBMIT)操作
CMPP_SUBMIT操作的目的是SP在与ISMG建立 应用层连接后向ISMG提交短信。 ISMG以CMPP_SUBMIT_RESP消息响应
type SubmitResp ¶
func NewSubmitResp ¶
func NewSubmitResp( sequenceID uint32, msgId uint64, result uint8) (*SubmitResp, error)
func ParseSubmitResp ¶
func ParseSubmitResp(hdr *Header, data []byte) (*SubmitResp, error)
func (*SubmitResp) Ok ¶
func (op *SubmitResp) Ok() (err error)
func (*SubmitResp) Serialize ¶
func (op *SubmitResp) Serialize() []byte
func (*SubmitResp) String ¶
func (op *SubmitResp) String() string
type Terminate ¶
type Terminate struct {
*Header
}
SP或ISMG请求拆除连接(CMPP_TERMINATE)操作
func NewTerminate ¶
type TerminateResp ¶
type TerminateResp struct {
*Header
}
func NewTerminateResp ¶
func NewTerminateResp(sequenceID uint32) (*TerminateResp, error)
func ParseTermaniteResp ¶
func ParseTermaniteResp(hdr *Header, data []byte) (*TerminateResp, error)
func (*TerminateResp) Ok ¶
func (op *TerminateResp) Ok() error
func (*TerminateResp) Serialize ¶
func (op *TerminateResp) Serialize() []byte
func (*TerminateResp) String ¶
func (op *TerminateResp) String() string