玩转微信公号开发(六)——设置菜单

这里要讲的是,在开发模式下,如何自定义菜单

因为可能有中文乱码的问题,所以这里直接拼json串,然后调接口,post就ok了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public function weixin_custom_menu(){
	$token 		= WXUtil::getAccessToken();
	$url 			= "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$token;
	$msg 		= '{"button":['
		//单菜单
		.'{"type":"click","name":"现在购买","key":"BTN_1"},'
		.'{"type":"click","name":"优惠活动","key":"BTN_2"},'
		.'{"name":"帮助",//多级菜单
			"sub_button":[
					{"type":"view","name":"下载","url":"http://xx.com/download.html"},
					{"type":"view","name":"使用教程","url":"http://xx.com/howbuy.html"},  
					{"type":"view","name":"关于我们","url":"http://xx.com/about.html"}
				]
			}
		]}';
	echo $msg;
	$r 		= Http::httpsPost($url, $msg);
	print_r($r);//打印结果,返回error为0的话,即为设置成功
	exit;
}

参数说明

  • type,按钮的类型
    1. click,按钮,点击后,发送给开发者网关一个事件
      view,链接,打开一个webview页面,页面地址为url字段指定
  • name,按钮的显示名称
  • key,事件标示,对应本系列第二篇里提到的EventKey字段
  • url

菜单设置后,通常需要退出公众号再进一次才能生效,如果还不行,只能取消关注、再关注一次

————
转载请注明住处:http://www.jiangkl.com/2014/01/weixin_custom_menu

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

*