在版本 v2.0 , Vbot 支持 API 以便開發者搭建自己的微信網頁客戶端,要開啟 API 功能,必須安裝?[swoole](http://www.swoole.com/)
### 配置
這里 IP 可以自行設置,例如如果你有公網IP ,這里可以設置公網IP
```
return [
// ...
'swoole' => [
'status' => true,
'ip' => '127.0.0.1',
'port' => '8866',
],
```
### API
API 的格式均為 post json 到?[http://ip:port](http://ip:port/), 如上配置即是?[http://127.0.0.1:8866](http://127.0.0.1:8866/)
json 格式均為
```
[
'action' => $action,
'params' => []
]
```
action 為 API 操作,當前僅支持 send 和 search
#### send API
##### params 參數
* type 發送類型,與消息的 type 相同
* username 發送對象
* content send()后面的參數,如果需要多個參數可逗號分隔
##### 發送文字
```
{"action":"send", "params": {"type":"text","username": "@@5e200a8c6e4fefcc7e5f86ebf6b585c85bb8dd066c32a3b28b4b5cf49cb5d6e5", "content":"hi, this is from api"}}
```
##### 發送名片
```
{"action":"send", "params": {"type":"card","username": "@@5e200a8c6e4fefcc7e5f86ebf6b585c85bb8dd066c32a3b28b4b5cf49cb5d6e5", "content":"hanson1994,API 測試"}}
```
等等。。。
#### search API
查詢 API 可直接操作聯系人所包含的方法
##### params 參數
* type 查詢的對象,可選 friends/groups/members/specials/officials
* method 執行方法
* filter 方法的參數(必須按順序)
##### getObject
```
{"action":"search","params":{"type":"friends", "method": "getObject","filter":["HanSon","NickName",false,true]}}
```