【已解决】开发模式下,微信公众号自定义菜单显示不全

原因是,最后一个元素有逗号

 

<?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;
}
?>

 

欢迎关注

硕士茂哥
硕士茂哥

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值