Introduction
After obtaining the credential (how to obtain the credential), the developer can use the credential to create, query, and delete user-defined menus of the public account. The custom menu interface supports the following buttons:
Click (click event): After you click the click type button, the server pushes the click event to the developer through the message interface (event type), and carries the key value filled by the developer in the button, developers can reply to a message through a custom key value. View (webpage access): After you click the view type button, the page will jump directly to the url specified by the developer.
After the custom menu is created, it takes 24 hours for the client to appear because of the client cache. We recommend that you try to remove the public account and follow it again during the test to see the effect after creation.
Menu Creation
Interface Description
By posting a specific struct, you can create a custom menu on the client.
Request description
Http Request Method: POSThttps: // api.weixin.qq.com/cgi-bin/menu/create? Access_token = ACCESS_TOKEN
Request example
{"Button": [{"type": "click", "name": "Today's songs", "key": "V1001_TODAY_MUSIC" },{ "type ": "view", "name": "artist profile", "url": "http://www.bkjia.com/" },{ "name": "menu", "sub_button ": [{"type": "click", "name": "hello word", "key": "V1001_HELLO_WORLD" },{ "type": "click ", "name": "like us", "key": "V1001_GOOD"}]}
Effect after creation:
Parameter description
| Parameters |
Required? |
Description |
| Button |
Yes |
Button array, the number of buttons should be 2 ~ 3 |
| Sub_button |
No |
Array of child buttons. The number of buttons should be 2 ~ Five |
| Type |
Yes |
Button type, which currently has the click type |
| Name |
Yes |
Button description. The name of a button cannot exceed 16 bytes, and the sub-menu cannot exceed 40 bytes. |
| Key |
Required for clicking type |
The KEY value of the button. It is used for message interface (event Type) Push and cannot exceed 128 bytes. |
Return description
Correct Json return results:
{"errcode":0,"errmsg":"ok"}
Incorrect Json return result
{"errcode":40018,"errmsg":"invalid button name size"}
Uniform return code Description
Menu Query
Interface Description
Query the currently used custom menu structure.
Request description
Http Request Method: GEThttps: // api.weixin.qq.com/cgi-bin/menu/get? Access_token = ACCESS_TOKEN
Return description
Corresponding to the creation interface, the correct Json return result: {"menu": {"button": [{"type": "click", "name": "Today's song ", "key": "V1001_TODAY_MUSIC", "sub_button": [] },{ "type": "click", "name": "", "key ": "V1001_TODAY_SINGER", "sub_button": [] },{ "name": "menu", "sub_button": [{"type": "click", "name ": "hello word", "key": "V1001_HELLO_WORLD", "sub_button": [] },{ "type": "click", "name": "like us ", "key": "V1001_GOOD", "sub_button": []}
Uniform return code Description
Menu Deletion
Interface Description
Cancels the currently used custom menu.
Request description
Http Request Method: GEThttps: // api.weixin.qq.com/cgi-bin/menu/delete? Access_token = ACCESS_TOKEN
Return description
Corresponding to the created interface, the correct Json return result: {"errcode": 0, "errmsg": "OK "}