Create
Back

From WeChat Official Account Admin Platform
Jump to: navigation, search

The user-defined menu enriches official account interfaces so that the users can better and quickly understand the official account's features. An example of an official account with a user-defined menu is shown below:

2.jpg


A user-defined menu can include up to three level-one menus, and each level-one menu can include up to five level-two menus. A user-defined menu will show on WeChat client 24 hours after it is created due to the client's caching function. You can unfollow the official account and then re-follow it to check the menu's status.

The user-defined menu API enables the following button types:

 1. click:push click event
 Clicking a clickable button causes the WeChat server to push the click event to the developer through an event-type message API. The key value filled in by the developer is included on the button. The developer can reply to messages based on the user-defined key value.
 2. view:open URL
 Clicking a view-only button causes the WeChat client to open the URL entered by the developer on the button. Developers can use this type of button together with the Obtain User Basic Information via Web Authorization to obtain user information.
 3. scancode_push: Scanning
 Clicking this type of menu item causes the WeChat client to call the scanning software and display a scanning page (or redirect to a new URL) after scanning. The scanning result will be sent to the developer so that the developer's backend system can deliver a corresponding message based on the result.
 4. scancode_waitmsg: Scanning and popping up "receiving message"
 Clicking this type of menu item causes the WeChat client to call the scanning software. After scanning, the scanning result will be sent to the developer's backend system and the scanning software will be closed to display a "receiving message" prompt window. Later, the WeChat client may receive a message sent from the developer's backend system.
 5. pic_sysphoto: popping up System Camera window
 Clicking this type of menu item causes the WeChat client to call the camera. After taking a photo, the photo will be sent to the developer's backend system, a photo event message will be pushed to the developer's backend system, and the camera will be closed. Later, the WeChat client may receive a message sent from the developer's backend system.
 6. pic_photo_or_album: popping up System Images or Camera window
 Clicking this type of menu item causes the WeChat client to prompt a selection menu for users to select "Take Photo" / "Photo Album". After users select, the selected method will be shown.
 7. pic_weixin:poping up WeChat My Posts window 
 Clicking this type of menu item causes the WeChat client to open the album. After images are selected, the images will be sent to the developer's backend system,then the album will be closed. Later, the WeChat client may receive a message sent by the developer's backend system.
 8. location_select: popping up Location window
 Clicking this type of button causes the WeChat client to call the location selector. After a point-of-interest (POI) is selected, location information will be sent to the developer's backend system and the location selector will be closed. Later, the WeChat client may receive a message sent by the developer's backend system.

Note that buttons of types 3-8 are available to users in WeChat versions iOS v5.4.1 or greater and Android v5.4 or greater. For WeChat users running earlier versions of WeChat, the buttons will be grayed out and selecting them not result in the developer's backend system to receive event messages as normal.

Request Description

HTTP request method: POST (Use Https protocol)
https://api.wechat.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

Request Example:

 {
     "button":[
     {	
          "type":"click",
          "name":"Daily Song",
          "key":"V1001_TODAY_MUSIC"
      },
      {
           "type":"click",
           "name":" Artist Profile",
           "key":"V1001_TODAY_SINGER"
      },
      {
           "name":"Menu",
           "sub_button":[
           {	
               "type":"view",
               "name":"Search",
               "url":"http://www.soso.com/"
            },
            {
               "type":"view",
               "name":"Video",
               "url":"http://v.qq.com/"
            },
            {
               "type":"click",
               "name":"Like us",
               "key":"V1001_GOOD"
            }]
       }]
 }

Example about other menu item actions:

"button": [
        {
            "name": "Scan", 
            "sub_button": [
                {
                    "type": "scancode_waitmsg", 
                    "name": "Scan & prompt", 
                    "key": "rselfmenu_0_0", 
                    "sub_button": [ ]
                }, 
                {
                    "type": "scancode_push", 
                    "name": "Scan&push", 
                    "key": "rselfmenu_0_1", 
                    "sub_button": [ ]
                }
            ]
        }, 
        {
            "name": "Post picture", 
            "sub_button": [
                {
                    "type": "pic_sysphoto", 
                    "name": "Take photo & post picture", 
                    "key": "rselfmenu_1_0", 
                   "sub_button": [ ]
                 }, 
                {
                    "type": "pic_photo_or_album", 
                    "name": "Take photo | Photo Album", 
                    "key": "rselfmenu_1_1", 
                    "sub_button": [ ]
                }, 
                {
                    "type": "pic_weixin", 
                    "name": "Post album image", 
                    "key": "rselfmenu_1_2", 
                    "sub_button": [ ]
                }
            ]
        }, 
        {
            "name": "Select location", 
            "type": "location_select", 
            "key": "rselfmenu_2_0"
        }
    ]
}

Parameter Description

Parameter Required Description
button Yes Level-one menu array: 1-3 buttons
sub_button No Level-two menu array: 1-5 buttons
type Yes Button type: click and view
name Yes Button name up to 16 characters; sub menu up to 40 characters.
key Must be a Click type Button key value: used for pushing the message API (event type); up to 128 characters.
url Must be a View type Web URL: opened by clicking the menu; up to 256 bytes

Return Description

An example of a successful JSON response is as follows:

{"errcode":0,"errmsg":"ok"}

An example of an unsuccessful JSON response (caused by an invalid button name size) is as follows:

{"errcode":40018,"errmsg":"invalid button name size"}

Return Codes

Developer Guide
Custom-defined Menu
WeChat JS-SDK