一段简单的自定义微信公众号菜单代码

$appId = $_POST['appId'];
    $appSecret = $_POST['appSecret'];


        $get_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+$appId+'&secret='+$appSecret;
        $get_return = file_get_contents($get_url);
        $get_return = (array)json_decode($get_return);
        if( !isset($get_return['access_token']) ){exit( '获取access_token失败!' );}

$ejson = '{ 
                     "button":[
                         {
                               "name":"篮球",
                               "sub_button":[
                                    {
                                       "type":"click",
                                       "name":"nba",
                                       "key":"V1001_NBA"
                                    },
                                    {
                                       "type":"click",
                                       "name":"cba",
                                       "key":"V1001_CBA"
                                    }
                                ]
                           },
                           {
                               "name":"体育",
                               "sub_button":[
                                    {
                                       "type":"click",
                                       "name":"足球",
                                       "key":"V1001_ZUQIU"
                                    },
                                    {
                                       "type":"click",
                                       "name":"排球",
                                       "key":"V1001_PAIQIU"
                                    },
                                    {
                                       "type":"click",
                                       "name":"台球",
                                       "key":"V1001_TAIQIU"
                                    }
                                ]
                           },
                           {
                               "name":"新闻",
                               "sub_button":[
                                    {
                                       "type":"click",
                                       "name":"国内新闻",
                                       "key":"V1001_GNNEWS"
                                    },
                                    {
                                       "type":"click",
                                       "name":"国际新闻",
                                       "key":"V1001_GJNEWS"
                                    }
                                ]
                           }
                       ]
                    }';


        $post_url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$get_return['access_token'];
        $ch = curl_init($post_url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS,$ejson);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($ejson))
        );
        $respose_data = curl_exec($ch);
        echo $respose_data;
        exit;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值