1. 程式人生 > >【已解決】開發模式下,微信公眾號自定義選單顯示不全

【已解決】開發模式下,微信公眾號自定義選單顯示不全

原因是,最後一個元素有逗號

<?php

$appid = "wx111111111111111";
$appsecret = "2222222222222222222222222222";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";

$output = https_request($url);
$jsoninfo = json_decode($output, true);

$access_token = $jsoninfo["access_token"];


$jsonmenu = '{
      "button":[
      {
            "name":"明星產品",
           "sub_button":[
           {
	               "type":"view",
	               "name":"限時搶購",
	               "url":"http://www.dadangsc.com/wx.php/home/goods/goodsinfo/id/268.html" //注意此處不允許有逗號,否則後面的選單都展現不出來
	           },
	            {
	               "type":"view",
	               "name":"每日推薦",
	               "url":"http://www.dadangsc.com/wx.php/home/goods/goodsinfo/id/243.html"
	            },
	            {
	               "type":"view",
	               "name":"每週爆款",
	               "url":"http://www.dadangsc.com/wx.php/home/goods/goodsinfo/id/96.html"
	            },
	            {
	               "type":"view",
	               "name":"月度明星",
	               "url":"http://www.dadangsc.com/wx.php/home/goods/goodsinfo/id/27.html"
	            }]
      

       },
       {
           "name":"進入商城",
           "type":"view",
           "url":"http://www.dadangsc.com/wx.php",
           "sub_button": []
       },
       {
           "name":"使用者中心",
           "sub_button":
           [
	            {
	               "type":"view",
	               "name":"我的主頁",
	               "url":"http://www.dadangsc.com/wx.php/home/user/userindex/test/four.html"
	            },
	            {
	               "type":"view",
	               "name":"快遞查詢",
	               "url":"http://m.kuaidi100.com/#input"
	            },
	            {
	               "type":"view",
	               "name":"線上客服",
	               "url":"http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=820706&configID=151385&jid=5530154684"
	            }
           ]
       }]
 }';


$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
var_dump($result);

function https_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}
?>