自定义菜单

读取(查询)已设置菜单

  1. $list = $app->menu->list();

获取当前菜单

  1. $current = $app->menu->current();

添加菜单

添加普通菜单

  1. $buttons = [
  2. [
  3. "type" => "click",
  4. "name" => "今日歌曲",
  5. "key" => "V1001_TODAY_MUSIC"
  6. ],
  7. [
  8. "name" => "菜单",
  9. "sub_button" => [
  10. [
  11. "type" => "view",
  12. "name" => "搜索",
  13. "url" => "http://www.soso.com/"
  14. ],
  15. [
  16. "type" => "view",
  17. "name" => "视频",
  18. "url" => "http://v.qq.com/"
  19. ],
  20. [
  21. "type" => "click",
  22. "name" => "赞一下我们",
  23. "key" => "V1001_GOOD"
  24. ],
  25. ],
  26. ],
  27. ];
  28. $app->menu->create($buttons);

以上将会创建一个普通菜单。

添加个性化菜单

与创建普通菜单不同的是,需要在 create() 方法中将个性化匹配规则作为第二个参数传进去:

  1. $buttons = [
  2. // ...
  3. ];
  4. $matchRule = [
  5. "tag_id" => "2",
  6. "sex" => "1",
  7. "country" => "中国",
  8. "province" => "广东",
  9. "city" => "广州",
  10. "client_platform_type" => "2",
  11. "language" => "zh_CN"
  12. ];
  13. $app->menu->create($buttons, $matchRule);

删除菜单

有两种删除方式,一种是全部删除,另外一种是根据菜单 ID 来删除(删除个性化菜单时用,ID 从查询接口获取):

  1. $app->menu->delete(); // 全部
  2. $app->menu->delete($menuId);

测试个性化菜单

  1. $app->menu->match($userId);

$userId 可以是粉丝的 OpenID,也可以是粉丝的微信号。

返回 $menu 与指定的 $userId 匹配的菜单项。