<?php 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="xxxxxxx"; $APPSECRET="xxxxxxxx"; $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$APPID}&secret={$APPSECRET}"; $json=mp($url); $result=json_decode($json,true); $access_token=$result["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":"click", "name":"关于开发", "key":"承接网站建设/微信开发/小程序开发/安卓app开发等业务/联系13131271093(微信同)" }, { "type": "pic_photo_or_album", "name": "文字提取", "key": "rselfmenu_1_1", "sub_button": [ ] }] }, { "name":"看电影", "sub_button":[ { "type":"click", "name":"今日推荐", "key":"tuijian" }, { "type":"view", "name":"全部电影", "url":"http://dy.mushanhangu.com/dianying2/list11.php?page=1" }, { "type":"view", "name":"爱奇艺vip", "url":"http://dy.mushanhangu.com/qy/qyviplist.php?remen=4&page=1" }, { "type":"view", "name":"芒果vip", "url":"http://dy.mushanhangu.com/mg/mgviplist.php?page=1" }, { "type":"view", "name":"搜狐VIP", "url":"http://dy.mushanhangu.com/souhu/shviplist.php?page=1" }] }, { "name":"其它福利", "sub_button":[ { "type":"click", "name":"找优惠", "key":"youhui" }, { "type":"view", "name":"DJKK网", "url":"http://dy.mushanhangu.com/jiexi/djkk/djkk.php?fenlei=Kushiyaki&renqi=all&page=1" }, { "type":"click", "name":"AI传图取字", "key":"AI传图取字" }, { "type":"click", "name":"小宋斗图", "key":"小宋斗图" }, { "type":"click", "name":"视频去水印", "key":"视频去水印" }] }'; echo createMenu($data); //echo getMenu(); //echo deleteMenu();
