How PHP Creates a custom menu of WeChat

Source: Internet
Author: User
This article mainly introduces the PHP implementation to create a custom menu method, combined with examples of PHP to create a custom menu of principles, procedures and specific implementation skills, the need for friends can refer to the following

The example in this article describes how the PHP implementation creates a custom menu. Share to everyone for your reference, as follows:

Before using the generic interface, you need to do the following two steps:

1. Have a public account and get to AppID and Appsecret(Apply for beta qualification on public platform and get it after approval)

2. Get to Access_token by obtaining the credential interface

Attention:

Access_token is a third-party ticket that accesses API resources;

Access_token corresponding to the public number is a globally unique ticket, and a duplicate fetch will result in the last acquired Access_token failure.

Visit the following address (note to replace your AppID and secret):

Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

Then the browser can see the return information:

{"Access_token": "Here is your Access_token", "expires_in": 7200}

To create a custom menu:

<?phpheader ("content-type:text/html; Charset=utf-8 ");d efine (" Access_token "," Fill in the Access_token you get Above ");//Create Menu function CreateMenu ($data) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=". Access_token); curl_setopt ($ch, Curlopt_customrequest, "POST") curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE); curl _setopt ($ch, Curlopt_ssl_verifyhost, FALSE); curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0) curl_setopt ($ch, curlopt_followlocation, 1); curl_setopt ($ch, Curlopt_autoreferer, 1); Curl_setopt ($ CH, curlopt_postfields, $data); curl_setopt ($ch, Curlopt_returntransfer, true); $tmpInfo = Curl_exec ($ch); if (curl_ errno ($ch)) {return curl_error ($ch);} Curl_close ($ch); return $tmpInfo;} Gets the menu function GetMenu () {return file_get_contents ("https://api.weixin.qq.com/cgi-bin/menu/get?access_token="). Access_token);} Delete Menu function DeleteMenu () {return file_get_contents ("Https://api.weixin.qq.com/cgi-bin/menu/deLete?access_token= ". Access_token);} $data = ' {' ' button ': [{' Type ': ' Click ', ' name ': ' Home ', ' key ': ' The "}, {' Type ': ' Click ', ' name ' ": Introduction", "Key": "Introduct"}, {"Name": "Menu", "Sub_button": [{"Type": "click", "Name": "Hello word", "key": "V1001_hello_world"}, {"Type": "click", "Name": "Likes Us", "Key": " V1001_good "}]}]} '; echo CreateMenu ($data);//echo GetMenu ();//echo DeleteMenu ();

Related recommendations:

Ways to create a custom menu in PHP

PHP custom Menu interface, customer service interface, QR code with a detailed description

PHP implementation to create custom menu Instances

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.