📄 weixin-channel-setup.md

← 返回目录

微信通道(@tencent-weixin/openclaw-weixin)配置方法

概述

微信通道插件是 OpenClaw 连接个人微信的通道插件(不是企业微信 WeCom)。 支持通过扫码完成登录授权,在微信里直接与 Agent 对话。

插件信息

- 插件名:@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. 导致二维码生成时已过期一半时间

✅ 正确做法(快速)

直接用 Node.js 调用插件的内部函数生成二维码,绕过 gateway 加载:

cd /root/.openclaw/agents/101/workspace && node weixin-login.mjs

这个脚本: 1. 直接调用插件源码的 startWeixinLoginWithQr() 生成二维码(5 秒内) 2. 显示二维码和链接 3. 调用 waitForWeixinLogin() 轮询等待扫码确认 4. 扫码成功后,自动保存正确的 botToken 到插件数据目录 5. 触发 gateway 配置重载

登录成功后

扫码登录完成后,必须重启 gateway 才能生效:

openclaw gateway restart

关键经验(2026-05-27 记录)

⚠️ token 写入错误的坑

waitForWeixinLogin() 返回的两个字段一定要区分:
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/ 目录:

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 写入错误,需重新扫码