微信公众号开发中中可以自定义微信菜单
1.首先获取token
$access_token = $jssdk->getAccessToken();2. 修改json数据为一下格式:
"button":[
{
"name":"销售",
"sub_button":[
{
"type": "click",
"name": "新车推荐",
"key": "推荐新车"
},
{
"type":"view",
"name":"预约试驾",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=?svrType=DR%23plugin_testDrive-drive"
},
{
"type": "click",
"name": "商城",
"key": "城商"
},
{
"type": "click",
"name": "关于我们",
"key": "我们关于"
}]
},
{
"name":"售后",
"sub_button":[
{
"type":"view",
"name":"保养预约",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=?svrType=SV%23plugin_maintain-maintainces"
},
{
"type":"view",
"name":"维修预约",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=?svrType=MA%23plugin_sprayPaint-metalServiceStar"
},
{
"type":"view",
"name":"钣金喷漆",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=?svrType=SP%23plugin_sprayPaint-metalServiceStar"
},
{
"type": "click",
"name": "我要续保",
"key": "续保"
},
{
"type": "click",
"name": "道路救援",
"key": "救援"
}]
},
{
"name":"关于我们",
"sub_button":[
{
"type":"view",
"name":"总经理工作台",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=?svrType=MA%23managerView"
},
{
"type": "click",
"name": "联系我们",
"key": "key_aboutUs"
},
{
"type": "click",
"name": "产品服务简介",
"key": "简介"
},
{
"type":"view",
"name":"会员中心",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=myCard"
},
{
"type":"view",
"name":"用户中心",
"url":"http://oliveche.com/zhanda/weixin/index.php?entry=?svrType=MA#me"
}]
}]
}';
3.通过微信API将数据发送给微信。
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
4.查看微信返回的状态码结果是否是200。若返回正确,则过一段时间,菜单栏就会更改,若没有更改,是因为微信有缓存。
var_dump($result);
5.curl 请求封装。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;
}