微信公众号开发教程[011]-自定义菜单以及个性化菜单

      自定义菜单最多包括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"
		},
		{
			
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值