menu

package
v0.0.0-...-5175aa2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReqCreate       = "cgi-bin/menu/create"
	ReqGet          = "cgi-bin/get_current_selfmenu_info"
	ReqDelete       = "cgi-bin/menu/delete"
	ReqCustomCreate = "cgi-bin/menu/addconditional"
	ReqCustomDelete = "cgi-bin/menu/delconditional"
	ReqTryMatch     = "cgi-bin/menu/trymatch"
	ReqCustomGet    = "cgi-bin/menu/get"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClickMenu

type ClickMenu struct {
	Typ string `json:"type"`

	Name string `json:"name"`
	Key  string `json:"key"`
}

func (*ClickMenu) Type

func (c *ClickMenu) Type()

type CustomInfo

type CustomInfo struct {
	Menu struct {
		Button []InfoBtn `json:"button"`
		MenuID int64     `json:"menuid"`
	} `json:"menu"`

	CustomMenu struct {
		Button []InfoBtn `json:"button"`
		Match  MatchRule `json:"matchrule"`
		MenuID int64     `json:"menuid"`
	} `json:"conditionalmenu"`
}

type Info

type Info struct {
	IsMenuOpen int `json:"is_menu_open"`
	MenuInfo   struct {
		Button []InfoBtn `json:"button"`
	} `json:"selfmenu_info"`
}

type InfoBtn

type InfoBtn struct {
	Type      string `json:"type"`
	Name      string `json:"name"`
	Key       string `json:"key,omitempty"`
	Value     string `json:"value,omitempty"`
	Url       string `json:"url,omitempty"`
	SubButton struct {
		List []InfoBtn `json:"list"`
	} `json:"sub_button,omitempty"`
	NewsInfo InfoNews `json:"news_info,omitempty"`
}

type InfoNews

type InfoNews struct {
	List []struct {
		Title      string `json:"title"`
		Author     string `json:"author"`
		Digest     string `json:"digest"`
		ShowCover  int    `json:"show_cover"`
		CoverURL   string `json:"cover_url"`
		ContentURL string `json:"content_url"`
		SourceURL  string `json:"source_url"`
	} `json:"list"`
}

type Item

type Item interface {
	Type()
}

每一个实现了Item接口的结构体,如果有Key字段的话,需要设置以便用来区分具体的事件

type LocationMenu

type LocationMenu struct {
	Typ string `json:"type"`

	Name string `json:"name"`
	Key  string `json:"key"`
}

func (*LocationMenu) Type

func (l *LocationMenu) Type()

type MatchInfo

type MatchInfo struct {
	Button []InfoBtn `json:"button"`
}

type MatchRule

type MatchRule struct {
	//there is at least one not null
	TagID              string `json:"tag_id,omitempty"`
	Sex                string `json:"sex,omitempty"`
	Country            string `json:"country,omitempty"`
	Province           string `json:"province,omitempty"`
	City               string `json:"city,omitempty"`
	ClientPlatformType string `json:"client_platform_type,omitempty"`
	Language           string `json:"language,omitempty"`
}

type MediaMenu

type MediaMenu struct {
	Typ string `json:"type"`

	Name    string `json:"name"`
	MediaID string `json:"media_id"`
}

func (*MediaMenu) Type

func (i *MediaMenu) Type()
type Menu struct {
	// contains filtered or unexported fields
}

func New

func New(r *request.Request) *Menu
func (m *Menu) Create(menu RootMenu) error

自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单。 一级菜单最多4个汉字,二级菜单最多7个汉字,多出来的部分将会以“...”代替。 创建自定义菜单后,菜单的刷新策略是,在用户进入公众号会话页或公众号profile页时,如果发现上一次拉取菜单的请求在5分钟以前,就会拉取一下菜单,如果菜单有更新,就会刷新客户端的菜单。测试时可以尝试取消关注公众账号后再次关注,则可以看到创建后的效果。​

自定义菜单接口可实现多种类型按钮,如下: click:点击推事件用户点击click类型按钮后,微信服务器会通过消息接口推送消息类型为event的结构给开发者(参考消息接口指南),并且带上按钮中开发者填写的key值,开发者可以通过自定义的key值与用户进行交互; view:跳转URL用户点击view类型按钮后,微信客户端将会打开开发者在按钮中填写的网页URL,可与网页授权获取用户基本信息接口结合,获得用户基本信息。 scancode_push:扫码推事件用户点击按钮后,微信客户端将调起扫一扫工具,完成扫码操作后显示扫描结果(如果是URL,将进入URL),且会将扫码的结果传给开发者,开发者可以下发消息。 scancode_waitmsg:扫码推事件且弹出“消息接收中”提示框用户点击按钮后,微信客户端将调起扫一扫工具,完成扫码操作后,将扫码的结果传给开发者,同时收起扫一扫工具,然后弹出“消息接收中”提示框,随后可能会收到开发者下发的消息。 pic_sysphoto:弹出系统拍照发图用户点击按钮后,微信客户端将调起系统相机,完成拍照操作后,会将拍摄的相片发送给开发者,并推送事件给开发者,同时收起系统相机,随后可能会收到开发者下发的消息。 pic_photo_or_album:弹出拍照或者相册发图用户点击按钮后,微信客户端将弹出选择器供用户选择“拍照”或者“从手机相册选择”。用户选择后即走其他两种流程。 pic_weixin:弹出微信相册发图器用户点击按钮后,微信客户端将调起微信相册,完成选择操作后,将选择的相片发送给开发者的服务器,并推送事件给开发者,同时收起相册,随后可能会收到开发者下发的消息。 location_select:弹出地理位置选择器用户点击按钮后,微信客户端将调起地理位置选择工具,完成选择操作后,将选择的地理位置发送给开发者的服务器,同时收起位置选择工具,随后可能会收到开发者下发的消息。 media_id:下发消息(除文本消息)用户点击media_id类型按钮后,微信服务器会将开发者填写的永久素材id对应的素材下发给用户,永久素材类型可以是图片、音频、视频、图文消息。请注意:永久素材id必须是在“素材管理/新增永久素材”接口上传后获得的合法id。 view_limited:跳转图文消息URL用户点击view_limited类型按钮后,微信客户端将打开开发者在按钮中填写的永久素材id对应的图文消息URL,永久素材类型只支持图文消息。请注意:永久素材id必须是在“素材管理/新增永久素材”接口上传后获得的合法id。​

func (m *Menu) CreateCustom(menu RootMenu) (menuId string, err error)

TODO Support custom menu 开发者可以通过以下条件来设置用户看到的菜单: 用户标签(开发者的业务需求可以借助用户标签来完成) 性别 手机操作系统 地区(用户在微信客户端设置的地区) 语言(用户在微信客户端设置的语言)

个性化菜单接口说明: 个性化菜单要求用户的微信客户端版本在iPhone6.2.2,Android 6.2.4以上,暂时不支持其他版本微信 菜单的刷新策略是,在用户进入公众号会话页或公众号profile页时,如果发现上一次拉取菜单的请求在5分钟以前,就会拉取一下菜单,如果菜单有更新,就会刷新客户端的菜单。测试时可以尝试取消关注公众账号后再次关注,则可以看到创建后的效果 普通公众号的个性化菜单的新增接口每日限制次数为2000次,删除接口也是2000次,测试个性化菜单匹配结果接口为20000次 出于安全考虑,一个公众号的所有个性化菜单,最多只能设置为跳转到3个域名下的链接 创建个性化菜单之前必须先创建默认菜单(默认菜单是指使用普通自定义菜单创建接口创建的菜单)。如果删除默认菜单,个性化菜单也会全部删除 个性化菜单接口支持用户标签,请开发者注意,当用户身上的标签超过1个时,以最后打上的标签为匹配

个性化菜单匹配规则说明: 个性化菜单的更新是会被覆盖的。 例如公众号先后发布了默认菜单,个性化菜单1,个性化菜单2,个性化菜单3。那么当用户进入公众号页面时,将从个性化菜单3开始匹配,如果个性化菜单3匹配成功,则直接返回个性化菜单3,否则继续尝试匹配个性化菜单2,直到成功匹配到一个菜单。 根据上述匹配规则,为了避免菜单生效时间的混淆,决定不予提供个性化菜单编辑API,开发者需要更新菜单时,需将完整配置重新发布一轮。

func (m *Menu) CustomInfo() (*CustomInfo, error)
func (m *Menu) CustomTryMatch(userID string) (*MatchInfo, error)
func (m *Menu) DelCustom(menuId string) error
func (m *Menu) Delete() error
func (m *Menu) Info() (*Info, error)

type PicType

type PicType int
const (
	PicSysPhoto   PicType = 1
	PicPhotoAlbum PicType = 2
	PicWx         PicType = 3
)

type PictureMenu

type PictureMenu struct {
	Typ string `json:"type"`

	Name     string `json:"name"`
	MenuType PicType
	Key      string `json:"key"`
}

func (*PictureMenu) Type

func (p *PictureMenu) Type()

type ProgramMenu

type ProgramMenu struct {
	Typ string `json:"type"`

	Name     string `json:"name"`
	Url      string `json:"url"`
	AppId    string `json:"appid"`
	PagePath string `json:"pagepath"`
}

func (*ProgramMenu) Type

func (p *ProgramMenu) Type()

type RootMenu

type RootMenu struct {
	Menus []Item     `json:"button"`
	Match *MatchRule `json:"matchrule,omitempty"`
}

func (*RootMenu) Type

func (r *RootMenu) Type()

type ScanMenu

type ScanMenu struct {
	Typ string `json:"type"`

	Name    string `json:"name"`
	Key     string `json:"key"`
	WithMsg bool   `json:"-"` //是否具有提示
}

func (*ScanMenu) Type

func (s *ScanMenu) Type()
type SubMenu struct {
	Name  string `json:"name"`
	Menus []Item `json:"sub_button"`
}
func (s *SubMenu) Type()

type ViewMenu

type ViewMenu struct {
	Typ string `json:"type"`

	Name string `json:"name"`
	//url or mediaID
	Url     string `json:"url"`
	MediaID string `json:"medio_id"` //if this field is not empty, then Url will be omitted
}

func (*ViewMenu) Type

func (v *ViewMenu) Type()

Jump to

Keyboard shortcuts

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