request

package
v0.0.0-...-5652a87 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

被动接收基本的消息(事件).

Index

Constants

View Source
const (
	// 微信服务器推送过来的事件类型
	EventTypeSubscribe   = "subscribe"   // 关注事件, 包括点击关注和扫描二维码(公众号二维码和公众号带参数二维码)关注
	EventTypeUnsubscribe = "unsubscribe" // 取消关注
	EventTypeScan        = "SCAN"        // 已经关注的用户扫描带参数二维码事件
	EventTypeLocation    = "LOCATION"    // 上报地理位置事件
)
View Source
const (
	// 微信服务器推送过来的消息类型
	MsgTypeText       = "text"       // 文本消息
	MsgTypeImage      = "image"      // 图片消息
	MsgTypeVoice      = "voice"      // 语音消息
	MsgTypeVideo      = "video"      // 视频消息
	MsgTypeShortVideo = "shortvideo" // 小视频消息
	MsgTypeLocation   = "location"   // 地理位置消息
	MsgTypeLink       = "link"       // 链接消息
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId   int64  `xml:"MsgId"   json:"MsgId"`   // 消息id, 64位整型
	MediaId string `xml:"MediaId" json:"MediaId"` // 图片消息媒体id, 可以调用多媒体文件下载接口拉取数据.
	PicURL  string `xml:"PicUrl"  json:"PicUrl"`  // 图片链接
}

图片消息

func GetImage

func GetImage(msg *mp.MixedMessage) *Image
type Link struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId       int64  `xml:"MsgId"       json:"MsgId"`       // 消息id, 64位整型
	Title       string `xml:"Title"       json:"Title"`       // 消息标题
	Description string `xml:"Description" json:"Description"` // 消息描述
	URL         string `xml:"Url"         json:"Url"`         // 消息链接
}

链接消息

func GetLink(msg *mp.MixedMessage) *Link

type Location

type Location struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId     int64   `xml:"MsgId"      json:"MsgId"`      // 消息id, 64位整型
	LocationX float64 `xml:"Location_X" json:"Location_X"` // 地理位置纬度
	LocationY float64 `xml:"Location_Y" json:"Location_Y"` // 地理位置经度
	Scale     int     `xml:"Scale"      json:"Scale"`      // 地图缩放大小
	Label     string  `xml:"Label"      json:"Label"`      // 地理位置信息
}

地理位置消息

func GetLocation

func GetLocation(msg *mp.MixedMessage) *Location

type LocationEvent

type LocationEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	Event     string  `xml:"Event"     json:"Event"`     // LOCATION
	Latitude  float64 `xml:"Latitude"  json:"Latitude"`  // 地理位置纬度
	Longitude float64 `xml:"Longitude" json:"Longitude"` // 地理位置经度
	Precision float64 `xml:"Precision" json:"Precision"` // 地理位置精度(实际上应该是整数, 但是微信推送过来是浮点数形式)
}

上报地理位置事件

func GetLocationEvent

func GetLocationEvent(msg *mp.MixedMessage) *LocationEvent

type ScanEvent

type ScanEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	Event    string `xml:"Event"    json:"Event"`    // SCAN
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 二维码的参数值(scene_id, scene_str)
	Ticket   string `xml:"Ticket"   json:"Ticket"`   // 二维码的ticket, 可用来换取二维码图片
}

用户已关注时, 扫描带参数二维码的事件

func GetScanEvent

func GetScanEvent(msg *mp.MixedMessage) *ScanEvent

type ShortVideo

type ShortVideo struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId        int64  `xml:"MsgId"        json:"MsgId"`        // 消息id, 64位整型
	MediaId      string `xml:"MediaId"      json:"MediaId"`      // 视频消息媒体id, 可以调用多媒体文件下载接口拉取数据.
	ThumbMediaId string `xml:"ThumbMediaId" json:"ThumbMediaId"` // 视频消息缩略图的媒体id, 可以调用多媒体文件下载接口拉取数据.
}

小视频消息

func GetShortVideo

func GetShortVideo(msg *mp.MixedMessage) *ShortVideo

type SubscribeEvent

type SubscribeEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	Event string `xml:"Event" json:"Event"` // subscribe

	// 下面两个字段只有在扫描带参数二维码进行关注时才有值, 否则为空值!
	EventKey string `xml:"EventKey,omitempty" json:"EventKey,omitempty"` // 事件KEY值, 格式为: qrscene_二维码的参数值
	Ticket   string `xml:"Ticket,omitempty"   json:"Ticket,omitempty"`   // 二维码的ticket, 可用来换取二维码图片
}

关注

func GetSubscribeEvent

func GetSubscribeEvent(msg *mp.MixedMessage) *SubscribeEvent

func (*SubscribeEvent) Scene

func (event *SubscribeEvent) Scene() (scene string, err error)

获取二维码参数

type Text

type Text struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId   int64  `xml:"MsgId"   json:"MsgId"`   // 消息id, 64位整型
	Content string `xml:"Content" json:"Content"` // 文本消息内容
}

文本消息

func GetText

func GetText(msg *mp.MixedMessage) *Text

type UnsubscribeEvent

type UnsubscribeEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	Event    string `xml:"Event"              json:"Event"`              // unsubscribe(取消关注)
	EventKey string `xml:"EventKey,omitempty" json:"EventKey,omitempty"` // 事件KEY值, 为空值
}

取消关注

func GetUnsubscribeEvent

func GetUnsubscribeEvent(msg *mp.MixedMessage) *UnsubscribeEvent

type Video

type Video struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId        int64  `xml:"MsgId"        json:"MsgId"`        // 消息id, 64位整型
	MediaId      string `xml:"MediaId"      json:"MediaId"`      // 视频消息媒体id, 可以调用多媒体文件下载接口拉取数据.
	ThumbMediaId string `xml:"ThumbMediaId" json:"ThumbMediaId"` // 视频消息缩略图的媒体id, 可以调用多媒体文件下载接口拉取数据.
}

视频消息

func GetVideo

func GetVideo(msg *mp.MixedMessage) *Video

type Voice

type Voice struct {
	XMLName struct{} `xml:"xml" json:"-"`
	mp.MessageHeader

	MsgId   int64  `xml:"MsgId"   json:"MsgId"`   // 消息id, 64位整型
	MediaId string `xml:"MediaId" json:"MediaId"` // 语音消息媒体id, 可以调用多媒体文件下载接口拉取该媒体
	Format  string `xml:"Format"  json:"Format"`  // 语音格式, 如amr, speex等

	// 语音识别结果, UTF8编码,
	// NOTE: 需要开通语音识别功能, 否则该字段为空, 即使开通了语音识别该字段还是有可能为空
	Recognition string `xml:"Recognition,omitempty" json:"Recognition,omitempty"`
}

语音消息

func GetVoice

func GetVoice(msg *mp.MixedMessage) *Voice

Jump to

Keyboard shortcuts

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