menu

package
v0.0.0-...-683899a Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2016 License: Apache-2.0 Imports: 1 Imported by: 0

README

自定义菜单接口

Documentation

Overview

自定义菜单接口.

Index

Constants

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

	// 请注意, 下面的事件仅支持微信iPhone5.4.1以上版本, 和Android5.4以上版本的微信用户,
	// 旧版本微信用户点击后将没有回应, 开发者也不能正常接收到事件推送.
	EventTypeScanCodePush    core.EventType = "scancode_push"      // 扫码推事件的事件推送
	EventTypeScanCodeWaitMsg core.EventType = "scancode_waitmsg"   // 扫码推事件且弹出"消息接收中"提示框的事件推送
	EventTypePicSysPhoto     core.EventType = "pic_sysphoto"       // 弹出系统拍照发图的事件推送
	EventTypePicPhotoOrAlbum core.EventType = "pic_photo_or_album" // 弹出拍照或者相册发图的事件推送
	EventTypePicWeixin       core.EventType = "pic_weixin"         // 弹出微信相册发图器的事件推送
	EventTypeLocationSelect  core.EventType = "location_select"    // 弹出地理位置选择器的事件推送
)
View Source
const (
	// 下面6个类型(包括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

func AddConditionalMenu

func AddConditionalMenu(clt *core.Client, menu *Menu) (menuId int64, err error)

创建个性化菜单.

func Create

func Create(clt *core.Client, menu *Menu) (err error)

创建自定义菜单.

func Delete

func Delete(clt *core.Client) (err error)

删除自定义菜单.

func DeleteConditionalMenu

func DeleteConditionalMenu(clt *core.Client, menuId int64) (err error)

删除个性化菜单.

func Get

func Get(clt *core.Client) (menu *Menu, conditionalMenus []Menu, err error)

查询自定义菜单.

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"`       // 必须;  菜单标题
	Key        string   `json:"key,omitempty"`        // 非必须; 菜单KEY值, 用于消息接口推送
	URL        string   `json:"url,omitempty"`        // 非必须; 网页链接, 用户点击菜单可打开链接
	MediaId    string   `json:"media_id,omitempty"`   // 非必须; 调用新增永久素材接口返回的合法media_id
	SubButtons []Button `json:"sub_button,omitempty"` // 非必须; 二级菜单数组
}

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:"-"`
	core.MsgHeader
	EventType core.EventType `xml:"Event"    json:"Event"`    // 事件类型, CLICK
	EventKey  string         `xml:"EventKey" json:"EventKey"` // 事件KEY值, 与自定义菜单接口中KEY值对应
}

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

func GetClickEvent

func GetClickEvent(msg *core.MixedMsg) *ClickEvent

type LocationSelectEvent

type LocationSelectEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `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,omitempty" json:"SendLocationInfo,omitempty"`
}

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

func GetLocationSelectEvent

func GetLocationSelectEvent(msg *core.MixedMsg) *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"`
	MatchRule *MatchRule `json:"matchrule,omitempty"`
	MenuId    int64      `json:"menuid,omitempty"` // 有个性化菜单时查询接口返回值包含这个字段
}

func TryMatch

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

测试个性化菜单匹配结果.

userId 可以是粉丝的 OpenID, 也可以是粉丝的微信号
type MenuInfo struct {
	Buttons []ButtonEx `json:"button,omitempty"`
}

func GetMenuInfo

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

获取自定义菜单配置接口.

type PicPhotoOrAlbumEvent

type PicPhotoOrAlbumEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `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"`
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"`
	} `xml:"SendPicsInfo,omitempty" json:"SendPicsInfo,omitempty"`
}

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

func GetPicPhotoOrAlbumEvent

func GetPicPhotoOrAlbumEvent(msg *core.MixedMsg) *PicPhotoOrAlbumEvent

type PicSysPhotoEvent

type PicSysPhotoEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `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"`
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"`
	} `xml:"SendPicsInfo,omitempty" json:"SendPicsInfo,omitempty"`
}

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

func GetPicSysPhotoEvent

func GetPicSysPhotoEvent(msg *core.MixedMsg) *PicSysPhotoEvent

type PicWeixinEvent

type PicWeixinEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `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"`
		} `xml:"PicList>item,omitempty" json:"PicList,omitempty"`
	} `xml:"SendPicsInfo,omitempty" json:"SendPicsInfo,omitempty"`
}

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

func GetPicWeixinEvent

func GetPicWeixinEvent(msg *core.MixedMsg) *PicWeixinEvent

type ScanCodePushEvent

type ScanCodePushEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `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,omitempty" json:"ScanCodeInfo,omitempty"`
}

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

func GetScanCodePushEvent

func GetScanCodePushEvent(msg *core.MixedMsg) *ScanCodePushEvent

type ScanCodeWaitMsgEvent

type ScanCodeWaitMsgEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `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,omitempty" json:"ScanCodeInfo,omitempty"`
}

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

func GetScanCodeWaitMsgEvent

func GetScanCodeWaitMsgEvent(msg *core.MixedMsg) *ScanCodeWaitMsgEvent

type ViewEvent

type ViewEvent struct {
	XMLName struct{} `xml:"xml" json:"-"`
	core.MsgHeader
	EventType core.EventType `xml:"Event"            json:"Event"`            // 事件类型, VIEW
	EventKey  string         `xml:"EventKey"         json:"EventKey"`         // 事件KEY值, 设置的跳转URL
	MenuId    int64          `xml:"MenuId,omitempty" json:"MenuId,omitempty"` // 菜单ID,如果是个性化菜单,则可以通过这个字段,知道是哪个规则的菜单被点击了。
}

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

func GetViewEvent

func GetViewEvent(msg *core.MixedMsg) *ViewEvent

Jump to

Keyboard shortcuts

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