header("Content-type: text/html; charset=utf-8");
function mp($url){
$user_agent = 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
@ $data = curl_exec($ch);
curl_close($ch);
return $data;
}
$APPID="";
$APPSECRET=" ";
header("Content-type: text/html; charset=utf-8");
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$APPID}&secret={$APPSECRET}";
//echo $url;
$json=mp($url);
//echo $json;
$result=json_decode($json,true);
//var_dump($result);
$access_token=$result["access_token"];
//echo $access_token;
define("ACCESS_TOKEN", $access_token);
//创建菜单
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;
}
//获取菜单
function getMenu(){
return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".ACCESS_TOKEN);
}
//删除菜单
function deleteMenu(){
return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".ACCESS_TOKEN);
}
$data = '{
"button":[
{
"name":"?生活服务",
"sub_button":[
{
"type":"click",
"name":"智能语音",
"key":"智能语音,想搜什么直接告诉我,记得要“按住说话”,说给我听"
},
{
"type": "location_select",
"name":"天气查询",
"key": "rselfmenu_2_0"
},
{
"type": "pic_photo_or_album",
"name": "文字提取",
"key": "rselfmenu_1_1",
"sub_button": [ ]
},
{
"type":"view",
"name":"分类信息",
"url":"http://"
}]
},
{
"name":"?其它福利",
"sub_button":[
{
"type":"click",
"name":"?找优惠",
"key":"youhui"
},
{
"type":"miniprogram",
"name":"伟航的小程序",
"url":"http://",
"appid":"wx22e6e4113e3de9da",
"pagepath":"pages/index/index"
},
{
"type":"view",
"name":"加入群聊",
"url":"http://www.0312of.com"
}]
}';
echo createMenu($data);
//echo getMenu();
//echo deleteMenu();