微信 自定义菜单 菜单响应 代码

除view类型可以直接在url中赋值跳转链接外,其它都需要在接口代码如responsemsg()内实现响应处理

<?php

$appid = "wx";
$appsecret = "0a0b97ad97ee2";
$times= date('y年m月d日 H:i:s',time());
echo $times."</br>";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;//取得token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
// echo $access_token."</br>";
$jsonmenu='{
    "button": [
    {
        "name": "学生",
        "sub_button": [
        {
            "type": "view",
            "name": "校园生活",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3Mzc5Nzg5OQ=b8&scene=1&srcid=03167nGF2xChIkNBVPVTb5Hw#wechat_redirect"
        },
        {
            "type": "view",
            "name": "校园明星",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3Mscene=1&srcid=0316P9Sig7iUFn0k6tMDJHX0#wechat_redirect"
        }
        ]
    },
    {
        "name": "教师",
        "sub_button": [
        {
            "type": "view",
            "name": "硕果累累",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3Mzc5Nzgcid=0316AuGEc8qIowrpV3B3bgsu#wechat_redirect"
        }
        ]
    },
    {
        "name": "学校",
        "sub_button": [
        {
            "type": "view",
            "name": "校园新闻",
            "url": "http://mp.weixin.qq.com/s?__biz=MzA3Mzc5Nzg5OQ==&mid=4081810EQhiTnao7WbWdK#wechat_redirect"
        },
        {
            "type": "view",
            "name": "学校简介",
            "url": "http://eqxiu.com/s/N9rn"
        }
        ]
    }
    ]
}
    ';
$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);
    //     echo "</br>";
    //     echo $output;
    return $output;
}
?>


你可能感兴趣的:(微信 自定义菜单 菜单响应 代码)