github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/menu/menu_info.go (about) 1 package menu 2 3 import ( 4 "github.com/chanxuehong/wechat/mp/core" 5 ) 6 7 // 获取自定义菜单配置接口. 8 func GetMenuInfo(clt *core.Client) (info MenuInfo, isMenuOpen bool, err error) { 9 const incompleteURL = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=" 10 11 var result struct { 12 core.Error 13 IsMenuOpen int `json:"is_menu_open"` 14 MenuInfo MenuInfo `json:"selfmenu_info"` 15 } 16 if err = clt.GetJSON(incompleteURL, &result); err != nil { 17 return 18 } 19 if result.ErrCode != core.ErrCodeOK { 20 err = &result.Error 21 return 22 } 23 info = result.MenuInfo 24 if result.IsMenuOpen != 0 { 25 isMenuOpen = true 26 } 27 return 28 } 29 30 type MenuInfo struct { 31 Buttons []ButtonEx `json:"button,omitempty"` 32 } 33 34 type ButtonEx struct { 35 Type string `json:"type,omitempty"` 36 Name string `json:"name,omitempty"` 37 Key string `json:"key,omitempty"` 38 URL string `json:"url,omitempty"` 39 MediaId string `json:"media_id,omitempty"` 40 41 Value string `json:"value,omitempty"` 42 NewsInfo struct { 43 Articles []Article `json:"list,omitempty"` 44 } `json:"news_info"` 45 46 SubButton struct { 47 Buttons []ButtonEx `json:"list,omitempty"` 48 } `json:"sub_button"` 49 } 50 51 type Article struct { 52 Title string `json:"title,omitempty"` // 图文消息的标题 53 Author string `json:"author,omitempty"` // 作者 54 Digest string `json:"digest,omitempty"` // 摘要 55 ShowCover int `json:"show_cover"` // 是否显示封面, 0为不显示, 1为显示 56 CoverURL string `json:"cover_url,omitempty"` // 封面图片的URL 57 ContentURL string `json:"content_url,omitempty"` // 正文的URL 58 SourceURL string `json:"source_url,omitempty"` // 原文的URL, 若置空则无查看原文入口 59 }