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
Attention:
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):
Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
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://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; //Get 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 ': ' 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.