menu

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: 2 Imported by: 0

Documentation

Overview

自定义菜单接口.

Index

Constants

View Source
const (
	EventTypeClick = "CLICK" // 点击菜单拉取消息时的事件推送
	EventTypeView  = "VIEW"  // 点击菜单跳转链接时的事件推送

	// 请注意, 下面的事件仅支持微信iPhone5.4.1以上版本, 和Android5.4以上版本的微信用户,
	// 旧版本微信用户点击后将没有回应, 开发者也不能正常接收到事件推送.
	EventTypeScanCodePush    = "scancode_push"      // scancode_push: 扫码推事件的事件推送
	EventTypeScanCodeWaitMsg = "scancode_waitmsg"   // scancode_waitmsg: 扫码推事件且弹出"消息接收中"提示框的事件推送
	EventTypePicSysPhoto     = "pic_sysphoto"       // pic_sysphoto: 弹出系统拍照发图的事件推送
	EventTypePicPhotoOrAlbum = "pic_photo_or_album" // pic_photo_or_album: 弹出拍照或者相册发图的事件推送
	EventTypePicWeixin       = "pic_weixin"         // pic_weixin: 弹出微信相册发图器的事件推送
	EventTypeLocationSelect  = "location_select"    // location_select: 弹出地理位置选择器的事件推送
)
View Source
const (
	MenuButtonCountLimit    = 3 // 一级菜单最多包含 3 个按钮
	SubMenuButtonCountLimit = 5 // 二级菜单最多包含 5 个按钮
)
View Source
const (
	MenuButtonNameLenLimit    = 16 // 菜单标题不超过16个字节
	SubMenuButtonNameLenLimit = 40 // 子菜单标题不超过40个字节
)
View Source
const (
	ButtonKeyLenLimit = 128 // 菜单KEY值不能超过128字节
	ButtonURLLenLimit = 256 // 网页链接不能超过256字节
)
View Source
const (
	// 下面六個類型(包括view)是在公众平台官网通过网站功能发布菜单的按鈕類型
	ButtonTypeText  = "text"
	ButtonTypeImage = "img"
	ButtonTypePhoto = "photo"
	ButtonTypeVideo = "video"
	ButtonTypeVoice = "voice"

	ButtonTypeView  = "view"  // 跳转URL
	ButtonTypeClick = "click" // 点击推事件

	// 仅支持微信iPhone5.4.1以上版本, 和Android5.4以上版本的微信用户,
	// 旧版本微信用户点击后将没有回应, 开发者也不能正常接收到事件推送.
	ButtonTypeScanCodePush    = "scancode_push"      // 扫码推事件
	ButtonTypeScanCodeWaitMsg = "scancode_waitmsg"   // 扫码带提示
	ButtonTypePicSysPhoto     = "pic_sysphoto"       // 系统拍照发图
	ButtonTypePicPhotoOrAlbum = "pic_photo_or_album" // 拍照或者相册发图
	ButtonTypePicWeixin       = "pic_weixin"         // 微信相册发图
	ButtonTypeLocationSelect  = "location_select"    // 发送位置

	// 专门给第三方平台旗下未微信认证(具体而言, 是资质认证未通过)的订阅号准备的事件类型,
	// 它们是没有事件推送的, 能力相对受限, 其他类型的公众号不必使用.
	ButtonTypeMediaId     = "media_id"     // 下发消息
	ButtonTypeViewLimited = "view_limited" // 跳转图文消息URL
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Title      string `json:"title,omitempty"`       // 图文消息的标题
	Author     string `json:"author,omitempty"`      // 作者
	Digest     string `json:"digest,omitempty"`      // 摘要
	ShowCover  int    `json:"show_cover"`            // 是否显示封面, 0为不显示, 1为显示
	CoverURL   string `json:"cover_url,omitempty"`   // 封面图片的URL
	ContentURL string `json:"content_url,omitempty"` // 正文的URL
	SourceURL  string `json:"source_url,omitempty"`  // 原文的URL, 若置空则无查看原文入口
}

type Button

type Button struct {
	Type       string   `json:"type,omitempty"`       // 非必须; 菜单的响应动作类型
	Name       string   `json:"name,omitempty"`       // 必须;  菜单标题, 不超过16个字节, 子菜单不超过40个字节
	Key        string   `json:"key,omitempty"`        // 非必须; 菜单KEY值, 用于消息接口推送, 不超过128字节
	URL        string   `json:"url,omitempty"`        // 非必须; 网页链接, 用户点击菜单可打开链接, 不超过256字节
	MediaId    string   `json:"media_id,omitempty"`   // 非必须; 调用新增永久素材接口返回的合法media_id
	SubButtons []Button `json:"sub_button,omitempty"` // 非必须; 二级菜单数组, 个数应为1~5个
}

菜单的按钮

func (*Button) SetAsClickButton

func (btn *Button) SetAsClickButton(name, key string)

设置 btn 指向的 Button 为 click 类型按钮

func (*Button) SetAsLocationSelectButton

func (btn *Button) SetAsLocationSelectButton(name, key string)

设置 btn 指向的 Button 为 弹出地理位置选择器 类型按钮

func (*Button) SetAsMediaIdButton

func (btn *Button) SetAsMediaIdButton(name, mediaId string)

设置 btn 指向的 Button 为 下发消息(除文本消息) 类型按钮

func (*Button) SetAsPicPhotoOrAlbumButton

func (btn *Button) SetAsPicPhotoOrAlbumButton(name, key string)

设置 btn 指向的 Button 为 弹出拍照或者相册发图 类型按钮

func (*Button) SetAsPicSysPhotoButton

func (btn *Button) SetAsPicSysPhotoButton(name, key string)

设置 btn 指向的 Button 为 弹出系统拍照发图 类型按钮

func (*Button) SetAsPicWeixinButton

func (btn *Button) SetAsPicWeixinButton(name, key string)

设置 btn 指向的 Button 为 弹出微信相册发图器 类型按钮

func (*Button) SetAsScanCodePushButton

func (btn *Button) SetAsScanCodePushButton(name, key string)

设置 btn 指向的 Button 为 扫码推事件 类型按钮

func (*Button) SetAsScanCodeWaitMsgButton

func (btn *Button) SetAsScanCodeWaitMsgButton(name, key string)

设置 btn 指向的 Button 为 扫码推事件且弹出"消息接收中"提示框 类型按钮

func (*Button) SetAsSubMenuButton

func (btn *Button) SetAsSubMenuButton(name string, subButtons []Button)

设置 btn 指向的 Button 为 子菜单 类型按钮

func (*Button) SetAsViewButton

func (btn *Button) SetAsViewButton(name, url string)

设置 btn 指向的 Button 为 view 类型按钮

func (*Button) SetAsViewLimitedButton

func (btn *Button) SetAsViewLimitedButton(name, mediaId string)

设置 btn 指向的 Button 为 跳转图文消息URL 类型按钮

type ButtonEx

type ButtonEx struct {
	Type    string `json:"type,omitempty"`
	Name    string `json:"name,omitempty"`
	Key     string `json:"key,omitempty"`
	URL     string `json:"url,omitempty"`
	MediaId string `json:"media_id,omitempty"`

	Value    string `json:"value,omitempty"`
	NewsInfo struct {
		Articles []Article `json:"list,omitempty"`
	} `json:"news_info"`

	SubButton struct {
		Buttons []ButtonEx `json:"list,omitempty"`
	} `json:"sub_button"`
}

type ClickEvent

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

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

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

func GetClickEvent

func GetClickEvent(msg *mp.MixedMessage) *ClickEvent

type Client

type Client mp.Client

func NewClient

func NewClient(srv mp.AccessTokenServer, clt *http.Client) *Client

func (*Client) CreateConditionalMenu

func (clt *Client) CreateConditionalMenu(menu *Menu) (menuId int64, err error)

创建个性化菜单.

func (*Client) CreateMenu

func (clt *Client) CreateMenu(menu Menu) (err error)

创建自定义菜单.

func (*Client) DeleteConditionalMenu

func (clt *Client) DeleteConditionalMenu(menuId int64) (err error)

删除个性化菜单.

func (*Client) DeleteMenu

func (clt *Client) DeleteMenu() (err error)

删除自定义菜单

func (*Client) GetMenu

func (clt *Client) GetMenu() (menu *Menu, conditionalMenus []Menu, err error)

获取自定义菜单

func (*Client) GetMenuInfo

func (clt *Client) GetMenuInfo() (info MenuInfo, isMenuOpen bool, err error)

获取自定义菜单配置接口

func (*Client) TryMatch

func (clt *Client) TryMatch(userId string) (menu *Menu, err error)

测试个性化菜单匹配结果. userId 可以是粉丝的 OpenID, 也可以是粉丝的微信号

type LocationSelectEvent

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

	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: 弹出地理位置选择器的事件推送

func GetLocationSelectEvent

func GetLocationSelectEvent(msg *mp.MixedMessage) *LocationSelectEvent

type MatchRule

type MatchRule struct {
	GroupId            *int64 `json:"group_id,omitempty"`
	Sex                *int   `json:"sex,omitempty"`
	Country            string `json:"country,omitempty"`
	Province           string `json:"province,omitempty"`
	City               string `json:"city,omitempty"`
	ClientPlatformType *int   `json:"client_platform_type,omitempty"`
	Language           string `json:"language,omitempty"`
}
type Menu struct {
	Buttons   []Button   `json:"button,omitempty"` // 一级菜单数组, 个数应为1~3个
	MatchRule *MatchRule `json:"matchrule,omitempty"`
	MenuId    int64      `json:"menuid,omitempty"` // 有个性化菜单时查询接口返回值包含这个字段
}
type MenuInfo struct {
	Buttons []ButtonEx `json:"button,omitempty"`
}

type PicPhotoOrAlbumEvent

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

	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: 弹出拍照或者相册发图的事件推送

func GetPicPhotoOrAlbumEvent

func GetPicPhotoOrAlbumEvent(msg *mp.MixedMessage) *PicPhotoOrAlbumEvent

type PicSysPhotoEvent

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

	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: 弹出系统拍照发图的事件推送

func GetPicSysPhotoEvent

func GetPicSysPhotoEvent(msg *mp.MixedMessage) *PicSysPhotoEvent

type PicWeixinEvent

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

	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: 弹出微信相册发图器的事件推送

func GetPicWeixinEvent

func GetPicWeixinEvent(msg *mp.MixedMessage) *PicWeixinEvent

type ScanCodePushEvent

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

	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: 扫码推事件的事件推送

func GetScanCodePushEvent

func GetScanCodePushEvent(msg *mp.MixedMessage) *ScanCodePushEvent

type ScanCodeWaitMsgEvent

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

	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: 扫码推事件且弹出"消息接收中"提示框的事件推送

func GetScanCodeWaitMsgEvent

func GetScanCodeWaitMsgEvent(msg *mp.MixedMessage) *ScanCodeWaitMsgEvent

type ViewEvent

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

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

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

func GetViewEvent

func GetViewEvent(msg *mp.MixedMessage) *ViewEvent

Jump to

Keyboard shortcuts

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