Home  >  Article  >  Backend Development  >  WeChat custom menu interface_PHP tutorial

WeChat custom menu interface_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:09888browse

Introduction

After the developer obtains the usage voucher (how to obtain the voucher), the developer can use the voucher to create, query, and delete the custom menu of the public account. The custom menu interface can implement the following types of buttons:

click(点击事件):

用户点击click类型按钮后,微信服务器会通过消息接口(event类型)推送点击事件给开发者,并且带上按钮中开发者填写的key值,开发者可以通过自定义的key值进行消息回复。

view(访问网页):

用户点击view类型按钮后,会直接跳转到开发者指定的url中。

After creating a custom menu, it will take 24 hours for the WeChat client to display it due to WeChat client caching. It is recommended that when testing, you can try to unfollow the public account and follow it again, and you can see the effect after creation.

Menu Creation

Interface Description

Create a custom menu on the WeChat client by POSTing a specific structure.


Request instructions

http请求方式:POST
https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

Request example

{
     "button":[
     {	
          "type":"click",
          "name":"今日歌曲",
          "key":"V1001_TODAY_MUSIC"
      },
      {
           "type":"view",
           "name":"歌手简介",
           "url":"http://www.bkjia.com/"
      },
      {
           "name":"菜单",
           "sub_button":[
            {
               "type":"click",
               "name":"hello word",
               "key":"V1001_HELLO_WORLD"
            },
            {
               "type":"click",
               "name":"赞一下我们",
               "key":"V1001_GOOD"
            }]
       }]
 }

After creation effect:

WeChat custom menu interface_PHP tutorial

Parameter description

参数 是否必须 说明
button 按钮数组,按钮个数应为2~3个
sub_button 子按钮数组,按钮个数应为2~5个
type 按钮类型,目前有click类型
name 按钮描述,既按钮名字,不超过16个字节,子菜单不超过40个字节
key 类型为click必须 按钮KEY值,用于消息接口(event类型)推送,不超过128字节

Return instructions

Correct Json return result:

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

Wrong Json return result

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

Unified return code description

Menu query

Interface Description

Query the currently used custom menu structure.

Request instructions

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

Return instructions

对应创建接口,正确的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":"click","name":"hello word","key":"V1001_HELLO_WORLD","sub_button":[]},{"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]}]}}

Unified return code description

Menu Delete

Interface Description

Cancel the currently used custom menu.

Request instructions

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

Return instructions

对应创建接口,正确的Json返回结果:
{"errcode":0,"errmsg":"ok"}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445640.htmlTechArticleIntroduction After developers obtain the usage certificate (how to obtain the certificate), they can use the certificate to customize the menu of the public account Perform operations such as creation, query, and deletion. Custom menu interface...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn