menu

package
v0.0.0-...-f32fcc8 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MenuCreateUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s"
	MenuQueryUrl  = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s"
	MenuDeleteUrl = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s"
)
View Source
const (
	CreateAditionalMenuUrl = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=%s"
	DeleteAditionalMenuUrl = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=%s"
	MatchAditionalMenuUrl  = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=%s"
)
View Source
const (
	SexMale   MatchSex = 1
	SexFemale          = 2
	SexNone            = 0
)
View Source
const (
	PlfIOS     MatchPlatForm = "IOS"
	PlfAndroid               = "ANDROID"
	PlfOthers                = "OTHERS"
	PlfNone                  = ""
)
View Source
const (
	//最常用的三种类型
	BtnClick       ButtonType = "click"
	BtnView                   = "view"
	BtnMiniProgram            = "miniprogram"
	//支持微信iPhone5.4.1以上版本,和Android5.4以上版本的微信用户,
	//旧版本微信用户点击后将没有回应,开发者也不能正常接收到事件推送
	BtnScanCodePush    = "scancode_push"
	BtnScanCodeWaitMsg = "scancode_waitmsg"
	BtnPicSysPhoto     = "pic_sysphoto"
	BtnPhotoOrAlbum    = "pic_photo_or_album"
	BtnPicWeixin       = "pic_weixin"
	BtnLocationSelect  = "location_select"

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

微信公众号文档中定义的常用的8种按钮类型,最后两种一般不用已注释

Variables

This section is empty.

Functions

func DeleteAditionalMenu

func DeleteAditionalMenu(accessToken string, menuID int) error

func DeleteMenu

func DeleteMenu(accessToken string) error

func GetMenuTypeHint

func GetMenuTypeHint(btnType ButtonType) string

Types

type Button

type Button struct {
	Type       ButtonType `json:"type,omitempty"`
	Name       string     `json:"name,omitempty"`
	Key        string     `json:"key,omitempty"`
	Url        string     `json:"url,omitempty"`
	AppID      string     `json:"appid,omitempty"`
	PagePath   string     `json:"pagepath,omitempty"`
	MediaID    string     `json:"media_id,omitempty"`
	SubButtons []*Button  `json:"sub_button,omitempty"`
}

带有omitempty标签的字段如果为nil或者空,则转为json时会被忽略

func NewButton

func NewButton(btnType ButtonType, name, key, url, appID, pagePath, mediaID string, subButotns []*Button) (*Button, error)

type ButtonType

type ButtonType string

type ConditionalMenu

type ConditionalMenu struct {
	Menu
	MatchRules *MacthRule `json:"matchrule"`
	MenuID     int        `json:"menuid,omitempty"`
}

func NewConditionalMenu

func NewConditionalMenu() *ConditionalMenu

func (*ConditionalMenu) AddMatchRule

func (cm *ConditionalMenu) AddMatchRule(mr *MacthRule) error

func (*ConditionalMenu) PostAndCreate

func (menu *ConditionalMenu) PostAndCreate(accesstoken string) error

type MacthRule

type MacthRule struct {
	TagID              int           `json:"tag_id,omitempty"`
	Sex                MatchSex      `json:"sex,omitempty"`
	ClientPlatformType MatchPlatForm `json:"client_platform_type,omitempty"`
	Country            string        `json:"country,omitempty"`
	Province           string        `json:"province,omitempty"`
	City               string        `json:"city,omitempty"`
	Language           string        `json:"language,omitempty"`
}

matchrule共六个字段,均可为空,但不能全部为空,至少要有一个匹配信息是不为空的。 country、province、city组成地区信息,将按照country、province、city的顺序进行验证,要符合地区信息表的内容。 地区信息从大到小验证,小的可以不填,即若填写了省份信息,则国家信息也必填并且匹配,城市信息可以不填。

func NewMatchRule

func NewMatchRule(tagID int, sex MatchSex, pl MatchPlatForm, country, province, city, language string) *MacthRule

type MatchPlatForm

type MatchPlatForm string

type MatchSex

type MatchSex int
type Menu struct {
	Buttons []*Button `json:"button"`
	MenuID  int       `json:"menuid,omitempty"`
}

微信公众号规定,自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单。

func NewMenu

func NewMenu() *Menu

func TryUserMatchMenu

func TryUserMatchMenu(accessToken, userID string) (*Menu, error)

user_id可以是粉丝的OpenID,也可以是粉丝的微信号。

func (menu *Menu) AddButton(btn ...*Button) error
func (menu *Menu) PostAndCreate(accesstoken string) error
type MenuResult struct {
	Menu             *Menu              `json:"menu"`
	ConditionalMenus []*ConditionalMenu `json:"conditionalmenu"`
}

该结构体用于查询菜单接口的结果

func NewMenuResult

func NewMenuResult() *MenuResult

func QueryMenu

func QueryMenu(accessToken string) (*MenuResult, error)

Jump to

Keyboard shortcuts

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