Documentation
¶
Overview ¶
message 包提供了基本的消息处理
Index ¶
- Constants
- Variables
- func TransferCustomerService(m Messager) ([]byte, error)
- type EventClickView
- type EventLocation
- type EventScan
- type EventTemplateSendJobFinish
- type Eventer
- type Handler
- type HandlerBus
- type Image
- type Link
- type Location
- type Message
- type Messager
- type ReplyTransferCustomerService
- type Server
- type ShortVideo
- type Text
- type Video
- type Voice
Constants ¶
const ( TemplateSendStatusSuccess int8 = 1 TemplateSendStatusUserBlock TemplateSendStatusSystemFailed )
模板的发送状态值
const ( EventTypeSubscribe = "subscribe" EventTypeUnsubscribe = "unsibuscribe" EventTypeScan = "SCAN" EventTypeLocation = "LOCATION" EventTypeClick = "CLICK" EventTypeView = "VIEW" EventTypeTemplateSendJobFinish = "TEMPLATESENDJOBFINISH" )
模板的事件类型
const ( TypeText = "text" TypeImage = "image" TypeVoice = "voice" TypeVideo = "video" TypeShortVideo = "shortvideo" TypeLocation = "location" TypeLink = "link" TypeEvent = "event" TypeTransferCustomerService = "transfer_customer_service" // 只能用于回复消息中 )
消息类型
Variables ¶
var ReplySuccess = []byte("success")
ReplySuccess 成功返回的内容
Functions ¶
func TransferCustomerService ¶
TransferCustomerService 是 Handler 的一种实现,实现了对消息的转发。
Types ¶
type EventClickView ¶
type EventClickView struct {
EventKey string `xml:"EventKey"`
// contains filtered or unexported fields
}
EventClickView 表示点击事件,可以菜单或是链接。
若是点击菜单,则 EventKey 表示菜单的 key,若 点击的是链接,则 EventKey 表示的是要点击的链接。
type EventLocation ¶
type EventLocation struct {
Latitude float64 `xml:"Latitude"` // 纬度
Longitude float64 `xml:"Longitude"` // 经度
Precision float64 `xml:"Precision"` // 精度
// contains filtered or unexported fields
}
EventLocation 表示通过扫描带参数的二维码事件
type EventScan ¶
type EventScan struct {
EventKey string `xml:"EventKey"`
Ticket string `xml:"Ticket"`
// contains filtered or unexported fields
}
EventScan 表示通过扫描带参数的二维码事件
subscribe 表示已关注下的扫描事件,SCAN 未关注下的扫描事件 若 IsScan() 为 false,则 subscribe 表示关注,unsbuscribe 表示取消关注
type EventTemplateSendJobFinish ¶
type EventTemplateSendJobFinish struct {
MsgID int64 `xml:"MsgID"`
Status string `xml:"Status"`
// contains filtered or unexported fields
}
EventTemplateSendJobFinish 模板消息发送事件
func (*EventTemplateSendJobFinish) EventType ¶
func (e *EventTemplateSendJobFinish) EventType() string
func (*EventTemplateSendJobFinish) StatusType ¶
func (e *EventTemplateSendJobFinish) StatusType() int8
StatusType 当前事例的状态
type Handler ¶
Handler 消息处理函数。 通过向 NewServer 注册 Handler 函数,获取对消息处理的权限。
参数 Messager 为从微信端传递过来的 xml 数据对象实例,都已定义在 messages.go 文件中。
函数的返回值,被当作消息被动回复内容传递给微信调用方。在 reply.go 中 定义了大部分可能用到返回类型,可以拿来直接使用。
NOTE 所有的 Handler 必须在 5 秒内有返回数据,否则微信端会再次发起同样的请求
type HandlerBus ¶
type HandlerBus struct {
// contains filtered or unexported fields
}
HandlerBus 为 Handler 接口的管理器,方便用户按类别来注册消息处理。
h := &HandlerBus{}
h.RegisterMessage(TypeText, h1)
h.RegisterMessage(TypeImage, h2)
srv := NewServer("token", h.Handler, nil)
func (*HandlerBus) Handler ¶
func (b *HandlerBus) Handler(m Messager) ([]byte, error)
Handler 实现的 Hnadler 接口
func (*HandlerBus) RegisterEvent ¶
func (b *HandlerBus) RegisterEvent(event string, h Handler)
RegisterEvent 注册事件处理函数
func (*HandlerBus) RegisterMessage ¶
func (b *HandlerBus) RegisterMessage(typ string, h Handler)
RegisterMessage 注册消息处理函数。 typ 的值若为 event,可以注册,但不会实际有作用。
type Image ¶
type Image struct {
PicURL string `xml:"PicUrl"`
MediaID string `xml:"MediaId"`
// contains filtered or unexported fields
}
Image 图片消息
type Link ¶
type Link struct {
Title string `xml:"Title"`
Description string `xml:"Description"`
URL string `xml:"Url"`
// contains filtered or unexported fields
}
Link 链接消息
type Location ¶
type Location struct {
X float64 `xml:"Location_X"` // 维度
Y float64 `xml:"Location_Y"` // 经度
Scale int `xml:"Scale"`
Label string `xml:"Label"` // 地理位置信息
// contains filtered or unexported fields
}
Location 位置消息
type Messager ¶
type Messager interface {
// 消息类型,对应 MsgType 字段
Type() string
// 开发者微信号,对应 ToUserName 字段
To() string
// 发送方账号,对应 FromUserName 字段
From() string
// 创建时间,对应 CreateTime 字段
Created() int64
}
Messager 表示消息和事件的基本结构。
type ReplyTransferCustomerService ¶
type ReplyTransferCustomerService struct {
XMLName xml.Name `xml:"xml"`
ToUserName xxml.CData `xml:"ToUserName"` // 开发者微信号
FromUserName xxml.CData `xml:"FromUserName"` // 发送方帐号(一个 OpenID)
MsgType xxml.CData `xml:"MsgType"` // 消息类型
CreateTime int64 `xml:"CreateTime"` // 消息创建时间 (整型)
}
ReplyTransferCustomerService 转发消息
func NewReplyTranferCustomerService ¶
func NewReplyTranferCustomerService(m Messager) *ReplyTransferCustomerService
NewReplyTranferCustomerService 将所有的消息进行转发
func (*ReplyTransferCustomerService) Bytes ¶
func (t *ReplyTransferCustomerService) Bytes() ([]byte, error)
Bytes 返回 []byte 内容
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 消息管理服务器。
func NewServer ¶
NewServer 声明一个新的消息管理服务器。
若将 h 参数指定为 nil,则会被自动赋予 TransferCustomerService 函数。 若将 errlog 指定为 nil,则会将错误信息输出到 stderr 中。
type ShortVideo ¶
type ShortVideo struct {
MediaID string `xml:"MediaId"`
ThumbMediaID string `xml:"ThumbMediaId"`
// contains filtered or unexported fields
}
shortVideo 短视频消息
type Text ¶
type Text struct {
Content string `xml:"Content"` // 文本消息内容
// contains filtered or unexported fields
}
Text 文本消息