微信通道插件是 OpenClaw 连接个人微信的通道插件(不是企业微信 WeCom)。 支持通过扫码完成登录授权,在微信里直接与 Agent 对话。
- 插件名:@tencent-weixin/openclaw-weixin
2.4.4>=2026.3.22/root/.openclaw/extensions/openclaw-weixin//root/.openclaw/openclaw-weixin/openclaw plugins install "@tencent-weixin/openclaw-weixin"openclaw config set plugins.entries.openclaw-weixin.enabled true
openclaw config set channels.openclaw-weixin.type "weixin"
openclaw config set channels.openclaw-weixin.label "微信"
openclaw channels login --channel openclaw-weixin 会:
1. 先启动整个 gateway + 加载所有插件(耗时 1-2 分钟)
2. 再生成二维码
3. 导致二维码生成时已过期一半时间cd /root/.openclaw/agents/101/workspace && node weixin-login.mjs
这个脚本:
1. 直接调用插件源码的 startWeixinLoginWithQr() 生成二维码(5 秒内)
2. 显示二维码和链接
3. 调用 waitForWeixinLogin() 轮询等待扫码确认
4. 扫码成功后,自动保存正确的 botToken 到插件数据目录
5. 触发 gateway 配置重载
openclaw gateway restart
waitForWeixinLogin() 返回的两个字段一定要区分:
accountId — 账号标识(例如 701556aaef02@im.bot),不是 tokenbotToken — 微信服务器返回的真正令牌(较长字符串),这个才是 token保存凭据的正确代码:
import { saveWeixinAccount, registerWeixinAccountId } from '...accounts.js';saveWeixinAccount(accountId, {
token: waitResult.botToken, // ✅ 正确的 token
baseUrl: waitResult.baseUrl,
userId: waitResult.userId,
});
registerWeixinAccountId(accountId);
错误例子(会导致 errcode -14 session expired):
saveWeixinAccount(accountId, {
token: accountId, // ❌ 错的!accountId 不是 token
});
/root/.openclaw/agents/101/workspace/weixin-login.mjs包含完整的:生成二维码 → 显示 → 等待扫码 → 保存凭据 → 触发重载 流程。
插件保存账号数据到 ~/.openclaw/openclaw-weixin/accounts/ 目录:
accounts.json — 账号索引列表accounts/{accountId}.json — 每个账号的 token/baseUrl/userIdaccounts/{accountId}-im-bot.sync.json — 消息同步缓冲区查看 gateway 日志:
tail -f /tmp/openclaw/openclaw-2026-05-27.log | grep -i "weixin"
正常状态会看到:
weixin monitor started (https://ilinkai.weixin.qq.com, account=xxx)
inbound: from=...@im.wechat bodyLen=xxx
outbound: text sent OK to=...@im.wechat
错误状态:
session expired (errcode -14) — token 写入错误,需重新扫码