mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
支持appimage,添加安装脚本,更新文档
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# WeFlow HTTP API / Push 文档
|
||||
|
||||
WeFlow 提供本地 HTTP API,便于外部脚本或工具读取聊天记录、会话、联系人、群成员和导出的媒体文件;也支持在检测到新消息后通过固定 SSE 地址主动推送消息事件。
|
||||
WeFlow 提供本地 HTTP API(已支持GET 和 POST请求),便于外部脚本或工具读取聊天记录、会话、联系人、群成员和导出的媒体文件;也支持在检测到新消息后通过固定 SSE 地址主动推送消息事件。
|
||||
|
||||
## 启用方式
|
||||
|
||||
@@ -11,17 +11,27 @@ WeFlow 提供本地 HTTP API,便于外部脚本或工具读取聊天记录、
|
||||
- 基础地址:`http://127.0.0.1:5031`
|
||||
- 可选开启 `主动推送`,检测到新收到的消息后会通过 `GET /api/v1/push/messages` 推送给 SSE 订阅端
|
||||
|
||||
**状态记忆**:API 服务和主动推送的状态及端口会自动保存,重启 WeFlow 后会自动恢复运行。
|
||||
|
||||
## 鉴权规范
|
||||
|
||||
**鉴权规范 (Access Token)** 除健康检查接口外,所有 `/api/v1/*` 接口均受 Token 保护。支持三种传参方式(任选其一):
|
||||
|
||||
1. **HTTP Header (推荐)**: `Authorization: Bearer <您的Token>`
|
||||
2. **Query 参数**: `?access_token=<您的Token>`(SSE 长连接推荐此方式)
|
||||
3. **JSON Body**: `{"access_token": "<您的Token>"}`(仅限 POST 请求)
|
||||
|
||||
## 接口列表
|
||||
|
||||
- `GET /health`
|
||||
- `GET /api/v1/health`
|
||||
- `GET /api/v1/push/messages`
|
||||
- `GET /api/v1/messages`
|
||||
- `GET /api/v1/messages/new`
|
||||
- `GET /api/v1/sessions`
|
||||
- `GET /api/v1/contacts`
|
||||
- `GET /api/v1/group-members`
|
||||
- `GET /api/v1/media/*`
|
||||
- `GET|POST /health`
|
||||
- `GET|POST /api/v1/health`
|
||||
- `GET|POST /api/v1/push/messages`
|
||||
- `GET|POST /api/v1/messages`
|
||||
- `GET|POST /api/v1/messages/new`
|
||||
- `GET|POST /api/v1/sessions`
|
||||
- `GET|POST /api/v1/contacts`
|
||||
- `GET|POST /api/v1/group-members`
|
||||
- `GET|POST /api/v1/media/*`
|
||||
|
||||
---
|
||||
|
||||
@@ -80,7 +90,7 @@ GET /api/v1/push/messages
|
||||
### 示例
|
||||
|
||||
```bash
|
||||
curl -N "http://127.0.0.1:5031/api/v1/push/messages"
|
||||
curl -N "http://127.0.0.1:5031/api/v1/push/messages?access_token=YOUR_TOKEN
|
||||
```
|
||||
|
||||
示例事件:
|
||||
@@ -94,6 +104,8 @@ data: {"event":"message.new","sessionId":"xxx@chatroom","messageKey":"server:123
|
||||
|
||||
## 3. 获取消息
|
||||
|
||||
> 当使用 POST 时,请将参数放在 JSON Body 中(Content-Type: application/json)
|
||||
|
||||
读取指定会话的消息,支持原始 JSON 和 ChatLab 格式。
|
||||
|
||||
**请求**
|
||||
@@ -231,6 +243,8 @@ curl "http://127.0.0.1:5031/api/v1/messages?talker=xxx@chatroom&media=1&image=1&
|
||||
|
||||
## 4. 获取会话列表
|
||||
|
||||
> 当使用 POST 时,请将参数放在 JSON Body 中(Content-Type: application/json)
|
||||
|
||||
**请求**
|
||||
|
||||
```http
|
||||
@@ -276,6 +290,8 @@ GET /api/v1/sessions
|
||||
|
||||
## 5. 获取联系人列表
|
||||
|
||||
> 当使用 POST 时,请将参数放在 JSON Body 中(Content-Type: application/json)
|
||||
|
||||
**请求**
|
||||
|
||||
```http
|
||||
@@ -325,6 +341,8 @@ GET /api/v1/contacts
|
||||
|
||||
## 6. 获取群成员列表
|
||||
|
||||
> 当使用 POST 时,请将参数放在 JSON Body 中(Content-Type: application/json)
|
||||
|
||||
返回群成员的 `wxid`、群昵称、备注、微信号等信息。
|
||||
|
||||
**请求**
|
||||
@@ -417,6 +435,8 @@ curl "http://127.0.0.1:5031/api/v1/group-members?chatroomId=xxx@chatroom&include
|
||||
|
||||
## 7. 访问导出媒体
|
||||
|
||||
> 当使用 POST 时,请将参数放在 JSON Body 中(Content-Type: application/json)
|
||||
|
||||
通过消息接口启用 `media=1` 后,接口会先把图片、语音、视频、表情导出到本地缓存目录,再返回可访问的 HTTP 地址。
|
||||
|
||||
**请求**
|
||||
@@ -461,19 +481,23 @@ curl "http://127.0.0.1:5031/api/v1/media/xxx@chatroom/emojis/emoji_300.gif"
|
||||
### PowerShell
|
||||
|
||||
```powershell
|
||||
Invoke-RestMethod http://127.0.0.1:5031/health
|
||||
Invoke-RestMethod http://127.0.0.1:5031/api/v1/sessions
|
||||
Invoke-RestMethod "http://127.0.0.1:5031/api/v1/messages?talker=wxid_xxx&limit=10"
|
||||
Invoke-RestMethod "http://127.0.0.1:5031/api/v1/group-members?chatroomId=xxx@chatroom&includeMessageCounts=1"
|
||||
$headers = @{ "Authorization" = "Bearer YOUR_TOKEN" }
|
||||
$body = @{ talker = "wxid_xxx"; limit = 10 } | ConvertTo-Json
|
||||
|
||||
Invoke-RestMethod -Uri "http://127.0.0.1:5031/api/v1/messages" -Method POST -Headers $headers -Body $body -ContentType "application/json"
|
||||
```
|
||||
|
||||
### cURL
|
||||
|
||||
```bash
|
||||
curl http://127.0.0.1:5031/health
|
||||
curl "http://127.0.0.1:5031/api/v1/messages?talker=wxid_xxx&chatlab=1"
|
||||
curl "http://127.0.0.1:5031/api/v1/contacts?keyword=张三"
|
||||
curl "http://127.0.0.1:5031/api/v1/group-members?chatroomId=xxx@chatroom"
|
||||
# GET 带 Token Header
|
||||
curl -H "Authorization: Bearer YOUR_TOKEN" "http://127.0.0.1:5031/api/v1/messages?talker=wxid_xxx"
|
||||
|
||||
# POST 带 JSON Body
|
||||
curl -X POST http://127.0.0.1:5031/api/v1/messages \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"talker": "xxx@chatroom", "chatlab": true}'
|
||||
```
|
||||
|
||||
### Python
|
||||
@@ -482,19 +506,21 @@ curl "http://127.0.0.1:5031/api/v1/group-members?chatroomId=xxx@chatroom"
|
||||
import requests
|
||||
|
||||
BASE_URL = "http://127.0.0.1:5031"
|
||||
headers = {"Authorization": "Bearer YOUR_TOKEN", "Content-Type": "application/json"}
|
||||
|
||||
messages = requests.get(
|
||||
f"{BASE_URL}/api/v1/messages",
|
||||
params={"talker": "xxx@chatroom", "limit": 50}
|
||||
# POST 方式获取消息
|
||||
messages = requests.post(
|
||||
f"{BASE_URL}/api/v1/messages",
|
||||
json={"talker": "xxx@chatroom", "limit": 50},
|
||||
headers=headers
|
||||
).json()
|
||||
|
||||
# GET 方式获取群成员
|
||||
members = requests.get(
|
||||
f"{BASE_URL}/api/v1/group-members",
|
||||
params={"chatroomId": "xxx@chatroom", "includeMessageCounts": 1}
|
||||
params={"chatroomId": "xxx@chatroom", "includeMessageCounts": 1},
|
||||
headers=headers
|
||||
).json()
|
||||
|
||||
print(messages)
|
||||
print(members)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user