1. 程式人生 > >微信開發學習總結(四)——自定義選單(2)——自定義選單查詢介面

微信開發學習總結(四)——自定義選單(2)——自定義選單查詢介面

自定義選單查詢介面

使用介面建立自定義選單後,開發者還可使用介面查詢自定義選單的結構。另外請注意,在設定了個性化選單後,使用本自定義選單查詢介面可以獲取預設選單和全部個性化選單資訊。

請求說明

http請求方式:GET
https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN

返回說明(無個性化選單時)

對應建立介面,正確的Json返回結果:
{
    "menu": {
        "button": [
            {
                "type": "click", 
                "name": "今日歌曲", 
                "key": "V1001_TODAY_MUSIC", 
                "sub_button": [ ]
            }, 
            {
                "type": "click", 
                "name": "歌手簡介", 
                "key": "V1001_TODAY_SINGER", 
                "sub_button": [ ]
            }, 
            {
                "name": "選單", 
                "sub_button": [
                    {
                        "type": "view", 
                        "name": "搜尋", 
                        "url": "http://www.soso.com/", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "view", 
                        "name": "視訊", 
                        "url": "http://v.qq.com/", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "click", 
                        "name": "贊一下我們", 
                        "key": "V1001_GOOD", 
                        "sub_button": [ ]
                    }
                ]
            }
        ]
    }
}

返回說明(有個性化選單時)

{
    "menu": {
        "button": [
            {
                "type": "click", 
                "name": "今日歌曲", 
                "key": "V1001_TODAY_MUSIC", 
                "sub_button": [ ]
            }
        ], 
        "menuid": 208396938
    }, 
    "conditionalmenu": [
        {
            "button": [
                {
                    "type": "click", 
                    "name": "今日歌曲", 
                    "key": "V1001_TODAY_MUSIC", 
                    "sub_button": [ ]
                }, 
                {
                    "name": "選單", 
                    "sub_button": [
                        {
                            "type": "view", 
                            "name": "搜尋", 
                            "url": "http://www.soso.com/", 
                            "sub_button": [ ]
                        }, 
                        {
                            "type": "view", 
                            "name": "視訊", 
                            "url": "http://v.qq.com/", 
                            "sub_button": [ ]
                        }, 
                        {
                            "type": "click", 
                            "name": "贊一下我們", 
                            "key": "V1001_GOOD", 
                            "sub_button": [ ]
                        }
                    ]
                }
            ], 
            "matchrule": {
                "group_id": 2, 
                "sex": 1, 
                "country": "中國", 
                "province": "廣東", 
                "city": "廣州", 
                "client_platform_type": 2
            }, 
            "menuid": 208396993
        }
    ]
}

注:menu為預設選單,conditionalmenu為個性化選單列表。欄位說明請見個性化選單介面頁的說明。

在這裡插入圖片描述

返回結果

200	OK
Connection: keep-alive
Date: Tue, 02 Oct 2018 14:12:09 GMT
Content-Type: application/json; encoding=utf-8
Content-Length: 841
{
    "menu": {
        "button": [
            {
                "name": "選單標題1", 
                "sub_button": [
                    {
                        "type": "click", 
                        "name": "點選型別選單1", 
                        "key": "1", 
                        "sub_button": [ ]
                    }
                ]
            }, 
            {
                "name": "選單標題2", 
                "sub_button": [
                    {
                        "type": "click", 
                        "name": "點選型別選單1", 
                        "key": "11", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "view", 
                        "name": "點選網頁型別1", 
                        "url": "http://www.baidu.com", 
                        "sub_button": [ ]
                    }
                ]
            }, 
            {
                "name": "選單標題3", 
                "sub_button": [
                    {
                        "type": "scancode_push", 
                        "name": "掃碼推事件", 
                        "key": "scancode_push", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "scancode_waitmsg", 
                        "name": "掃碼帶提示", 
                        "key": "scancode_waitmsg", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "pic_sysphoto", 
                        "name": "系統拍照發圖", 
                        "key": "pic_sysphoto", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "pic_photo_or_album", 
                        "name": "拍照或者相簿發圖", 
                        "key": "pic_photo_or_album", 
                        "sub_button": [ ]
                    }, 
                    {
                        "type": "pic_weixin", 
                        "name": "微信相簿發圖", 
                        "key": "pic_weixin", 
                        "sub_button": [ ]
                    }
                ]
            }
        ]
    }
}