WeChat public platform development (8) custom menu function development _ PHP Tutorial

Source: Internet
Author: User
Public platform development (8) custom menu function development. The service number of the public platform and the subscription number that has been successfully applied for beta testing all have the function of customizing the menu. Developers can use this function to add

Public PlatformService numberAndSubscription No. successfully applied for beta testing qualificationAll have custom menu functions. Developers can use this function to add custom menus at the bottom of the public account's session interface. Users can click the Options in the menu to bring up corresponding reply information or webpage links. The custom menu interface provides more possibilities for the public account information display space. This article will make simple development and application for custom menus,

After obtaining 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 ):

View (webpage access ):

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.

Document address: http://mp.weixin.qq.com/wiki/index.php? Title = % E8 % 87% AA % E5 % AE % 9A % E4 % B9 % 89% E8 % 8F % 9C % E5 % 8D % 95% E6 % 8E % A5 % E5 % 8F % a3

3.1 obtain appid and appsecret

Find appid and appsecret in public platform> Advanced Functions> development mode.

3.2 Use appid and appsecret to request access_token from the interface for obtaining Creden

Request address: https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = APPID & secret = APPSECRET

Request parameter description:

Return description:

Correct Json return results:

{"access_token":"ACCESS_TOKEN","expires_in":7200}

Response parameters:

Access_token: the obtained credential.

Expires_in: The validity period of the credential. unit: seconds.

3.3 Specific implementation

A. print out the format

 

The result is as follows:

B. get access_token

 

Note: The access_token corresponds to the public number, which is globally unique. repeated acquisition will invalidate the last access_token.

Method:By posting a specific struct, you can create a custom menu on the client.

Request address: https://api.weixin.qq.com/cgi-bin/menu/create? Access_token = ACCESS_TOKEN


Example:

Menu structure and description:


Return description:

Correct Json return results:

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

Submit menu:

Use curl to submit the preceding menu data. the code is as follows:

="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=". =, CURLOPT_URL, , CURLOPT_CUSTOMREQUEST, "POST", CURLOPT_SSL_VERIFYPEER, , CURLOPT_SSL_VERIFYHOST, , CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)', CURLOPT_FOLLOWLOCATION, 1, CURLOPT_AUTOREFERER, 1, CURLOPT_POSTFIELDS, , CURLOPT_RETURNTRANSFER,  = curl_exec( (curl_errno( 'Errno'.curl_error(();

Running result:

Test results:

Menu created successfully.

Query the currently used custom menu structure.

Request address: https://api.weixin.qq.com/cgi-bin/menu/get? Access_token = ACCESS_TOKEN

The curl code is as follows:

="https://api.weixin.qq.com/cgi-bin/menu/get?access_token=". =, CURLOPT_URL, , CURLOPT_RETURNTRANSFER, 1 = curl_exec( = json_decode( ;

Cancels the currently used custom menu.

Request address: https://api.weixin.qq.com/cgi-bin/menu/delete? Access_token = ACCESS_TOKEN

The curl code is as follows:

= "Https://api.weixin.qq.com/cgi-bin/menu/delete? Access_token = ". =, CURLOPT_URL, CURLOPT_RETURNTRANSFER, 1 = curl_exec (= json_decode (-> errcode =" 0 "" menu deleted "" menu deleted "failed"

Running result:

Test results:

Menu deleted successfully.

VII. obtain the complete code

Go to QQ group 213260412 sharing to download and use it.

VIII. Follow

Please follow Zhuo Jin SuzhouPublic account, Zhuo Jin SuzhouDeveloped and tested based on the SAE platform for mainstream features.

You can follow Zhuo Jin SuzhouThe public account performs function tests and obtains new application development.

1. log on to the client, and choose "Add Friend"> "search number"> "zhuojinsz "..

2. scan the QR code:

Zhuo Jin SuzhouMenu function:

At present, the menu functions are still under development and will be updated one after another...

< p>

< strong>We Believe, Great People Share Knowledge...

The renewal service number and the subscription number that has been successfully applied for beta testing have the custom menu function. Developers can use this function to add the following content at the bottom of the public account session interface...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.