Documentation ¶
Index ¶
- Constants
- Variables
- func GB18030ToUtf8(in string) (string, error)
- func GenAuthenticatorClient(clientId, secret string, timestamp uint32) ([]byte, error)
- func GenAuthenticatorServer(status Status, secret, AuthenticatorClient string) ([]byte, error)
- func GenMsgID(spId string, sequenceNum uint32) (string, error)
- func GenNowTimeYYStr() string
- func GenNowTimeYYYYStr() string
- func GenTimestamp() uint32
- func SplitLongSms(content string) [][]byte
- func Ucs2ToUtf8(in string) (string, error)
- func UnpackMsgId(msgId string) string
- func Utf8ToGB18030(in string) (string, error)
- func Utf8ToUcs2(in string) (string, error)
- type Conn
- type Header
- type OctetString
- type OpError
- type Options
- type Packer
- type RequestID
- type SmgpActiveTestReqPkt
- type SmgpActiveTestRespPkt
- type SmgpDeliverMsgContent
- type SmgpDeliverReqPkt
- type SmgpDeliverRespPkt
- type SmgpExitReqPkt
- type SmgpExitRespPkt
- type SmgpLoginReqPkt
- type SmgpLoginRespPkt
- type SmgpQueryReqPkt
- type SmgpQueryRespPkt
- type SmgpSubmitReqPkt
- type SmgpSubmitRespPkt
- type State
- type Status
- type TLV
- type Tag
Constants ¶
const ( SmgpActiveTestReqPktLen uint32 = 12 //12d, 0xc SmgpActiveTestRespPktLen uint32 = 12 //12d, 0xc )
const ( SmgpExitReqPktLen uint32 = 12 //12d, 0xc SmgpExitRespPktLen uint32 = 12 //12d, 0xc )
const ( SmgpLoginReqPktLen = HeaderPktLen + 8 + 16 + 1 + 4 + 1 //42d, 0x2a SmgpLoginRespPktLen = HeaderPktLen + 4 + 16 + 1 //33d, 0x21 )
const ( SMGP_HEADER_LEN uint32 = 12 SMGP_PACKET_MAX uint32 = 2477 SMGP_PACKET_MIN uint32 = 12 )
const ( SmgpQueryReqPktLen = HeaderPktLen + 8 + 1 + 10 //42d, 0x2a SmgpQueryRespPktLen = HeaderPktLen + 8 + 1 + 10 + 4*8 + 8 //33d, 0x21 )
const ( SEND_MODE = iota RECEIVE_MODE TRANSMIT_MODE )
const ( MO = 0 // MO消息(终端发给SP) MT = 6 // MT消息(SP发给终端,包括WEB上发送的点对点短消息) )
MsgType
const ( ASCII = 0 // ASCII编码 BINARY = 4 // 二进制短消息 UCS2 = 8 // UCS2编码 GB18030 = 15 // GB18030编码 )
MsgFormat 短消息内容体的编码格式 对于文字短消息,要求MsgFormat=15, 对于回执消息,要求MsgFormat=0
const ( NOT_REPORT = 0 // 不是状态报告 IS_REPORT = 1 // 是状态报告 )
const ( NO_NEED_REPORT = 0 NEED_REPORT = 1 )
是否要求返回状态报告
const ( LOW_PRIORITY = iota NORMAL_PRIORITY HIGHER_PRIORITY HIGHEST_PRIORITY )
短消息发送优先级
const HeaderPktLen uint32 = 4 + 4 + 4
const (
SmgpDeliverRespPktLen = HeaderPktLen + 10 + 4 //26d, 0x1a
)
const (
SmgpSubmitRespPktLen = HeaderPktLen + 10 + 4 //26d, 0x1a
)
const (
VERSION uint8 = 0x30
)
Variables ¶
var ( // Common errors. ErrMethodParamsInvalid = errors.New("params passed to method is invalid") // Protocol errors. ErrTotalLengthInvalid = errors.New("PacketLength in Packet data is invalid") ErrRequestIDInvalid = errors.New("RequestID in Packet data is invalid") ErrRequestIDNotSupported = errors.New("RequestID in Packet data is not supported") // Connection errors. ErrConnIsClosed = errors.New("connection is closed") ErrReadHeaderTimeout = errors.New("read header timeout") ErrReadPktBodyTimeout = errors.New("read packet body timeout") )
var ErrLength = errors.New("Options: error length")
var TagName = map[Tag]string{ TAG_TP_pid: "TAG_TP_pid", TAG_TP_udhi: "TAG_TP_udhi", TAG_LinkID: "TAG_LinkID", TAG_ChargeUserType: "TAG_ChargeUserType", TAG_ChargeTermType: "TAG_ChargeTermType", TAG_ChargeTermPseudo: "TAG_ChargeTermPseudo", TAG_DestTermType: "TAG_DestTermType", TAG_PkTotal: "TAG_PkTotal", TAG_PkNumber: "TAG_PkNumber", TAG_SubmitMsgType: "TAG_SubmitMsgType", TAG_SPDealResult: "TAG_SPDealResult", TAG_SrcTermType: "TAG_SrcTermType", TAG_SrcTermPseudo: "TAG_SrcTermPseudo", TAG_NodesCount: "TAG_NodesCount", TAG_MsgSrc: "TAG_MsgSrc", TAG_SrcType: "TAG_SrcType", TAG_MServiceID: "TAG_MServiceID", }
var TpUdhiSeq byte = 0x00
Functions ¶
func GB18030ToUtf8 ¶
func GenAuthenticatorClient ¶
生成客户端认证码 其值通过单向MD5 hash计算得出,表示如下: AuthenticatorClient =MD5(ClientID+7 字节的二进制0(0x00) + Shared secret+Timestamp) Shared secret 由服务器端与客户端事先商定,最长15字节。 此处Timestamp格式为:MMDDHHMMSS(月日时分秒),经TimeStamp字段值转换成字符串,转换后右对齐,左补0x30得到。 例如3月1日0时0分0秒,TimeStamp字段值为0x11F0E540,此处为0301000000。
func GenAuthenticatorServer ¶ added in v0.0.1
生成服务端认证码 Login服务器端返回给客户端的认证码,当客户端认证出错时,此项为空。 其值通过单向MD5 hash计算得出,表示如下: AuthenticatorServer =MD5(Status+AuthenticatorClient + Shared secret) Shared secret 由服务器端与客户端事先商定,最长15字节AuthenticatorClient为客户端发送给服务器端的Login中的值。参见6.2.2节。
func GenMsgID ¶
MsgId字段包含以下三部分内容: SMGW代码:3字节(BCD码)
编码规则如下: 3位区号(不足前添0)+2位设备类别+1位序号 区号:所在省长途区号 设备类别:SMGW取06 序号:所在省的设备编码,例如第一个网关编号为1
时间:4字节(BCD码),格式为MMDDHHMM(月日时分) 序列号:3字节(BCD码),取值范围为000000~999999,从0开始,顺序累加,步长为1,循环使用。 例如某SMGW的代码为010061,在2003年1月16日下午5时0分收到一条短消息,这条短消息的MsgID为:0x01006101161700012345,其中010061表示SMGW代码,01161700表示接收时间,012345表示消息序列号。 MsgID 无法用数字的形式存储,16进制字符串,总长度 10*2
func GenNowTimeYYStr ¶
func GenNowTimeYYStr() string
func GenNowTimeYYYYStr ¶
func GenNowTimeYYYYStr() string
func GenTimestamp ¶
func GenTimestamp() uint32
func SplitLongSms ¶
func Ucs2ToUtf8 ¶
func UnpackMsgId ¶
func Utf8ToGB18030 ¶
func Utf8ToUcs2 ¶
Types ¶
type Conn ¶
type Conn struct { net.Conn State State Version uint8 // for SequenceID generator goroutine SequenceID <-chan uint32 // for SequenceNum generator goroutine SequenceNum <-chan uint32 // contains filtered or unexported fields }
func (*Conn) RecvAndUnpackPkt ¶
type Header ¶
type Header struct { PacketLength uint32 // 数据包长度 RequestID uint32 // 请求标识 SequenceID uint32 // 消息流水号 }
消息头(所有消息公共包头)
type OctetString ¶
type OctetString string
不强制以0x00结尾的定长字符串。 当位数不足时,在不明确注明的 情况下, 应左对齐,右补0x00。 在明确注明的情况下,以该字段的明确注明为准。
func NewOctetString ¶
func NewOctetString(o string) OctetString
func (OctetString) FixedString ¶
func (o OctetString) FixedString(fixedLength int) string
type RequestID ¶
type RequestID uint32
const (
SMGP_REQUEST_MIN, SMGP_RESPONSE_MIN RequestID = iota, 0x80000000 + iota
SMGP_LOGIN, SMGP_LOGIN_RESP
SMGP_SUBMIT, SMGP_SUBMIT_RESP
SMGP_DELIVER, SMGP_DELIVER_RESP
SMGP_ACTIVE_TEST, SMGP_ACTIVE_TEST_RESP
SMGP_FORWARD, SMGP_FORWARD_RESP
SMGP_EXIT, SMGP_EXIT_RESP
SMGP_QUERY, SMGP_QUERY_RESP
SMGP_QUERY_TE_ROUTE, SMGP_QUERY_TE_ROUTE_RESP
SMGP_QUERY_SP_ROUTE, SMGP_QUERY_SP_ROUTE_RESP
SMGP_PAYMENT_REQUEST, SMGP_PAYMENT_REQUEST_RESP
SMGP_PAYMENT_AFFIRM, SMGP_PAYMENT_AFFIRM_RESP
SMGP_QUERY_USERSTATE, SMGP_QUERY_USERSTATE_RESP
SMGP_GET_ALL_TE_ROUTE, SMGP_GET_ALL_TE_ROUTE_RESP
SMGP_GET_ALL_SP_ROUTE, SMGP_GET_ALL_SP_ROUTE_RESP
SMGP_UPDATE_TE_ROUTE, SMGP_UPDATE_TE_ROUTE_RESP
SMGP_UPDATE_SP_ROUTE, SMGP_UPDATE_SP_ROUTE_RESP
SMGP_PUSH_UPDATE_TE_ROUTE, SMGP_PUSH_UPDATE_TE_ROUTE_RESP
SMGP_PUSH_UPDATE_SP_ROUTE, SMGP_PUSH_UPDATE_SP_ROUTE_RESP
SMGP_REQUEST_MAX, SMGP_RESPONSE_MAX
)
type SmgpActiveTestReqPkt ¶
type SmgpActiveTestReqPkt struct { // used in session SequenceID uint32 }
func (*SmgpActiveTestReqPkt) Pack ¶
func (p *SmgpActiveTestReqPkt) Pack(seqId uint32) ([]byte, error)
func (*SmgpActiveTestReqPkt) String ¶
func (p *SmgpActiveTestReqPkt) String() string
func (*SmgpActiveTestReqPkt) Unpack ¶
func (p *SmgpActiveTestReqPkt) Unpack(data []byte) error
type SmgpActiveTestRespPkt ¶
type SmgpActiveTestRespPkt struct { // used in session SequenceID uint32 }
func (*SmgpActiveTestRespPkt) Pack ¶
func (p *SmgpActiveTestRespPkt) Pack(seqId uint32) ([]byte, error)
func (*SmgpActiveTestRespPkt) String ¶
func (p *SmgpActiveTestRespPkt) String() string
func (*SmgpActiveTestRespPkt) Unpack ¶
func (p *SmgpActiveTestRespPkt) Unpack(data []byte) error
type SmgpDeliverMsgContent ¶
type SmgpDeliverMsgContent struct { SubmitMsgID string // submit resp 的 MsgID Sub string Dlvrd string SubmitDate string DoneDate string Stat string Err string Txt string }
func DecodeDeliverMsgContent ¶
func DecodeDeliverMsgContent(data []byte) *SmgpDeliverMsgContent
func (*SmgpDeliverMsgContent) Encode ¶
func (p *SmgpDeliverMsgContent) Encode() string
func (*SmgpDeliverMsgContent) String ¶
func (p *SmgpDeliverMsgContent) String() string
type SmgpDeliverReqPkt ¶
type SmgpDeliverReqPkt struct { MsgID string // 短消息流水号 IsReport uint8 // 是否为状态报告 MsgFormat uint8 // 短消息格式 RecvTime string // 短消息接收时间 SrcTermID string // 短消息发送号码 DestTermID string // 短消息接收号码 MsgLength uint8 // 短消息长度 MsgContent []byte // 短消息内容 Reserve string // 保留 // 可选字段 Options Options // used in session SequenceID uint32 MsgStatContent *SmgpDeliverMsgContent }
func (*SmgpDeliverReqPkt) String ¶
func (p *SmgpDeliverReqPkt) String() string
func (*SmgpDeliverReqPkt) Unpack ¶
func (p *SmgpDeliverReqPkt) Unpack(data []byte) error
type SmgpDeliverRespPkt ¶
func (*SmgpDeliverRespPkt) String ¶
func (p *SmgpDeliverRespPkt) String() string
func (*SmgpDeliverRespPkt) Unpack ¶
func (p *SmgpDeliverRespPkt) Unpack(data []byte) error
type SmgpExitReqPkt ¶
type SmgpExitReqPkt struct { // used in session SequenceID uint32 }
func (*SmgpExitReqPkt) String ¶
func (p *SmgpExitReqPkt) String() string
func (*SmgpExitReqPkt) Unpack ¶
func (p *SmgpExitReqPkt) Unpack(data []byte) error
type SmgpExitRespPkt ¶
type SmgpExitRespPkt struct { // used in session SequenceID uint32 }
func (*SmgpExitRespPkt) String ¶
func (p *SmgpExitRespPkt) String() string
func (*SmgpExitRespPkt) Unpack ¶
func (p *SmgpExitRespPkt) Unpack(data []byte) error
type SmgpLoginReqPkt ¶
type SmgpLoginReqPkt struct { ClientID string AuthenticatorClient string LoginMode uint8 TimeStamp uint32 ClientVersion uint8 // used in session SequenceID uint32 Secret string }
func (*SmgpLoginReqPkt) String ¶
func (p *SmgpLoginReqPkt) String() string
func (*SmgpLoginReqPkt) Unpack ¶
func (p *SmgpLoginReqPkt) Unpack(data []byte) error
type SmgpLoginRespPkt ¶
type SmgpLoginRespPkt struct { Status Status // 请求返回结果 AuthenticatorServer string // 服务器端返回给客户端的认证码 ServerVersion uint8 // 服务器端支持的最高版本号 // auth Secret string AuthenticatorClient string // used in session SequenceID uint32 }
func (*SmgpLoginRespPkt) String ¶
func (p *SmgpLoginRespPkt) String() string
func (*SmgpLoginRespPkt) Unpack ¶
func (p *SmgpLoginRespPkt) Unpack(data []byte) error
type SmgpQueryReqPkt ¶ added in v0.0.3
type SmgpQueryReqPkt struct { QueryTime string QueryType uint8 QueryCode string // used in session SequenceID uint32 }
func (*SmgpQueryReqPkt) Pack ¶ added in v0.0.3
func (p *SmgpQueryReqPkt) Pack(seqId uint32) ([]byte, error)
func (*SmgpQueryReqPkt) String ¶ added in v0.0.3
func (p *SmgpQueryReqPkt) String() string
func (*SmgpQueryReqPkt) Unpack ¶ added in v0.0.3
func (p *SmgpQueryReqPkt) Unpack(data []byte) error
type SmgpQueryRespPkt ¶ added in v0.0.3
type SmgpQueryRespPkt struct { QueryTime string QueryType uint8 QueryCode string MT_TLMsg uint32 MT_Tlusr uint32 MT_Scs uint32 MT_WT uint32 MT_FL uint32 MO_Scs uint32 MO_WT uint32 MO_FL uint32 Reserve string // used in session SequenceID uint32 }
func (*SmgpQueryRespPkt) Pack ¶ added in v0.0.3
func (p *SmgpQueryRespPkt) Pack(seqId uint32) ([]byte, error)
func (*SmgpQueryRespPkt) String ¶ added in v0.0.3
func (p *SmgpQueryRespPkt) String() string
func (*SmgpQueryRespPkt) Unpack ¶ added in v0.0.3
func (p *SmgpQueryRespPkt) Unpack(data []byte) error
type SmgpSubmitReqPkt ¶
type SmgpSubmitReqPkt struct { MsgType uint8 // 短消息类型 NeedReport uint8 // SP是否要求返回状态报告 Priority uint8 // 短消息发送优先级 ServiceID string // 业务代码 FeeType string // 收费类型 FeeCode string // 资费代码 FixedFee string // 包月费/封顶费 MsgFormat uint8 // 短消息格式 ValidTime string // 短消息有效时间 AtTime string // 短消息定时发送时间 SrcTermID string // 短信息发送方号码 ChargeTermID string // 计费用户号码 DestTermIDCount uint8 // 短消息接收号码总数,最多 100 DestTermID []string // 短消息接收号码 MsgLength uint8 // 短消息长度 MsgContent string // 短消息内容 Reserve string // 保留 // 可选参数 Options Options // used in session SequenceID uint32 }
func GetLongMsgPkgs ¶
func GetLongMsgPkgs(pkg *SmgpSubmitReqPkt) ([]*SmgpSubmitReqPkt, error)
func (*SmgpSubmitReqPkt) String ¶
func (p *SmgpSubmitReqPkt) String() string
func (*SmgpSubmitReqPkt) Unpack ¶
func (p *SmgpSubmitReqPkt) Unpack(data []byte) error
type SmgpSubmitRespPkt ¶
func (*SmgpSubmitRespPkt) String ¶
func (p *SmgpSubmitRespPkt) String() string
func (*SmgpSubmitRespPkt) Unpack ¶
func (p *SmgpSubmitRespPkt) Unpack(data []byte) error
type Tag ¶
type Tag uint16
const ( TAG_TP_pid Tag = 0x0001 + iota TAG_TP_udhi TAG_LinkID TAG_ChargeUserType TAG_ChargeTermType TAG_ChargeTermPseudo TAG_DestTermType TAG_DestTermPseudo TAG_PkTotal TAG_PkNumber TAG_SubmitMsgType TAG_SPDealResult TAG_SrcTermType TAG_SrcTermPseudo TAG_NodesCount TAG_MsgSrc TAG_SrcType TAG_MServiceID )
可选参数标签定义 Option Tag