自定義菜單的創建
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 <?php define("APPID", "您的appid"); define("APPSECRET", "您的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); //獲取文件內容或獲取網絡請求的內容 //echo $res; $result = json_decode($res, true); //接受一個 JSON 格式的字符串並且把它轉換為 PHP 變量 $access_token = $result['access_token']; define("ACCESS_TOKEN", $access_token); //將access_token定義為常量,便於使用. $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . ACCESS_TOKEN; $menuData = ' { "button":[ { "type":"click", "name":"今日歌曲", "key":"V1001_TODAY_MUSIC" }, { "name":"菜單", "sub_button":[ { "type":"view", "name":"搜索", "url":"http://www.soso.com/" }, { "type":"view", "name":"視頻", "url":"http://v.qq.com/" }, { "type":"click", "name":"贊一下我們", "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 (curl_errno($ch)) { echo 'Error' . curl_error($ch); //用戶檢查php運行環境中的curl模塊開啟情況. } curl_close($ch); print_r($info); //查看post提交到微信服務器後,返回的數據.自定義菜單的獲取
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php define("APPID", "您的appid"); define("APPSECRET", "您的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); //獲取文件內容或獲取網絡請求的內容 $result = json_decode($res, true); //接受一個 JSON 格式的字符串並且把它轉換為 PHP 變量 $access_token = $result['access_token']; $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token; $menu_json = file_get_contents($make_menu_url); echo $menu_json;自定義菜單的刪除
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php define("APPID", "您的appid"); define("APPSECRET", "您的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); //獲取文件內容或獲取網絡請求的內容 $result = json_decode($res, true); //接受一個 JSON 格式的字符串並且把它轉換為 PHP 變量 $access_token = $result['access_token']; $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token; $menu_json = file_get_contents($make_menu_url); echo $menu_json;