<commit_before># 自定义菜单 - 创建菜单

创建自定义菜单需要注入 AccessToken，创建菜单前需要先定义菜单。

## 菜单定义

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

- view
- click
- scancode_push
- scancode_waitmsg
- pic_sysphoto
- pic_photo_or_album
- pic_weixin
- location_select
- media_id
- view_limited

```php
$button = new \Thenbsp\Wechat\Menu\Button('菜单名称', '菜单类型', 'key/url/media_id');
```

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

```php
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');
```

## 创建菜单

```php
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('菜单已创建成功');
```<commit_msg>change menu-create doc<commit_after># 自定义菜单 - 创建菜单

创建自定义菜单需要注入 AccessToken，创建菜单前需要先定义菜单。

## 定义菜单

```php
use Thenbsp\Wechat\Menu\Button;
use Thenbsp\Wechat\Menu\ButtonCollection;

// 菜单集合
$buttonCollection   = new ButtonCollection('菜单名称');

// 一级菜单
$button = new \Thenbsp\Wechat\Menu\Button('菜单名称', '菜单类型', '菜单值');
```

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

- view
- click
- scancode_push
- scancode_waitmsg
- pic_sysphoto
- pic_photo_or_album
- pic_weixin
- location_select
- media_id
- view_limited

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

```php
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');
```

## 创建菜单

```php
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('菜单已创建成功');
```
{'fraction_non_alphanumeric': 0.18760698390962, 'fraction_numerical': 0.015748031496062992, 'mean_word_length': 4.441340782122905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2239877', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1525, 'n_words': 189}