mirror of
https://github.com/w7corp/easywechat.git
synced 2025-01-22 19:52:10 +00:00
Updated 自定义菜单 (markdown)
parent
47b55f1be0
commit
76c3fe9bac
14
自定义菜单.md
14
自定义菜单.md
@ -24,15 +24,15 @@ use Overtrue\Wechat\MenuItem;
|
|||||||
$appId = 'wx3cf0f39249eb0e60';
|
$appId = 'wx3cf0f39249eb0e60';
|
||||||
$secret = 'f1c242f4f28f735d4687abb469072a29';
|
$secret = 'f1c242f4f28f735d4687abb469072a29';
|
||||||
|
|
||||||
$menu = new Menu($appId, $secret);
|
$menuService = new Menu($appId, $secret);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
+ `array $menu->get();` 读取菜单
|
+ `array $menuService->get();` 读取菜单
|
||||||
+ `boolean $menu->set(array $menus);` 设置菜单,参数为一个包含最多三个一级菜单项的数组
|
+ `boolean $menuService->set(array $menus);` 设置菜单,参数为一个包含最多三个一级菜单项的数组
|
||||||
+ `boolean $menu->delete();` 删除菜单
|
+ `boolean $menuService->delete();` 删除菜单
|
||||||
+ `new MenuItem($name, $type = null, $key = null)` 创建一个菜单项
|
+ `new MenuItem($name, $type = null, $key = null)` 创建一个菜单项
|
||||||
- `$name` 菜单项名称,比如:`今日歌曲`
|
- `$name` 菜单项名称,比如:`今日歌曲`
|
||||||
- `$type` 菜单项类型,比如:`view`,`click`等,更多请参考 http://mp.weixin.qq.com/wiki `自定义菜单` 章节。
|
- `$type` 菜单项类型,比如:`view`,`click`等,更多请参考 http://mp.weixin.qq.com/wiki `自定义菜单` 章节。
|
||||||
@ -60,7 +60,7 @@ $menus = array(
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$menu->set($menus);// 请求微信服务器
|
$menuService->set($menus);// 请求微信服务器
|
||||||
echo '设置成功!';
|
echo '设置成功!';
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
echo '设置失败:' . $e->getMessage();
|
echo '设置失败:' . $e->getMessage();
|
||||||
@ -168,7 +168,7 @@ class WechatController {
|
|||||||
$appId = 'wx3cf0f39249eb0e60';
|
$appId = 'wx3cf0f39249eb0e60';
|
||||||
$secret = 'f1c242f4f28f735d4687abb469072a29';
|
$secret = 'f1c242f4f28f735d4687abb469072a29';
|
||||||
|
|
||||||
$menu = new Menu($appId, $secret);
|
$menuService = new Menu($appId, $secret);
|
||||||
|
|
||||||
$menus = Input::get('menus'); // menus 是你自己后台管理中心表单post过来的一个数组
|
$menus = Input::get('menus'); // menus 是你自己后台管理中心表单post过来的一个数组
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class WechatController {
|
|||||||
$target[] = $item;
|
$target[] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu->set($target); // 失败会抛出异常
|
$menuService->set($target); // 失败会抛出异常
|
||||||
|
|
||||||
return Redirect::back()->withMessage('菜单设置成功!');
|
return Redirect::back()->withMessage('菜单设置成功!');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user