request

package
v0.0.0-...-f5adc6c Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2014 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

定义常规情况下微信服务器推送过来的消息数据结构

Index

Constants

View Source
const (
	// 微信服务器推送过来的消息类型
	MSG_TYPE_TEXT     = "text"     // 文本消息
	MSG_TYPE_IMAGE    = "image"    // 图片消息
	MSG_TYPE_VOICE    = "voice"    // 语音消息
	MSG_TYPE_VIDEO    = "video"    // 视频消息
	MSG_TYPE_LOCATION = "location" // 地理位置消息
	MSG_TYPE_LINK     = "link"     // 链接消息
	MSG_TYPE_EVENT    = "event"    // 事件推送
)
View Source
const (
	// 微信服务器推送过来的事件类型
	EVENT_TYPE_SUBSCRIBE             = "subscribe"             // 订阅, 包括点击订阅和扫描二维码
	EVENT_TYPE_UNSUBSCRIBE           = "unsubscribe"           // 取消订阅
	EVENT_TYPE_SCAN                  = "SCAN"                  // 已经订阅用户扫描二维码事件
	EVENT_TYPE_LOCATION              = "LOCATION"              // 上报地理位置事件
	EVENT_TYPE_CLICK                 = "CLICK"                 // 点击菜单拉取消息时的事件推送
	EVENT_TYPE_VIEW                  = "VIEW"                  // 点击菜单跳转链接时的事件推送
	EVENT_TYPE_SCANCODE_PUSH         = "scancode_push"         // scancode_push:扫码推事件的事件推送
	EVENT_TYPE_SCANCODE_WAITMSG      = "scancode_waitmsg"      // scancode_waitmsg:扫码推事件且弹出“消息接收中”提示框的事件推送
	EVENT_TYPE_PIC_SYSPHOTO          = "pic_sysphoto"          // pic_sysphoto:弹出系统拍照发图的事件推送
	EVENT_TYPE_PIC_PHOTO_OR_ALBUM    = "pic_photo_or_album"    // pic_photo_or_album:弹出拍照或者相册发图的事件推送
	EVENT_TYPE_PIC_WEIXIN            = "pic_weixin"            // pic_weixin:弹出微信相册发图器的事件推送
	EVENT_TYPE_LOCATION_SELECT       = "location_select"       // location_select:弹出地理位置选择器的事件推送
	EVENT_TYPE_MASSSENDJOBFINISH     = "MASSSENDJOBFINISH"     // 微信服务器推送群发结果
	EVENT_TYPE_TEMPLATESENDJOBFINISH = "TEMPLATESENDJOBFINISH" // 模板消息发送状态通知
	EVENT_TYPE_MERCHANTORDER         = "merchant_order"        // 订单付款通知
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonHead

type CommonHead struct {
	ToUserName   string `xml:"ToUserName"   json:"ToUserName"`   // 开发者微信号
	FromUserName string `xml:"FromUserName" json:"FromUserName"` // 发送方帐号(一个OpenID)
	CreateTime   int64  `xml:"CreateTime"   json:"CreateTime"`   // 消息创建时间(整型), unixtime
	MsgType      string `xml:"MsgType"      json:"MsgType"`      // 消息类型
}

type Image

type Image struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

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

图片消息

type Link struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	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"`         // 消息链接
}

链接消息

type Location

type Location struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	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"`      // 地理位置信息
}

地理位置消息

type LocationEvent

type LocationEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	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"` // 地理位置精度
}

上报地理位置事件

type MassSendJobFinishEvent

type MassSendJobFinishEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event string `xml:"Event" json:"Event"` // 事件信息,此处为 MASSSENDJOBFINISH

	MsgId int64 `xml:"MsgId" json:"MsgId"` // 群发的消息ID, 64位整型

	// 群发的结构, 为 "send success" 或 "send fail" 或 "err(num)".
	// 但 send success 时, 也有可能因用户拒收公众号的消息, 系统错误等原因造成少量用户接收失败.
	// err(num) 是审核失败的具体原因, 可能的情况如下:
	// err(10001), //涉嫌广告
	// err(20001), //涉嫌政治
	// err(20004), //涉嫌社会
	// err(20002), //涉嫌色情
	// err(20006), //涉嫌违法犯罪
	// err(20008), //涉嫌欺诈
	// err(20013), //涉嫌版权
	// err(22000), //涉嫌互推(互相宣传)
	// err(21000), //涉嫌其他
	Status string `xml:"Status" json:"Status"`

	TotalCount int `xml:"TotalCount" json:"TotalCount"` // group_id 下粉丝数, 或者 openid_list 中的粉丝数

	// 过滤(过滤是指特定地区, 性别的过滤, 用户设置拒收的过滤; 用户接收已超4条的过滤)后,
	// 准备发送的粉丝数, 原则上, FilterCount = SentCount + ErrorCount
	FilterCount int `xml:"FilterCount" json:"FilterCount"`
	SentCount   int `xml:"SentCount"   json:"SentCount"`  // 发送成功的粉丝数
	ErrorCount  int `xml:"ErrorCount"  json:"ErrorCount"` // 发送失败的粉丝数
}

高级群发消息, 事件推送群发结果

type MenuClickEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,CLICK
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,与自定义菜单接口中KEY值对应
}

点击菜单拉取消息时的事件推送

type MenuLocationSelectEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,location_select
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,由开发者在创建菜单时设定

	SendLocationInfo struct {
		LocationX float64 `xml:"Location_X" json:"Location_X"` // 地理位置纬度
		LocationY float64 `xml:"Location_Y" json:"Location_Y"` // 地理位置经度
		Scale     int     `xml:"Scale"      json:"Scale"`      // 精度,可理解为精度或者比例尺、越精细的话 scale越高
		Label     string  `xml:"Label"      json:"Label"`      // 地理位置的字符串信息
		Poiname   string  `xml:"Poiname"    json:"Poiname"`    // 朋友圈POI的名字,可能为空
	} `xml:"SendLocationInfo" json:"SendLocationInfo"` // 发送的位置信息
}

location_select:弹出地理位置选择器的事件推送

type MenuPicPhotoOrAlbumEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,pic_photo_or_album
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,由开发者在创建菜单时设定

	SendPicsInfo struct {
		Count   int `xml:"Count"   json:"Count"` // 发送的图片数量
		PicList []struct {
			PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"` // 图片的MD5值,开发者若需要,可用于验证接收到图片
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"` // 图片列表
	} `xml:"SendPicsInfo" json:"SendPicsInfo"` // 发送的图片信息
}

pic_photo_or_album:弹出拍照或者相册发图的事件推送

type MenuPicSysPhotoEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,pic_sysphoto
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,由开发者在创建菜单时设定

	SendPicsInfo struct {
		Count   int `xml:"Count"   json:"Count"` // 发送的图片数量
		PicList []struct {
			PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"` // 图片的MD5值,开发者若需要,可用于验证接收到图片
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"` // 图片列表
	} `xml:"SendPicsInfo" json:"SendPicsInfo"` // 发送的图片信息
}

pic_sysphoto:弹出系统拍照发图的事件推送

type MenuPicWeixinEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,pic_weixin
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,由开发者在创建菜单时设定

	SendPicsInfo struct {
		Count   int `xml:"Count"   json:"Count"` // 发送的图片数量
		PicList []struct {
			PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"` // 图片的MD5值,开发者若需要,可用于验证接收到图片
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"` // 图片列表
	} `xml:"SendPicsInfo" json:"SendPicsInfo"` // 发送的图片信息
}

pic_weixin:弹出微信相册发图器的事件推送

type MenuScanCodePushEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,scancode_push
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,由开发者在创建菜单时设定

	ScanCodeInfo struct {
		ScanType   string `xml:"ScanType"   json:"ScanType"`   // 扫描类型,一般是qrcode
		ScanResult string `xml:"ScanResult" json:"ScanResult"` // 扫描结果,即二维码对应的字符串信息
	} `xml:"ScanCodeInfo" json:"ScanCodeInfo"` // 扫描信息
}

scancode_push:扫码推事件的事件推送

type MenuScanCodeWaitMsgEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,scancode_waitmsg
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,由开发者在创建菜单时设定

	ScanCodeInfo struct {
		ScanType   string `xml:"ScanType"   json:"ScanType"`   // 扫描类型,一般是qrcode
		ScanResult string `xml:"ScanResult" json:"ScanResult"` // 扫描结果,即二维码对应的字符串信息
	} `xml:"ScanCodeInfo" json:"ScanCodeInfo"` // 扫描信息
}

scancode_waitmsg:扫码推事件且弹出“消息接收中”提示框的事件推送

type MenuViewEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,VIEW
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,设置的跳转URL
}

点击菜单跳转链接时的事件推送

type MerchantOrderEvent

type MerchantOrderEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event       string `xml:"Event"       json:"Event"`       // 事件类型, merchant_order
	OrderId     string `xml:"OrderId"     json:"OrderId"`     // 订单 id
	OrderStatus int    `xml:"OrderStatus" json:"OrderStatus"` // 订单状态(2-待发货, 3-已发货, 5-已完成, 8-维权中)
	ProductId   string `xml:"ProductId"   json:"ProductId"`   // 商品 id
	SkuInfo     string `xml:"SkuInfo"     json:"SkuInfo"`     // sku 信息
}

微信小店, 订单付款通知

type Request

type Request struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	// fuck weixin, MsgId != MsgID
	MsgId int64 `xml:"MsgId,omitempty" json:"MsgId,omitempty"`
	MsgID int64 `xml:"MsgID,omitempty" json:"MsgID,omitempty"`

	Content      string  `xml:"Content,omitempty"      json:"Content,omitempty"`
	MediaId      string  `xml:"MediaId,omitempty"      json:"MediaId,omitempty"`
	PicURL       string  `xml:"PicUrl,omitempty"       json:"PicUrl,omitempty"`
	Format       string  `xml:"Format,omitempty"       json:"Format,omitempty"`
	Recognition  string  `xml:"Recognition,omitempty"  json:"Recognition,omitempty"`
	ThumbMediaId string  `xml:"ThumbMediaId,omitempty" json:"ThumbMediaId,omitempty"`
	LocationX    float64 `xml:"Location_X,omitempty"   json:"Location_X,omitempty"`
	LocationY    float64 `xml:"Location_Y,omitempty"   json:"Location_Y,omitempty"`
	Scale        int     `xml:"Scale,omitempty"        json:"Scale,omitempty"`
	Label        string  `xml:"Label,omitempty"        json:"Label,omitempty"`
	Title        string  `xml:"Title,omitempty"        json:"Title,omitempty"`
	Description  string  `xml:"Description,omitempty"  json:"Description,omitempty"`
	URL          string  `xml:"Url,omitempty"          json:"Url,omitempty"`

	Event        string `xml:"Event,omitempty"       json:"Event,omitempty"`
	EventKey     string `xml:"EventKey,omitempty"    json:"EventKey,omitempty"`
	ScanCodeInfo struct {
		ScanType   string `xml:"ScanType"   json:"ScanType"`
		ScanResult string `xml:"ScanResult" json:"ScanResult"`
	} `xml:"ScanCodeInfo" json:"ScanCodeInfo"`
	SendPicsInfo struct {
		Count   int `xml:"Count"   json:"Count"`
		PicList []struct {
			PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"`
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"`
	} `xml:"SendPicsInfo" json:"SendPicsInfo"`
	SendLocationInfo struct {
		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"`
		Poiname   string  `xml:"Poiname"    json:"Poiname"`
	} `xml:"SendLocationInfo" json:"SendLocationInfo"`
	Ticket      string  `xml:"Ticket,omitempty"      json:"Ticket,omitempty"`
	Latitude    float64 `xml:"Latitude,omitempty"    json:"Latitude,omitempty"`
	Longitude   float64 `xml:"Longitude,omitempty"   json:"Longitude,omitempty"`
	Precision   float64 `xml:"Precision,omitempty"   json:"Precision,omitempty"`
	Status      string  `xml:"Status,omitempty"      json:"Status,omitempty"`
	TotalCount  int     `xml:"TotalCount,omitempty"  json:"TotalCount,omitempty"`
	FilterCount int     `xml:"FilterCount,omitempty" json:"FilterCount,omitempty"`
	SentCount   int     `xml:"SentCount,omitempty"   json:"SentCount,omitempty"`
	ErrorCount  int     `xml:"ErrorCount,omitempty"  json:"ErrorCount,omitempty"`
	OrderId     string  `xml:"OrderId,omitempty"     json:"OrderId,omitempty"`
	OrderStatus int     `xml:"OrderStatus,omitempty" json:"OrderStatus,omitempty"`
	ProductId   string  `xml:"ProductId,omitempty"   json:"ProductId,omitempty"`
	SkuInfo     string  `xml:"SkuInfo,omitempty"     json:"SkuInfo,omitempty"`
}

微信服务器推送到开发者 URL 的所有已知的消息类型的组合体

func (*Request) Image

func (req *Request) Image() (image *Image)
func (req *Request) Link() (link *Link)

func (*Request) Location

func (req *Request) Location() (location *Location)

func (*Request) LocationEvent

func (req *Request) LocationEvent() (event *LocationEvent)

func (*Request) MassSendJobFinishEvent

func (req *Request) MassSendJobFinishEvent() (event *MassSendJobFinishEvent)

func (*Request) MenuClickEvent

func (req *Request) MenuClickEvent() (event *MenuClickEvent)

func (*Request) MenuLocationSelectEvent

func (req *Request) MenuLocationSelectEvent() (event *MenuLocationSelectEvent)

func (*Request) MenuPicPhotoOrAlbumEvent

func (req *Request) MenuPicPhotoOrAlbumEvent() (event *MenuPicPhotoOrAlbumEvent)

func (*Request) MenuPicSysPhotoEvent

func (req *Request) MenuPicSysPhotoEvent() (event *MenuPicSysPhotoEvent)

func (*Request) MenuPicWeixinEvent

func (req *Request) MenuPicWeixinEvent() (event *MenuPicWeixinEvent)

func (*Request) MenuScanCodePushEvent

func (req *Request) MenuScanCodePushEvent() (event *MenuScanCodePushEvent)

func (*Request) MenuScanCodeWaitMsgEvent

func (req *Request) MenuScanCodeWaitMsgEvent() (event *MenuScanCodeWaitMsgEvent)

func (*Request) MenuViewEvent

func (req *Request) MenuViewEvent() (event *MenuViewEvent)

func (*Request) MerchantOrderEvent

func (req *Request) MerchantOrderEvent() (event *MerchantOrderEvent)

func (*Request) ScanEvent

func (req *Request) ScanEvent() (event *ScanEvent)

func (*Request) SubscribeByScanEvent

func (req *Request) SubscribeByScanEvent() (event *SubscribeByScanEvent)

func (*Request) SubscribeEvent

func (req *Request) SubscribeEvent() (event *SubscribeEvent)

func (*Request) TemplateSendJobFinishEvent

func (req *Request) TemplateSendJobFinishEvent() (event *TemplateSendJobFinishEvent)

func (*Request) Text

func (req *Request) Text() (text *Text)

func (*Request) UnsubscribeEvent

func (req *Request) UnsubscribeEvent() (event *UnsubscribeEvent)

func (*Request) Video

func (req *Request) Video() (video *Video)

func (*Request) Voice

func (req *Request) Voice() (voice *Voice)

func (*Request) Zero

func (req *Request) Zero() *Request

type ScanEvent

type ScanEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,SCAN
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id
	Ticket   string `xml:"Ticket"   json:"Ticket"`   // 二维码的ticket,可用来换取二维码图片
}

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

func (*ScanEvent) SceneId

func (event *ScanEvent) SceneId() (id uint32, err error)

获取二维码参数

type SubscribeByScanEvent

type SubscribeByScanEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event    string `xml:"Event"    json:"Event"`    // 事件类型,subscribe
	EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值,qrscene_为前缀,后面为二维码的参数值
	Ticket   string `xml:"Ticket"   json:"Ticket"`   // 二维码的ticket,可用来换取二维码图片
}

用户未关注时,扫描带参数二维码进行关注后的事件推送

func (*SubscribeByScanEvent) SceneId

func (event *SubscribeByScanEvent) SceneId() (id uint32, err error)

获取二维码参数

type SubscribeEvent

type SubscribeEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event string `xml:"Event" json:"Event"` // 事件类型,subscribe(订阅)
}

关注事件(普通关注)

type TemplateSendJobFinishEvent

type TemplateSendJobFinishEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event string `xml:"Event" json:"Event"` // 事件信息,此处为 TEMPLATESENDJOBFINISH

	MsgId int64 `xml:"MsgId" json:"MsgId"` // 模板消息ID

	// 送达成功时:                                     success
	// 送达由于用户拒收(用户设置拒绝接收公众号消息)而失败时:  failed:user block
	// 送达由于其他原因失败时:                            failed: system failed
	Status string `xml:"Status" json:"Status"`
}

在模版消息发送任务完成后,微信服务器会将是否送达成功作为通知,发送到开发者中心中填写的服务器配置地址中。

type Text

type Text struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

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

文本消息

type UnsubscribeEvent

type UnsubscribeEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	Event string `xml:"Event" json:"Event"` // 事件类型,unsubscribe(取消订阅)
}

取消关注

type Video

type Video struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

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

视频消息

type Voice

type Voice struct {
	XMLName struct{} `xml:"xml" json:"-"`
	CommonHead

	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" json:"Recognition"`
}

语音消息

Jump to

Keyboard shortcuts

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