微信官方文档 https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html
php代码
// 自定义菜单 public function menu(){ // 实例化微信操作类 $wx = new Wechat(); $token = $wx->getAccessToken(); $jsonmenu = '{ "button":[ { "name":"天气预报", "sub_button":[ { "type":"click", "name":"北京天气", "key":"天气北京" }, { "type":"click", "name":"上海天气", "key":"天气上海" }, { "type":"click", "name":"广州天气", "key":"天气广州" }, { "type":"click", "name":"深圳天气", "key":"天气深圳" }, { "type":"view", "name":"本地天气", "url":"http://m.hao123.com/a/tianqi" }] }, { "name":"瑞雪", "sub_button":[ { "type":"click", "name":"公司简介", "key":"company" }, { "type":"click", "name":"趣味游戏", "key":"游戏" }, { "type":"click", "name":"讲个笑话", "key":"笑话" }] }] }'; $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$token"; // 生成自定义菜单 $res = $wx->http_curl($url, 'post', 'json', $jsonmenu); echo "<pre>"; print_r($res); }
效果图
Wechat类是我自己封装的,比如获取access_token,ticket,curl请求这些,代码可以看上一篇文字 微信开发之生成二维码,扫码关注公众号PHP