Skip to content
thenbsp edited this page Mar 3, 2016 · 4 revisions

创建菜单

菜单的值因菜单类型不同而不同,具体分为 key/url/media_id,菜单类型包括:

  • view
  • click
  • scancode_push
  • scancode_waitmsg
  • pic_sysphoto
  • pic_photo_or_album
  • pic_weixin
  • location_select
  • media_id
  • view_limited
use Thenbsp\Wechat\Menu\Button;
use Thenbsp\Wechat\Menu\ButtonCollection;

$button1 = new ButtonCollection('菜单一');
$button1->addChild(new Button('点击', 'click', 'key_1'));
$button1->addChild(new Button('打开网页', 'view', 'http://www.163.com/'));
$button1->addChild(new Button('扫码', 'scancode_push', 'key_2'));

$button2 = new ButtonCollection('菜单二');
$button2->addChild(new Button('系统拍照发图', 'pic_sysphoto', 'key_3'));
$button2->addChild(new Button('拍照或者相册发图', 'pic_photo_or_album', 'key_4'));
$button2->addChild(new Button('微信相册发图', 'pic_weixin', 'key_5'));

$button3 = new Button('菜单三', 'location_select', 'key_6');

发布菜单

use Thenbsp\Wechat\Menu\Create;

$create = new Create($accessToken);
$create->add($button1);
$create->add($button2);
$create->add($button3);

try {
    $create->doCreate();
} catch (\Exception $e) {
    exit($e->getMessage());
}

var_dump('菜单已创建成功');

一级菜单不能超过 3 个,子菜单不能超过 5 个。