自定义微信菜单(一)

微信公众号开发中中可以自定义微信菜单

1.首先获取token

    $access_token = $jssdk->getAccessToken();

2. 修改json数据为一下格式:


$jsonmenu = '{
      "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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值