From 2bb40a640e259fc45a2f709997e88a96231afd08 Mon Sep 17 00:00:00 2001 From: wenzl Date: Fri, 16 Sep 2016 14:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- menu/menu.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/menu/menu.go b/menu/menu.go index f744bee..80900ab 100644 --- a/menu/menu.go +++ b/menu/menu.go @@ -15,6 +15,7 @@ const ( menuAddConditionalURL = "https://api.weixin.qq.com/cgi-bin/menu/addconditional" menuDeleteConditionalURL = "https://api.weixin.qq.com/cgi-bin/menu/delconditional" menuTryMatchURL = "https://api.weixin.qq.com/cgi-bin/menu/trymatch" + menuSelfMenuInfoURL = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info" ) //Menu struct @@ -63,6 +64,42 @@ type ResMenu struct { conditionalmenu []resConditionalMenu `json:"conditionalmenu"` } +//ResSelfMenuInfo 自定义菜单配置返回结果 +type ResSelfMenuInfo struct { + util.CommonError + + IsMenuOpen int32 `json:"is_menu_open"` + SelfMenuInfo struct { + Button []SelfMenuButton `json:"button"` + } `json:"selfmenu_info"` +} + +//SelfMenuButton 自定义菜单配置详情 +type SelfMenuButton struct { + Type string `json:"type"` + Name string `json:"name"` + Key string `json:"key"` + URL string `json:"url,omitempty"` + Value string `json:"value,omitempty"` + SubButton struct { + List []SelfMenuButton `json:"list"` + } `json:"sub_button,omitempty"` + NewsInfo struct { + List []ButtonNew `json:"list"` + } `json:"news_info,omitempty"` +} + +//ButtonNew 图文消息菜单 +type ButtonNew struct { + Title string `json:"title"` + Author string `json:"author"` + Digest string `json:"digest"` + ShowCover int32 `json:"show_cover"` + CoverURL string `json:"cover_url"` + ContentURL string `json:"content_url"` + SourceURL string `json:"source_url"` +} + //MatchRule 个性化菜单规则 type MatchRule struct { GroupID int32 `json:"group_id,omitempty"` @@ -235,3 +272,28 @@ func (menu *Menu) MenuTryMatch(userID string) (buttons []Button, err error) { buttons = resMenuTryMatch.Button return } + +//GetCurrentSelfMenuInfo 获取自定义菜单配置接口 +func (menu *Menu) GetCurrentSelfMenuInfo() (resSelfMenuInfo ResSelfMenuInfo, err error) { + var accessToken string + accessToken, err = menu.GetAccessToken() + if err != nil { + return + } + uri := fmt.Sprintf("%s?access_token=%s", menuSelfMenuInfoURL, accessToken) + var response []byte + response, err = util.HTTPGet(uri) + if err != nil { + return + } + fmt.Println(string(response)) + err = json.Unmarshal(response, &resSelfMenuInfo) + if err != nil { + return + } + if resSelfMenuInfo.ErrCode != 0 { + err = fmt.Errorf("GetCurrentSelfMenuInfo Error , errcode=%d , errmsg=%s", resSelfMenuInfo.ErrCode, resSelfMenuInfo.ErrMsg) + return + } + return +}