Files
weixin-plugin-test/README.md
zyh 77019ec050 feat: 初始化微信插件独立测试环境
添加完整的微信插件测试框架,包含:
- 微信插件源码(weixin-plugin/)
- TypeScript 类型定义(types.ts)
- 插件编译脚本(scripts/build-weixin-plugin.sh)
- 简化测试脚本(scripts/test-weixin-simple.js)
- 完整测试脚本(scripts/test-weixin-plugin.js)
- 项目配置和依赖管理(package.json)
- 使用说明文档(README.md)

主要功能:
- 支持二维码登录认证
- HTTP 长轮询消息接收
- 文本、图片、视频、文件消息收发
- 自动回复测试
- 运行状态统计

Generated with [Claude Code](https://claude.com/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-03-30 07:14:00 +00:00

180 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 微信插件独立测试环境
这是一个独立的测试环境,用于验证微信插件 (`weixin-plugin/`) 的功能。
## 目录结构
```
weixin-plugin-test/
├── package.json # 项目配置和依赖
├── weixin-plugin/ # 微信插件源码
│ ├── types.ts # 类型定义
│ ├── weixinGateway.ts # 网关入口
│ ├── weixin/ # 核心实现
│ └── dist/ # 编译输出(运行 build 后生成)
├── scripts/ # 测试脚本
│ ├── build-weixin-plugin.sh # 编译脚本
│ ├── test-weixin-simple.js # 简化测试
│ └── test-weixin-plugin.js # 完整测试
└── README.md # 本文档
```
## 快速开始
### 1. 安装依赖
```bash
cd /root/weixin-plugin-test
npm install
```
### 2. 编译插件
```bash
npm run build
```
### 3. 运行测试
**简化测试(推荐先运行):**
```bash
npm run test:simple
```
**完整测试(包含消息监听和自动回复):**
```bash
npm run test:full
```
## 可用命令
| 命令 | 说明 |
|------|------|
| `npm install` | 安装所有依赖 |
| `npm run build` | 编译微信插件 |
| `npm run test:simple` | 运行简化测试 |
| `npm run test:full` | 运行完整测试 |
| `npm run clean` | 清理编译文件 |
## 测试内容
### 简化测试 (test:simple)
1. ✓ 检查依赖qrcode 等)
2. ✓ 加载微信插件模块
3. ✓ 获取登录二维码
4. ✓ 等待扫码登录
5. ✓ 启动网关
6. ✓ 验证连接状态
7. ✓ 停止网关
### 完整测试 (test:full)
包含简化测试的所有内容,额外提供:
- 持续监听消息
- 自动回复收到的消息
- 显示运行统计信息
- 按 Ctrl+C 退出
## 使用流程
1. **安装依赖**
```bash
npm install
```
2. **编译插件**
```bash
npm run build
```
3. **运行测试**
```bash
npm run test:simple
```
4. **扫码登录**
- 二维码会保存到 `weixin-qrcode.png`
- 使用微信扫描二维码
- 在手机上确认登录
5. **查看结果**
- 测试通过会显示成功消息
- 可以看到账号信息和连接状态
## 故障排除
### 编译失败
```bash
# 清理后重新编译
npm run clean
npm run build
```
### 模块加载失败
确保已运行编译脚本:
```bash
npm run build
```
### 二维码登录超时
- 检查网络连接
- 确保能访问 `ilinkai.weixin.qq.com`
- 重新运行测试
## 依赖说明
### 生产依赖
- `qrcode` - 二维码生成
### 开发依赖
- `@types/qrcode` - qrcode 类型定义
- `typescript` - TypeScript 编译器
## 数据存储
登录后的账号信息保存在:
```
~/.openclaw/openclaw-weixin/accounts/
├── registered-accounts.json # 账号注册表
└── {accountId}.json # 账号数据token 等)
```
## 清理数据
如需清理测试账号数据:
```bash
# 删除所有测试账号
rm -rf ~/.openclaw/openclaw-weixin/
# 或手动删除特定账号
rm ~/.openclaw/openclaw-weixin/accounts/test-account.json
```
## 注意事项
1. **编译要求**:修改源码后需要重新编译
2. **网络要求**:需要访问 `ilinkai.weixin.qq.com`
3. **二维码有效期**5 分钟,过期后会自动刷新(最多 3 次)
4. **自动化限制**:需要手动扫码登录,无法完全自动化
## 下一步
测试通过后,可以:
1. 将插件集成到主项目
2. 开发自定义消息处理逻辑
3. 添加更多功能(群聊、媒体消息等)
---
**最后更新:** 2026-03-30