pkg

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SgipBindReqPktLen  = HeaderPktLen + 1 + 16 + 16 + 8 //61d, 0x3d
	SgipBindRespPktLen = HeaderPktLen + 1 + 8           //29d, 0x1d
)
View Source
const (
	BIND_CLIENT = 1
	BIND_SERVER = 2
)
View Source
const (
	MO = 0 // MO消息(终端发给SP)
	MT = 6 // MT消息(SP发给终端,包括WEB上发送的点对点短消息)
)

MsgType

View Source
const (
	ASCII   = 0  // ASCII编码
	BINARY  = 4  // 二进制短消息
	UCS2    = 8  // UCS2编码
	GB18030 = 15 // GB18030编码
)

MsgFormat 短消息内容体的编码格式 对于文字短消息,要求MsgFormat=15, 对于回执消息,要求MsgFormat=0

View Source
const (
	NOT_REPORT = 0 // 不是状态报告
	IS_REPORT  = 1 // 是状态报告
)
View Source
const (
	NO_NEED_REPORT = 0
	NEED_REPORT    = 1
)

是否要求返回状态报告

View Source
const (
	LOW_PRIORITY = iota
	NORMAL_PRIORITY
	HIGHER_PRIORITY
	HIGHEST_PRIORITY
)

短消息发送优先级

View Source
const (
	SGIP_HEADER_LEN uint32 = 12
	SGIP_PACKET_MAX uint32 = 2477
	SGIP_PACKET_MIN uint32 = 12
)
View Source
const (
	SgipTraceReqPktLen  = HeaderPktLen + 12 + 21 + 8             //61d, 0x3d
	SgipTraceRespPktLen = HeaderPktLen + 1 + 1 + 6 + 16 + 16 + 8 //68d, 0x44
)
View Source
const (
	SgipUnbindReqPktLen  = HeaderPktLen
	SgipUnbindRespPktLen = HeaderPktLen
)
View Source
const HeaderPktLen uint32 = 4 + 4 + 12
View Source
const (
	SgipDeliverReqPktLen = HeaderPktLen + 21 + 21 + 1 + 1 + 1 + 4 + 8 //77d, 0x4d
)
View Source
const (
	SgipReportReqPktLen = HeaderPktLen + 12 + 1 + 21 + 1 + 1 + 8 //64d, 0x40
)
View Source
const (
	SgipRespPktLen = HeaderPktLen + 1 + 8 //29d, 0x1d
)
View Source
const (
	SgipSubmitRespPktLen = HeaderPktLen + 10 + 4 //26d, 0x1a
)
View Source
const (
	SgipUserRptReqPktLen = HeaderPktLen + 21 + 21 + 1 + 8 //71d, 0x47
)

Variables

View Source
var (
	// Common errors.
	ErrMethodParamsInvalid = errors.New("params passed to method is invalid")

	// Protocol errors.
	ErrTotalLengthInvalid    = errors.New("PacketLength in Packet data is invalid")
	ErrCommandIDInvalid      = errors.New("RequestID in Packet data is invalid")
	ErrCommandIDNotSupported = 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")
)
View Source
var ErrLength = errors.New("Options: error length")
View Source
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",
}

Functions

func GB18030ToUtf8

func GB18030ToUtf8(in string) (string, error)

func GenNodeId

func GenNodeId(areaCode, corpId string) (uint32, error)

节点编号 通信节点编号规则 在整个网关系统中,所有的通信节点(SMG、GNS、SP和SMSC)都有一个唯一的数字编号,不同的SP或SMSC或SMG或GNS编号不能相同,编号由系统管理人员负责分配。编号规则如下: SMG的编号规则:1AAAAX SMSC的编号规则: 2AAAAX SP的编号规则:3AAAAQQQQQ GNS的编号规则:4AAAAX 其中, AAAA表示四位长途区号(不足四位的长途区号,左对齐,右补零),X表示1位序号,QQQQQ表示5位企业代码。

func GenNowTimeNoYearStr

func GenNowTimeNoYearStr() string

func GenNowTimeYYYYStr

func GenNowTimeYYYYStr() string

func GenSequenceNum

func GenSequenceNum(nodeId, sequenceId uint32) [3]uint32

SequenceNum 字段包含以下三部分内容: 命令源节点的编号:4字节 时间:4字节,格式为MMDDHHMMSS(月日时分秒) 序列号:4字节

func GenSequenceNumStr

func GenSequenceNumStr(seqId [3]uint32) string

func GenTimestamp

func GenTimestamp() uint32

func Ucs2ToUtf8

func Ucs2ToUtf8(in string) (string, error)

func UnpackSequenceNum

func UnpackSequenceNum(sequenceNum [12]byte) [3]uint32

func Utf8ToGB18030

func Utf8ToGB18030(in string) (string, error)

func Utf8ToUcs2

func Utf8ToUcs2(in string) (string, error)

Types

type CommandID

type CommandID uint32
const (
	SGIP_REQUEST_MIN, SGIP_RESPONSE_MIN CommandID = iota, 0x80000000 + iota
	SGIP_BIND, SGIP_BIND_RESP
	SGIP_UNBIND, SGIP_UNBIND_RESP
	SGIP_SUBMIT, SGIP_SUBMIT_RESP
	SGIP_DELIVER, SGIP_DELIVER_RESP
	SGIP_REPORT, SGIP_REPORT_RESP

	SGIP_ADDSP, SGIP_ADDSP_RESP
	SGIP_MODIFYSP, SGIP_MODIFYSP_RESP
	SGIP_DELETESP, SGIP_DELETESP_RESP
	SGIP_QUERYROUTE, SGIP_QUERYROUTE_RESP
	SGIP_ADDTELESEG, SGIP_ADDTELESEG_RESP
	SGIP_MODIFYTELESEG, SGIP_MODIFYTELESEG_RESP
	SGIP_DELETETELESEG, SGIP_DELETETELESEG_RESP
	SGIP_ADDSMG, SGIP_ADDSMG_RESP
	SGIP_MODIFYSMG, SGIP_MODIFYSMG_RESP
	SGIP_DELETESMG, SGIP_DELETESMG_RESP
	SGIP_CHECKUSER, SGIP_CHECKUSER_RESP
	SGIP_USERRPT, SGIP_USERRPT_RESP
	SGIP_TRACE, SGIP_TRACE_RESP

	SGIP_REQUEST_MAX, SGIP_RESPONSE_MAX
)

func (CommandID) String

func (id CommandID) String() string

type CommandIDHeader

type CommandIDHeader struct {
	PacketLength uint32   // 数据包长度
	CommandID    uint32   // 请求标识
	SequenceID   [12]byte // 请求标识
}

type Conn

type Conn struct {
	net.Conn
	State State

	// for SequenceNum generator goroutine
	SequenceID <-chan uint32
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(conn net.Conn) *Conn

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) RecvAndUnpackPkt

func (c *Conn) RecvAndUnpackPkt(timeout time.Duration) (Packer, error)

func (*Conn) SendPkt

func (c *Conn) SendPkt(packet Packer, seqNum [3]uint32) error

func (*Conn) SetState

func (c *Conn) SetState(state State)
type Header struct {
	PacketLength uint32    // 数据包长度
	CommandID    uint32    // 请求标识
	SequenceNum  [3]uint32 // 消息流水号
}

消息头(所有消息公共包头)

func (*Header) Pack

func (p *Header) Pack(w *pkgWriter, pktLen, commandId uint32, seqNum [3]uint32) *pkgWriter

func (*Header) String

func (p *Header) String() string

func (*Header) Unpack

func (p *Header) Unpack(r *pkgReader) *Header

type OctetString

type OctetString string

不强制以0x00结尾的定长字符串。 当位数不足时,在不明确注明的 情况下, 应左对齐,右补0x00。 在明确注明的情况下,以该字段的明确注明为准。

func NewOctetString

func NewOctetString(o string) OctetString

func (OctetString) Byte

func (o OctetString) Byte(fixedLength int) []byte

按需补零

func (OctetString) FixedString

func (o OctetString) FixedString(fixedLength int) string

func (OctetString) String

func (o OctetString) String(fixedLength int) string

去除补零,转为字符串

type OpError

type OpError struct {
	// contains filtered or unexported fields
}

func NewOpError

func NewOpError(e error, op string) *OpError

func (*OpError) Cause

func (e *OpError) Cause() error

func (*OpError) Error

func (e *OpError) Error() string

func (*OpError) Op

func (e *OpError) Op() string

type Options

type Options map[Tag]*TLV

可选参数 map

func ParseOptions

func ParseOptions(rawData []byte) (Options, error)

func (Options) Len

func (o Options) Len() int

返回可选字段部分的长度

func (Options) String

func (o Options) String() string

type Packer

type Packer interface {
	Pack(seqNum [3]uint32) ([]byte, error)
	Unpack(data []byte) error
	String() string
}

type SgipBindReqPkt

type SgipBindReqPkt struct {
	LoginType     uint8  // 登录类型 1 sp -> SMG, 2 SMG -> SP
	LoginName     string // 登陆名
	LoginPassword string // 登陆密码
	Reserve       string // 保留

	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipBindReqPkt) Pack

func (p *SgipBindReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipBindReqPkt) String

func (p *SgipBindReqPkt) String() string

func (*SgipBindReqPkt) Unpack

func (p *SgipBindReqPkt) Unpack(data []byte) error

type SgipBindRespPkt

type SgipBindRespPkt struct {
	SgipRespPkt
}

func (*SgipBindRespPkt) Pack

func (p *SgipBindRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipBindRespPkt) String

func (p *SgipBindRespPkt) String() string

func (*SgipBindRespPkt) Unpack

func (p *SgipBindRespPkt) Unpack(data []byte) error

type SgipDeliverReqPkt

type SgipDeliverReqPkt struct {
	UserNumber     string
	SPNumber       string
	TP_pid         uint8
	TP_udhi        uint8
	MessageCoding  uint8
	MessageLength  uint32
	MessageContent string
	Reserve        string

	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipDeliverReqPkt) Pack

func (p *SgipDeliverReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipDeliverReqPkt) String

func (p *SgipDeliverReqPkt) String() string

func (*SgipDeliverReqPkt) Unpack

func (p *SgipDeliverReqPkt) Unpack(data []byte) error

type SgipDeliverRespPkt

type SgipDeliverRespPkt struct {
	SgipRespPkt
}

func (*SgipDeliverRespPkt) Pack

func (p *SgipDeliverRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipDeliverRespPkt) String

func (p *SgipDeliverRespPkt) String() string

func (*SgipDeliverRespPkt) Unpack

func (p *SgipDeliverRespPkt) Unpack(data []byte) error

type SgipReportReqPkt added in v0.0.3

type SgipReportReqPkt struct {
	SubmitSequenceNum [3]uint32
	ReportType        uint8
	UserNumber        string
	State             uint8
	ErrorCode         uint8
	Reserve           string

	// used in session
	SequenceNum          [3]uint32
	SequenceNumStr       string
	SubmitSequenceNumStr string
}

func (*SgipReportReqPkt) Pack added in v0.0.3

func (p *SgipReportReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipReportReqPkt) String added in v0.0.3

func (p *SgipReportReqPkt) String() string

func (*SgipReportReqPkt) Unpack added in v0.0.3

func (p *SgipReportReqPkt) Unpack(data []byte) error

type SgipReportRespPkt added in v0.0.3

type SgipReportRespPkt struct {
	SgipRespPkt
}

func (*SgipReportRespPkt) Pack added in v0.0.3

func (p *SgipReportRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipReportRespPkt) String added in v0.0.3

func (p *SgipReportRespPkt) String() string

func (*SgipReportRespPkt) Unpack added in v0.0.3

func (p *SgipReportRespPkt) Unpack(data []byte) error

type SgipRespPkt

type SgipRespPkt struct {
	Result  Status // 请求返回结果,0:执行成功 其它:错误码
	Reserve string // 保留

	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipRespPkt) Pack

func (p *SgipRespPkt) Pack(seqNum [3]uint32, commandId CommandID) ([]byte, error)

func (*SgipRespPkt) String

func (p *SgipRespPkt) String() string

func (*SgipRespPkt) Unpack

func (p *SgipRespPkt) Unpack(data []byte) error

type SgipSubmitReqPkt

type SgipSubmitReqPkt struct {
	SPNumber         string
	ChargeNumber     string
	UserCount        uint8
	UserNumber       []string // 接收该短消息的手机号,该字段重复UserCount指定的次数,手机号码前加“86”国别标志
	CorpId           string
	ServiceType      string
	FeeType          uint8
	FeeValue         string
	GivenValue       string
	AgentFlag        uint8
	MorelatetoMTFlag uint8
	Priority         uint8
	ExpireTime       string
	ScheduleTime     string
	ReportFlag       uint8
	TP_pid           uint8
	TP_udhi          uint8
	MessageCoding    uint8
	MessageType      uint8
	MessageLength    uint32
	MessageContent   string
	Reserve          string

	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipSubmitReqPkt) Pack

func (p *SgipSubmitReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipSubmitReqPkt) String

func (p *SgipSubmitReqPkt) String() string

func (*SgipSubmitReqPkt) Unpack

func (p *SgipSubmitReqPkt) Unpack(data []byte) error

type SgipSubmitRespPkt

type SgipSubmitRespPkt struct {
	SgipRespPkt
}

func (*SgipSubmitRespPkt) Pack

func (p *SgipSubmitRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipSubmitRespPkt) String

func (p *SgipSubmitRespPkt) String() string

func (*SgipSubmitRespPkt) Unpack

func (p *SgipSubmitRespPkt) Unpack(data []byte) error

type SgipTraceReqPkt added in v0.0.3

type SgipTraceReqPkt struct {
	SubmitSequenceNum [3]uint32
	UserNumber        string
	Reserve           string

	// used in session
	SequenceNum          [3]uint32
	SequenceNumStr       string
	SubmitSequenceNumStr string
}

func (*SgipTraceReqPkt) Pack added in v0.0.3

func (p *SgipTraceReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipTraceReqPkt) String added in v0.0.3

func (p *SgipTraceReqPkt) String() string

func (*SgipTraceReqPkt) Unpack added in v0.0.3

func (p *SgipTraceReqPkt) Unpack(data []byte) error

type SgipTraceRespPkt added in v0.0.3

type SgipTraceRespPkt struct {
	Count       uint8
	Result      uint8
	NodeId      string
	ReceiveTime string
	SendTime    string
	Reserve     string

	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipTraceRespPkt) Pack added in v0.0.3

func (p *SgipTraceRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipTraceRespPkt) String added in v0.0.3

func (p *SgipTraceRespPkt) String() string

func (*SgipTraceRespPkt) Unpack added in v0.0.3

func (p *SgipTraceRespPkt) Unpack(data []byte) error

type SgipUnbindReqPkt

type SgipUnbindReqPkt struct {
	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipUnbindReqPkt) Pack

func (p *SgipUnbindReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipUnbindReqPkt) String

func (p *SgipUnbindReqPkt) String() string

func (*SgipUnbindReqPkt) Unpack

func (p *SgipUnbindReqPkt) Unpack(data []byte) error

type SgipUnbindRespPkt

type SgipUnbindRespPkt struct {
	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipUnbindRespPkt) Pack

func (p *SgipUnbindRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipUnbindRespPkt) String

func (p *SgipUnbindRespPkt) String() string

func (*SgipUnbindRespPkt) Unpack

func (p *SgipUnbindRespPkt) Unpack(data []byte) error

type SgipUserRptReqPkt added in v0.0.3

type SgipUserRptReqPkt struct {
	SPNumber      string
	UserNumber    string
	UserCondition uint8
	Reserve       string

	// used in session
	SequenceNum    [3]uint32
	SequenceNumStr string
}

func (*SgipUserRptReqPkt) Pack added in v0.0.3

func (p *SgipUserRptReqPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipUserRptReqPkt) String added in v0.0.3

func (p *SgipUserRptReqPkt) String() string

func (*SgipUserRptReqPkt) Unpack added in v0.0.3

func (p *SgipUserRptReqPkt) Unpack(data []byte) error

type SgipUserRptRespPkt added in v0.0.3

type SgipUserRptRespPkt struct {
	SgipRespPkt
}

func (*SgipUserRptRespPkt) Pack added in v0.0.3

func (p *SgipUserRptRespPkt) Pack(seqNum [3]uint32) ([]byte, error)

func (*SgipUserRptRespPkt) String added in v0.0.3

func (p *SgipUserRptRespPkt) String() string

func (*SgipUserRptRespPkt) Unpack added in v0.0.3

func (p *SgipUserRptRespPkt) Unpack(data []byte) error

type State

type State uint8
const (
	CONNECTION_CLOSED State = iota
	CONNECTION_CONNECTED
	CONNECTION_AUTHOK
)

type Status

type Status uint8
const (
	STAT_OK Status = iota
)

func (*Status) Data

func (s *Status) Data() uint8

func (*Status) Error

func (s *Status) Error() error

func (Status) String

func (s Status) String() string

type TLV

type TLV struct {
	// 字段的标签,用于唯一标识可选参数
	Tag Tag
	// 字段的长度
	Length uint16
	// 可变类型 字段内容
	Value []byte
}

可选参数采用TLV(Tag、Length、Value)形式定义, 每个可选参数的Tag、Length、Value的定义见6.3节。

func NewTLV

func NewTLV(tag Tag, value []byte) *TLV

func (*TLV) Byte

func (t *TLV) Byte() []byte

序列化为字节流

func (*TLV) String

func (t *TLV) String() string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL