时间:2026-03-23 17:07
人气:
作者:admin

最近在搭建个人 AI 助手时,发现 OpenClaw 这个强大的开源框架,折腾两天终于把微信成功接入。本文将完整记录 Windows 环境下的配置过程,帮你避开我踩过的坑。
OpenClaw 是一个开源的 AI 代理框架,可以理解为一个「机器人中间件」。它的核心能力包括:
- 多通道支持:微信、飞书、Discord、Telegram、Slack 等
- AI 集成:OpenAI、Anthropic、Gemini 及本地模型
- 插件系统:丰富的官方和社区插件
- Web 管理:可视化配置和监控面板
- 技能系统:可扩展的自定义能力
官网:https://openclaw.ai
GitHub:https://github.com/openclaw/openclaw
1. 系统要求
- 操作系统:Windows 10/11(本文以 Windows 11 为例)
- Node.js:22.16+ 或 24.x(推荐 LTS 版本)
- 微信账号:一个可以扫码登录的微信号(建议用小号)
2. 安装 Node.js
访问 Node.js 官网 https://nodejs.org 下载 LTS 版本安装。
安装完成后,打开 PowerShell 验证:
node --version
npm --version
正常输出示例:
v22.14.0
10.9.2
1. 全局安装
打开 PowerShell(建议以管理员身份),执行:
npm install -g openclaw
如果网络较慢,可以使用淘宝镜像:
npm install -g openclaw --registry=https://registry.npmmirror.com
2. 验证安装
openclaw --version
成功输出示例:
OpenClaw 2026.3.11 (29dc654)
3. 初始化配置
运行 onboarding 完成基础配置:
openclaw onboard --install-daemon
这一步会:
- 创建配置目录 C:\Users\你的用户名\.openclaw\
- 设置 Gateway 为系统服务(开机自启)
- 引导配置 AI 模型(可以暂时跳过)
4. 检查 Gateway 状态
openclaw gateway status
正常输出应包含:
- Service: Scheduled Task (registered)
- RPC probe: ok
- Listening: 127.0.0.1:18789
1. 安装插件包
npm install -g @tencent-weixin/openclaw-weixin-cli
输出示例:
added 1 package in 545ms
2. Windows 用户必看:修复检测脚本
插件的检测逻辑使用了 Linux/Mac 的 which 命令,在 Windows 上会失败,需要手动修改源码。
第一步:进入插件目录
cd C:\Users\你的用户名\AppData\Roaming\npm\node_modules\@tencent-weixin\openclaw-weixin-cli
第二步:编辑 cli.mjs 文件
notepad cli.mjs
第三步:找到 which 函数(大约在第 30 行附近)
原代码:
function which(bin) {
try {
return execSync(`which ${bin}`, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
} catch {
return null;
}
}
修改为:
function which(bin) {
try {
// Windows 使用 where 命令,Unix/Linux/Mac 使用 which 命令
const cmd = process.platform === 'win32' ? `where ${bin}` : `which ${bin}`;
return execSync(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
} catch {
return null;
}
}
第四步:保存并关闭记事本。
3. 运行安装向导
weixin-installer install
安装过程会自动执行:
- 检测 OpenClaw 环境
- 安装微信插件到 OpenClaw
- 显示二维码(用微信扫码登录)
- 重启 Gateway
成功输出示例:
[openclaw-weixin] 已找到本地安装的 openclaw
[openclaw-weixin] 正在安装插件...
[openclaw-weixin] 插件就绪,开始首次连接...
✅ 与微信连接成功!
1. 查看插件状态
openclaw plugins list | findstr weixin
正常输出:
Weixin 插件状态为 loaded
2. 查看通道状态
openclaw channels status --probe
微信通道应显示:
openclaw-weixin: enabled, configured, running
3. 实时查看对话日志
openclaw logs --follow
向微信机器人发送一条消息(如「你好」),日志中应出现:
[weixin] Received message from 用户名: 你好
[agent] Processing...
[weixin] Sending reply: 你好!我是 OpenClaw 机器人
按 Ctrl+C 退出日志查看。
4. 访问 Web 管理界面
浏览器打开:http://127.0.0.1:18789
可以看到 Gateway 状态、通道列表、会话记录等。
问题1:插件检测不到 openclaw
错误信息:[openclaw-weixin] 未找到 openclaw,请先安装
原因:Windows 没有 which 命令
解决方案:按本文第四节第2步修改插件源码。
问题2:Gateway 端口被占用
错误信息:Gateway failed to start: another gateway instance is already listening
原因:已有 Gateway 实例在运行
解决方案:
openclaw gateway stop
openclaw gateway start
问题3:微信收不到回复
排查步骤:
- 检查微信登录状态:openclaw channels login --channel openclaw-weixin,重新扫码登录
- 查看详细日志:openclaw logs --follow --level debug
- 检查 AI 模型配置:openclaw configure --section model
- 确认网络连接:openclaw doctor
问题4:看不到消息具体内容
现象:日志只显示警告,看不到收发消息
解决方案:
openclaw config set logging.level debug
openclaw gateway restart
openclaw logs --follow
1. 配置 AI 模型
编辑配置文件 C:\Users\你的用户名\.openclaw\config.json:
{
"models": {
"default": "gpt-4o-mini",
"providers": {
"openai": {
"apiKey": "sk-xxxxxxxxxxxxx",
"baseURL": "https://api.openai.com/v1"
}
}
},
"agents": {
"main": {
"model": "gpt-4o-mini",
"systemPrompt": "你是一个友好的微信助手"
}
}
}
2. 禁用插件加载提示
openclaw config set plugins.allow ["openclaw-weixin"]
3. 设置 Gateway 开机自启
openclaw gateway start --daemon
4. 查看所有配置
openclaw config list