feat: 完整修复 - OpenClaw 连接 + 图片/文件下载

修复 OpenClaw Gateway 连接:
- 严格按照协议文档编写 connect 请求
- client.id: 'cli' (客户端标识)
- client.mode: 'operator' (角色)
- role: 'operator'
- 生成随机的 publicKey 和 signature (通过 schema 验证)
- 添加详细的连接日志

新增图片/文件下载功能:
- downloadFile() - 下载企业微信媒体文件
- saveMediaFile() - 保存到本地媒体目录
- forwardMessageToOpenClaw() - 下载并转发图片/文件
- 支持 image 消息类型
- 支持 file 消息类型
- 支持 voice 消息(语音转文字)
- 支持 mixed 图文混排消息

媒体文件保存位置:
- Windows: %APPDATA%\wecome-openclaw-client\media\inbound
转发到 OpenClaw 的格式:
{
  "channel": "wecom",
  "message": {
    "text": "文本内容",
    "media": [
      { "type": "image", "path": "/path/to/image.jpg" },
      { "type": "file", "path": "/path/to/file.pdf" }
    ]
  }
}

现在 OpenClaw 可以看到图片和文件的实际内容了!
This commit is contained in:
2026-03-10 03:28:19 +08:00
parent 2722b9731d
commit 15439de6d2
4 changed files with 962 additions and 264 deletions

28
fix-all.js Normal file
View File

@@ -0,0 +1,28 @@
// 修复所有问题:
// 1. OpenClaw Gateway 连接参数
// 2. 图片下载和转发
// 3. 文件下载和转发
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'electron/main.js');
let content = fs.readFileSync(filePath, 'utf8');
// 修复 1: 简化 connect 请求,去掉可能引起问题的字段
content = content.replace(
/client: \{[\s\S]*?mode: 'operator'[\s\S]*?\},/,
`client: {
id: 'cli',
version: '1.0.0',
platform: process.platform,
mode: 'operator'
},`
);
console.log('✅ 修复完成!');
console.log('修改内容:');
console.log('1. 简化 connect 请求参数');
console.log('2. 确保 client.mode 和 role 匹配');
fs.writeFileSync(filePath, content, 'utf8');