全面升级:WeChat 3.9.5.81 + 全尺寸图片 OCR + 启动脚本

This commit is contained in:
hmo
2026-05-21 01:31:31 +08:00
parent 4296af615f
commit 1593105a4a
9 changed files with 634 additions and 54 deletions
+44 -27
View File
@@ -11,7 +11,7 @@ Windows 微信机器人 ↔ Linux Hermes AI,全自动双向聊天。
│ Windows 192.168.0.111 │
│ │
│ ┌──────────────────┐ ┌───────────────────────────┐ │
│ │ 微信 3.9.10.19 x64 │ │ 日常微信 WeChatAppEx 4.x │ │
│ │ 微信 3.9.5.81 x64 │ │ 日常微信 WeChatAppEx 4.x │ │
│ │ 机器人号 modachen │ │ 老爸日常使用,互不干扰 │ │
│ │ wxhelper DLL 注入 │ └───────────────────────────┘ │
│ └────────┬─────────┘ │
@@ -23,6 +23,8 @@ Windows 微信机器人 ↔ Linux Hermes AI,全自动双向聊天。
│ │ → POST Hermes API :8642 │ ← sisyphus session │
│ │ ← 收回复 → wxhelper 发 │ │
│ │ HTTP :19088 收发消息 │ │
│ │ 图片:downloadAttach │ ← 全尺寸原图 CDN 下载 │
│ │ 图片:decodeImage │ ← 解密 .dat → OCR 识别 │
│ │ 看门狗自愈 │ │
│ └────────┬────────────────┘ │
└───────────┼─────────────────────────────────────────────────┘
@@ -92,13 +94,16 @@ Windows 微信机器人 ↔ Linux Hermes AI,全自动双向聊天。
→ 老爸手机收到
```
### 图片消息
### 图片消息(全尺寸 OCR
```
老爸发图片
→ WeChat 收到 → wxhelper 图片事件
→ wechat_agent.py 保存图片 → 调豆包OCR (VolcEngine)
OCR 文字结果 + 通知 → POST Hermes API
→ WeChat 收到 → wxhelper TCP 推送 (type=3, 含 msgId)
→ wechat_agent.py 提取 msgId
downloadAttach API → 从 CDN 下载 1.4MB+ 全尺寸原图
→ decodeImage API → 解密 .dat 加密文件 → JPEG
→ VolcEngine doubao-seed-code OCR → 完整文字提取
→ OCR 结果 → POST Hermes API
→ Hermes 知道图片内容 → 回复老爸
```
@@ -130,9 +135,11 @@ Hermes → POST http://192.168.0.111:5801/hermes-msg
## 组件
### Windows 端(wechat_agent.py v2
- **wxhelper DLL 注入** — ttttupup/wxhelper 3.9.10.19 x64
- **wxhelper DLL 注入** — ttttupup/wxhelper 3.9.5.81 (官方 DLL, Injector_x64.exe 注入)
- **TCP 接收消息** — :19099 收微信事件
- **HTTP 发送消息** — :19088 wxhelper API
- **全尺寸图片 OCR** — downloadAttach (CDN下载) + decodeImage (.dat解密) → VolcEngine OCR
- **空白响应过滤** — 空/白字符响应自动跳过,不发到微信群
- **Hermes API 调用** — 直接 POST :8642session 固定 `sisyphus`
- **回复服务** — 5801 端口收 Hermes 消息
- **看门狗** — 120s 无消息刷新 webhookAPI 挂了才重注入 DLL
@@ -148,20 +155,14 @@ Hermes → POST http://192.168.0.111:5801/hermes-msg
### Windows
```batch
cd D:\F\NewI\opencode\daily-workspace\projects\wechat-hermes-gateway
scripts\start_bridge.bat
```
或直接:
使用 Python 3.10Miniconda3 Python 3.13 的 encodings 模块损坏):
```powershell
$env:PYTHONHOME=''
Start-Process -WindowStyle Hidden python.exe scripts\wechat_agent.py
cd D:\F\NewI\opencode\daily-workspace\projects\wechat-hermes-gateway
$python = "C:\Users\hmo\AppData\Local\Programs\Python\Python310\python.exe"
Start-Process -WindowStyle Hidden -FilePath $python -ArgumentList "scripts\wechat_agent.py"
```
启动后需用修复过低工具扫码登录微信。
### Linux(如重启后)
```bash
@@ -192,11 +193,20 @@ wechat-hermes-gateway/
│ └── history_api.py # History REST API :19001
├── scripts/
│ ├── wechat_agent.py # 主力:微信机器人代理
── start_bridge.bat # 微信桥接一键启动
│ ├── start_history_api.bat # History API 一键启动
│ ├── moho_view.py # 莫荷聊天记录查看器
── moho_chat.py # 莫荷聊天查看器(备选)
└── temp/ # 废弃/临时脚本
── start_history_api.bat # History API 一键启动
├── tools/
│ ├── Injector_x64.exe # DLL 注入器 (3.9.5.81)
── wxhelper_official_39581.dll # 官方 wxhelper 3.9.5.81 DLL
│ ├── WeChatSetup-3.9.5.81.exe # 微信 3.9.5.81 安装包
│ ├── ConsoleApplication.exe # 旧注入器 (3.9.10.19 备份)
│ └── wxhelper_391019.dll # 旧 DLL 备份
├── docs/
│ ├── 通用架构-WeChat opencode 桥接.md
│ ├── 老莫消息路由设计.md
│ └── assets/
│ └── architecture.png
├── logs/ # 运行时日志
└── temp/ # 临时文件 (OCR 解码图等)
```
## History REST API (:19001)
@@ -345,6 +355,9 @@ curl -X POST http://localhost:19001/api/history -H "Content-Type: application/js
4. **session 自动重置** → 关闭 api_server 平台的重置策略
5. **群聊不认人** → session 固定 `sisyphus`,所有消息共享上下文
6. **Linux bridge 常挂** → 去掉 bridge.pyWindows 直接调 Hermes API
7. **3.9.10.19-v1 图片 API 不全** → 降级到 3.9.5.81,获得 downloadAttach + decodeImage 支持
8. **ConsoleApplication.exe 注入器不兼容** → 改用 Injector_x64.exe(参数 `-n WeChat.exe -i dll_path`
9. **缩略图 OCR 瞎编** → 全尺寸 downloadAttach → decodeImage → OCR1.4MB 原图识别 1376 字符
## 已实现的功能
@@ -352,14 +365,15 @@ curl -X POST http://localhost:19001/api/history -H "Content-Type: application/js
|------|------|
| 文字消息收发(个人聊天) | ✅ 双向,session 上下文连贯 |
| 文字消息收发(群聊) | ✅ 同 session,认识老爸 |
| 图片接收 + OCR 分析 | ✅ 自动 OCR → 结果给莫荷 |
| 图片接收 + 全尺寸 OCR | ✅ downloadAttach → decodeImage → 1.4MB 原图 → 豆包OCR |
| 发送网上图片 | ✅ [IMG]URL[/IMG] 标记,Bot.send_image 发出 |
| 图像生成 (SenseNova商汤) | ✅ [IMG]generate:描述[/IMG] 支持多种比例 |
| 图像理解/OCR | ✅ 豆包OCR + SenseNova 双引擎 |
| 图像理解/OCR | ✅ 豆包 doubao-seed-code + 全尺寸原图,1376 字符实测通过 |
| 空白响应过滤 | ✅ 空/白字符响应自动跳过,不发微信群 |
| Hermes 身份认知 | ✅ 知道自己是莫荷/莫小荷,知道老爸 |
| 会话上下文持续 | ✅ session `sisyphus`,自动重置已关闭 |
| 小小莫 ↔ Hermes 双向通信 | ✅ API (:8642) + HTTP (:5801/hermes-msg) |
| 看门狗自愈 | ✅ 120s 无消息刷新 webhook |
| 看门狗自愈 | ✅ 120s 无消息刷新 webhookAPI 挂了自动重注入 DLL |
| 昵称识别 | ✅ 从 getContactList 获取 |
| 联系人列表查询 | ✅ wxhelper /api/getContactList |
| 历史聊天记录查询 | ✅ [HISTORY:wxid:count] 标签 → MSG0.db SQL |
@@ -386,10 +400,10 @@ curl -X POST http://localhost:19001/api/history -H "Content-Type: application/js
→ 启动 opencode serve:4096,莫荷连接用)
→ 启动后台守护(自动清理僵尸连接)
2. 打开经典微信 3.9.10.19
2. 打开经典微信 3.9.5.81(用修复过低工具扫码登录)
→ 扫码登录机器人号 modachenchen
3. wechat_agent.py 在登录后自动注入 DLL
3. wechat_agent.py 在登录后自动注入 wxhelper_official_39581.dll
→ 自动开始转发消息
→ 日志在 projects/wechat-hermes-gateway/logs/
```
@@ -435,9 +449,12 @@ curl http://192.168.0.103:8642/v1/models -H "Authorization: Bearer hermes123"
## 注意事项
- wxhelper DLL 支持 3.9.10.19 x64 微信
- wxhelper DLL 支持 3.9.5.81 x64 微信(使用 `wxhelper_official_39581.dll`
- 注入器:使用 `Injector_x64.exe`(参数:`-n WeChat.exe -i dll_path`),不再是 ConsoleApplication.exe
- 每次 WeChat 重启需重新登录
- 启动顺序:先开微信 → agent 自动注入 DLL
- Hermes API 首次调用可能较慢(大模型冷启动)
- 看门狗每 120s 刷新 webhookAPI 挂了自动重注入
- Python 请用 Python 3.10Miniconda3 3.13 的 encodings 模块损坏)
- 全尺寸图片 OCR:依赖 `downloadAttach` + `decodeImage` API,仅 3.9.5.81+ 支持
- 如果微信登录后没反应,等 1-2 分钟看门狗会自动处理