|
<? Php
Define ("APPID", "Your appid ");
Define ("APPSECRET", "Your appsecret ");
$ Token_access_url = "https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = ". APPID." & secret = ". APPSECRET;
$ Res = file_get_contents ($ token_access_url); // get the file content or the content of the network request
// Echo $ res;
$ Result = json_decode ($ res, true); // receives a JSON string and converts it to a PHP variable.
$ Access_token = $ result ['Access _ token'];
Define ("ACCESS_TOKEN", $ access_token); // defines access_token as a constant for ease of use.
$ Make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/create? Access_token = ". ACCESS_TOKEN;
$ MenuData = '{
"Button ":[
{
"Type": "click ",
"Name": "Today's songs ",
"Key": "V1001_TODAY_MUSIC"
},
{
"Name": "menu ",
"Sub_button ":[
{
"Type": "view ",
"Name": "Search ",
"Url": "http://www.soso.com /"
},
{
"Type": "view ",
"Name": "video ",
"Url": "http://v.qq.com /"
},
{
"Type": "click ",
"Name": "like us ",
"Key": "V1001_GOOD"
}]
}]
}';
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ make_menu_url );
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 6.0; Windows NT 5.1;. net clr 1.1.4322 )");
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Curl_setopt ($ ch, CURLOPT_AUTOREFERER, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ menuData );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE );
$ Info = curl_exec ($ ch );
// If an error occurs during execution, a data error report is sent.
If (curl_errno ($ ch )){
Echo 'error'. curl_error ($ ch); // check whether the curl module is enabled in the php runtime environment.
}
Curl_close ($ ch );
Print_r ($ info); // view the data returned after the post is submitted to the server.
|