How to create a custom menu using PHP _php Tips

Source: Internet
Author: User

Before using a generic interface, you need to do the following two steps:
1. Have a micro-letter public account, and access to AppID and Appsecret (on the public platform to apply for the beta qualification, after the approval can be obtained)
2. Obtain the Access_token by obtaining the voucher interface
Access_token is a third-party access to API resources of the bill;
Access_token corresponds to a public number that is globally unique, and repeated acquisition will cause the last acquired access_token to fail.

Visit this address below (note to replace your AppID and secret):


Then you can see the return information in the browser:
{"Access_token": "Here is your Access_token", "expires_in": 7200}

To create a custom menu:

<?php header ("content-type:text/html;
Charset=utf-8 ");

Define ("Access_token", "Fill in the Access_token you get Above"); Create Menu function CreateMenu ($data) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, "Https:// /menu/create?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; //Get Menu function GetMenu () {return file_get_contents ("").
Access_token); //Delete menu function DeleteMenu () {return file_get_contents (" ".
Access_token); $data = ' {button ': [{' Type ': ' Click ', ' Name ': ' First ', ' key ': ' Home '}, {' Type ': ' CLI CK ", Name:" Introduction "," Key ":" Introduct "}, {" Name ":" Menu "," Sub_button ": [{' type ':] "Click", "Name": "Hello word", "key": "V1001_hello_world"}, {"Type": "Click", "

Name ":" Praise Us "," Key ":" V1001_good "}]}]} ';
Echo CreateMenu ($data);
Echo GetMenu ();
 Echo DeleteMenu ();

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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: 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.