您的位置:首页 > 移动开发 > 微信开发

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

2017-05-31 20:36 239 查看
原因是,最后一个元素有逗号

<?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;
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  微信 公众号 菜单