自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单.类型分别有click,view,scancode_push,scancode_waitmsg,pic_sysphoto,pic_photo_or_album,pic_weixin,location_select,media_id,view_limited.详见官方文档.
一.通用的自定义菜单
1).创建通用菜单.代码如下:
function create() {
$ACCESS_TOKEN = "uZNdRwxNN3V7RwT5x_K8K21wNWfO1kX4dMH3JS0usWmXXMIB03-WWoTfMg8as1NyuznLfZK_GqYgJgqiYwIRO4dCK0ZbYNQd-5cxYSX5awA3TkEE-5Qn4QTneX8YIpnTJWJfABAZMZ";
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$ACCESS_TOKEN";
$data = '
{
"button": [
{
"type": "click",
"name": "今日歌曲",
"key": "V1001_TODAY_MUSIC"
},
{
"name": "菜单",
"sub_button": [
{
"type": "click",
"name": "1.click.赞一下我们",
"key": "V1001_GOOD"
},
{
"type": "view",
"name": "2.view.视频",
"url": "http://v.qq.com/"
},
{
"type": "scancode_push",
"name": "3.scancode_push.扫码推事件",
"key": "rselfmenu_0_1",
"sub_button": []
},
{
"type": "scancode_waitmsg",
"name": "4.scancode_waitmsg.扫码带提示",
"key": "rselfmenu_0_0",
"sub_button": []
},
{
"type": "pic_sysphoto",
"name": "5.pic_sysphoto.系统拍照发图",
"key": "rselfmenu_1_0",
"sub_button": []
}]
},
{
"name": "菜单",
"sub_button": [
{
"type": "pic_photo_or_album",
"name": "6.pic_photo_or_album.拍照/相册发图",
"key": "rselfmenu_1_1",
"sub_button": []
},
{
"type": "pic_weixin",
"name": "7.pic_weixin.微信相册发图",
"key": "rselfmenu_1_2",
"sub_button": []
},
{
"type": "location_select",
"name": "8.location_select.发送位置",
"key": "rselfmenu_2_0"
}]
}]
}
';
$result = curl_http_post($url, $data);
echo $result;
}
返回结果如下:
{"errcode":0,"errmsg":"ok"}
2).查询通用菜单.代码如下:
function query() {
$ACCESS_TOKEN = "uZNdRwxNN3V7RwT5x_K8K21wNWfO1kX4dMH3JS0usWmXXMIB03-WWoTfMg8as1NyuznLfZK_GqYgJgqiYwIRO4dCK0ZbYNQd-5cxYSX5awA3TkEE-5Qn4QTneX8YIpnTJWJfABAZMZ";
$url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=$ACCESS_TOKEN";
$result = curl_http_get($url);
echo $result;
}
返回结果如下:
{
"button": [
{
"type": "click",
"name": "今日歌曲",
"key": "V1001_TODAY_MUSIC"
},
{
"name": "菜单",
"sub_button": [
{
"type": "click",
"name": "1.click.赞一下我们",
"key": "V1001_GOOD"
},
{