小程序自定义菜单

以yii框架为例

微信官方文档

public function actionQrrr(){
        $APPID="wx3ea1*******148bc";
        $APPSECRET="7492106fcc*******f*******58d8a4e60";
        $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
        $date=$this->postcurl($url);
        $access_token=$date['access_token'];
        $url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
//        $url = 'https://'.$_SERVER['SERVER_NAME'];
        //type =  view
        $data = '{
    "button": [
        {
            "type": "miniprogram", 
            "name": "约课", 
            "url": "http://mp.weixin.qq.com", 
            "appid": "wx2ad7*****0990ca", 
            "pagepath": "pages/index/index"
        }, 
        {
            "name": "发现", 
            "sub_button": [
                {
                    "type": "miniprogram", 
                    "name": "邀请有礼 ∣ 优惠券", 
                    "url": "http://mp.weixin.qq.com", 
                    "appid": "wx2ad7***00990ca", 
                    "pagepath": "pages/index/invite/invite?type=1"
                }
            ]
        }, 
        {
            "name": "我的", 
            "sub_button": [
                {
                    "type": "miniprogram", 
                    "name": "我的预约", 
                    "url": "http://mp.weixin.qq.com", 
                    "appid": "wx2ad7*****8e00990ca", 
                    "pagepath": "pages/my/myCourse/myCourse?type=1"
                }, //跳转至小程序
                 {
                    "type": "scancode_push", 
                    "name": "上课扫码", 
                    "key": "rselfmenu_1_0", 
                    "sub_button": [ ]
                },//打开扫码
                 {
                    "type": "view",
                    "name": "迈小步", 
                    "url":"https://maibu.****club/maibuweb/BabyStep.html"
                },//打开网站
                {
                    "type": "media_id",
                    "name": "联系我们", 
                    "media_id": "ZwEU4ZHPpv_BkwVNH5VdHE5vuYt6_HqdwjuDW2DUxAY"
                },//获取素材
                {
                    "type": "view",
                    "name": "关于迈步", 
                    "url":"https://maibu.*******.club/maibuweb/AboutUs.html"
                }
            ]
        }
    ]
}';
        $result=$this->postcurl($url,urldecode($data));
        return json_encode($result);
    }
    //请求接口方法
    function postcurl($url,$data = null)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output = json_decode($output, true);
    }
    

你可能感兴趣的:(微信,自定义菜单,公众号)