菜單
讀取(查詢)已設置菜單
$list = $officialAccount->menu->query();
獲取當前菜單
$current = $officialAccount->menu->queryConfig();
添加菜單
添加普通菜單
<?php
$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"
],
],
],
];
$officialAccount->menu->create($buttons);
以上將會創(chuàng)建一個普通菜單。
添加個性化菜單
與創(chuàng)建普通菜單不同的是,需要在 create()
方法中將個性化匹配規(guī)則作為第二個參數(shù)傳進去:
<?php
$matchRule = [
"matchrule" => [
"tag_id" => "2",
"sex" => "1",
"country" => "中國",
"province" => "廣東",
"city" => "廣州",
"client_platform_type" => "2",
"language" => "zh_CN"
],
];
$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"
],
],
],
];
$officialAccount->menu->create($buttons, $matchRule);
刪除菜單
有兩種刪除方式,一種是全部刪除,另外一種是根據(jù)菜單 ID
來刪除(刪除個性化菜單時用,ID
從查詢接口獲取):
// 刪除全部
$officialAccount->menu->delete();
刪除個性化菜單
$officialAccount->menu->delconditional($menuId);
測試個性化菜單
$officialAccount->menu->match($userId);
$userId
可以是粉絲的 OpenID
,也可以是粉絲的微信號。
返回 $menu
與指定的 $userId
匹配的菜單項。