公众号菜单获取、更新
公众号菜单获取
在extend/utiles/wechat/MenuService.php
里面如下 控制器请求该操作即可
/** * 获取微信公众号菜单 * @return array 返回菜单列表 */ public static function getMenu(){ $app = Factory::officialAccount(config('my.official_accounts')); $list = $app->menu->list(); return $list; }
公众号菜单更新(微信公众平台必须设置白名单)
在extend/utiles/wechat/MenuService.php
里面如下 控制器请求该操作即可
/** * 设置微信公众号菜单 * @return bools; $buttons = [ [ "type" => "click", "name" => "今日歌曲", "key" => "V1001_TODAY_MUSIC" ], [ "name" => "菜单", "sub_button" => [ [ "type" => "view", "name" => "搜索", "url" => "http://www.soso.com/" ], [ "type" => "view", "name" => "视频", "url" => "http://v.qq.com/" ], [ "type" => "click", "name" => "赞一下我们", "key" => "V1001_GOOD" ], ], ], ]; */ public static function setMenu($buttons){ $app = Factory::officialAccount(config('my.official_accounts')); try{ $res = $app->menu->create($buttons); }catch(\Exception $e){ log::error('微信菜单更新错误:'.print_r($e->getMessage(),true)); throw new \Exception('微信菜单更新失败'); } return $res; }