切换主题
接收附件网关
适用于读取当前微信账号已经落地的普通文件附件。独立 Python 网关默认监听 127.0.0.1:14217。从仓库根目录启动,使用相同的本机 Bearer 凭据。
powershell
python -B tools/receive_files.py --account-dir 'D:\WeChatData\xwechat_files\example_account'账号目录内应有 msg/file。--port 可覆盖监听端口。网关从仓库根的 api_v2_42013.json 读取主 Hook 的端口和 token。查找文件时要求文件名、大小和 MD5 均匹配。适用大小为 1 B–20 MiB。
附件列表
GET /v2/received-files 无参数。先读取列表建立索引,再取其中的 file_id 调用状态或内容接口。
data 字段 | 说明 |
|---|---|
items | 当前索引条目,最多 512 条。 |
session、gap | 当前主服务事件会话及是否观测到事件缺口。 |
native_download | 固定为 false,当前只读取已落地文件。 |
items[] 字段 | 说明 |
|---|---|
file_id | 网关生成的 32 位十六进制标识。 |
filename、size_bytes、media_type、md5 | 文件名、字节数、按扩展名推断的 MIME 类型和消息记录中的 MD5。 |
message_id、sender_id、conversation_id | 微信消息 ID、发件人和会话。 |
available、status | 索引尚未验证磁盘时分别为 null 和 check_on_download。 |
download_url | 本机下载 URL,需要相同的鉴权头。 |
文件状态
GET /v2/received-files/{file_id},也可用 GET /v2/received-files/{file_id}/status。输入为列表中的 ID。响应有 file_id、filename、size_bytes、available、status。
状态 ready 表示校验匹配。not_downloaded_or_not_matched 表示未找到匹配文件。missing_checksum 表示缺 MD5。unsupported_size 表示超出大小限制。search_limit 表示目录扫描达上限。
读取内容
GET /v2/received-files/{file_id}/content。成功为 HTTP 200 原始字节流,响应含 Content-Type: application/octet-stream、Content-Length、带 UTF-8 文件名的 Content-Disposition。ID 未知返回 404。文件不可用或校验变化返回 409 action_unavailable。重启会话后可重新查询索引。
powershell
$gateway = 'http://127.0.0.1:14217'
$list = Invoke-RestMethod "$gateway/v2/received-files" -Headers $headers
$file = $list.data.items | Where-Object filename -eq 'example.txt' | Select-Object -First 1
if ($file) {
$state = Invoke-RestMethod "$gateway/v2/received-files/$($file.file_id)" -Headers $headers
if ($state.data.available) {
Invoke-WebRequest $file.download_url -Headers $headers -OutFile '.\received.txt'
}
}以上 $headers 来自 实例配置示例。