微信个人号接入 Claude Code 完整指南(cc-connect + ilink)

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

本文记录通过 cc-connect 将微信个人号与 Claude Code Agent 打通的完整操作步骤,包括扫码登录、配置写入、权限限制和启动验证。


准备工作

环境要求

条件说明
cc-connect 已安装并可执行无需公网 IP,ilink 由云端提供
Claude Code Agent 已配置指向你的工作目录
微信手机端用于扫码完成 ilink 登录

理解 cc-connect 的工作模型

cc-connect 通过 config.toml 管理多个「项目(project)」,每个项目包含:

  • agent:底层执行引擎(如 claudecode),配置工作目录和运行模式
  • platforms:消息来源平台(如 feishuweixin),配置对应的认证信息

微信个人号通道底层使用腾讯 ilink 机器人 HTTP 网关,采用 getUpdates 长轮询 + sendMessage 下发的方式收发消息。


Step 1:查看现有配置

操作前先确认你的 config.toml 路径和现有结构。以下是一个已配置飞书平台的典型示例:

language = "zh"

[log]
level = "info"

[[projects]]
name = "justgotrip"

[projects.agent]
type = "claudecode"

[projects.agent.options]
work_dir = "/Users/terry/Downloads/szjz"
mode = "default"

[[projects.platforms]]
type = "feishu"

[projects.platforms.options]
app_id = "cli_xxxxxxxxxxxx"
app_secret = "xxxxxxxxxxxxxxxxxxxxxxxx"

此时只有飞书平台。目标是新增一个 eutopian 项目,挂载微信平台,并将 Claude Code 指向 /Users/terry/Downloads/code/eutopian


Step 2:扫码登录,自动写入 Token

微信接入需要通过 ilink 机器人网关获取 Bearer Token。cc-connect 提供了一条命令完成扫码+写入的全流程:

cc-connect weixin setup --project eutopian --config /path/to/config.toml

参数说明:

参数作用
--project eutopian目标项目名;若不存在会自动创建并挂上 weixin 平台
--config指定 config.toml 路径;不填则使用默认路径

执行后终端会:

  1. 打印 ASCII 二维码(同时输出可复制的 URL)
  2. 等待你用手机微信扫码并确认登录
  3. 扫码成功后,自动将 tokenbase_urlaccount_id 等写回 config.toml

扫码成功后,config.toml 会自动追加类似以下内容:

[[projects]]
name = "eutopian"

[projects.agent]
type = "claudecode"

[projects.agent.options]
work_dir = "/Users/terry/.cc-connect"   # 注意:此处需要手动修正
mode = "default"

[[projects.platforms]]
type = "weixin"

[projects.platforms.options]
token = "d36404f141ed@im.bot:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
base_url = "https://ilinkai.weixin.qq.com"
account_id = "d36404f141ed@im.bot"

⚠️ 注意:自动写入的 work_dir 默认为 cc-connect 自身目录,需要手动修正为你的实际项目路径。


Step 3:修正 work_dir

work_dir 改为你希望 Claude Code 实际工作的项目目录:

[projects.agent.options]
work_dir = "/Users/terry/Downloads/code/eutopian"   # ✅ 修正后
mode = "default"

直接编辑 config.toml 文件,找到 eutopian 项目下的 work_dir 行并替换即可。


Step 4:配置 allow_from 和 admin_from

启动 cc-connect 后默认不限制任何用户,日志会出现警告:

level=WARN msg="allow_from is not set — all users are permitted."
level=WARN msg="admin_from is not set — privileged commands are blocked."

生产环境强烈建议配置这两个字段。

如何获取你的微信用户 ID

启动 cc-connect 后,用微信给机器人发一条任意消息,日志中会出现:

level=INFO msg="message received" platform=weixin
  user=o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat
  session=weixin:dm:o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat

user 字段即为你的 ilink 用户 ID,格式为 xxxxx@im.wechat

写入配置

[projects.platforms.options]
token = "d36404f141ed@im.bot:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
base_url = "https://ilinkai.weixin.qq.com"
account_id = "d36404f141ed@im.bot"
allow_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat"   # 限制只允许此用户
admin_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat"   # 允许使用管理命令

字段说明:

字段说明
allow_from允许与机器人对话的用户 ID,多个用英文逗号分隔;"*" 表示不限制(不安全)
admin_from允许执行 /shell/show/dir/restart/upgrade 等特权命令的用户 ID

Step 5:完整 config.toml 示例

配置完成后,完整的 config.toml 结构如下:

language = "zh"

[log]
level = "info"

# ── 项目一:justgotrip(飞书)──────────────────────────────────
[[projects]]
name = "justgotrip"

[projects.agent]
type = "claudecode"

[projects.agent.options]
work_dir = "/Users/terry/Downloads/szjz"
mode = "default"

[[projects.platforms]]
type = "feishu"

[projects.platforms.options]
app_id = "cli_xxxxxxxxxxxx"
app_secret = "xxxxxxxxxxxxxxxxxxxxxxxx"

# ── 项目二:eutopian(微信)───────────────────────────────────
[[projects]]
name = "eutopian"

[projects.agent]
type = "claudecode"

[projects.agent.options]
work_dir = "/Users/terry/Downloads/code/eutopian"
mode = "default"

[[projects.platforms]]
type = "weixin"

[projects.platforms.options]
token = "d36404f141ed@im.bot:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
base_url = "https://ilinkai.weixin.qq.com"
account_id = "d36404f141ed@im.bot"
allow_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat"
admin_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat"

Step 6:启动 cc-connect

cc-connect start --config /path/to/config.toml

正常启动日志应包含:

level=INFO msg="platform ready" project=justgotrip platform=feishu
level=INFO msg="engine started" project=justgotrip agent=claudecode platforms=1
level=INFO msg="platform ready" project=eutopian platform=weixin
level=INFO msg="engine started" project=eutopian agent=claudecode platforms=1
level=INFO msg="cc-connect is running" projects=2

两个项目均显示 platform ready 即为成功。


Step 7:触发首次 context_token 关联

微信通道有一个重要的初始化步骤:首次连接时必须先发一条消息触发 context_token 关联,之后才能正常使用 /new/reset 等指令。

操作步骤:

  1. cc-connect 启动后,用微信向机器人发任意一条消息(如「你好」)
  2. 等待机器人回复(首次响应约需 10-15 秒)
  3. 关联完成后即可正常使用

常见问题 FAQ

Q1:扫码超时或无反应

# 增加超时时间重试
cc-connect weixin setup --project eutopian --timeout 600

检查网络是否能访问 https://ilinkai.weixin.qq.com,也可用 --api-url 指定其他网关地址。

Q2:已有 Token,不想重新扫码

cc-connect weixin bind --project eutopian --token '<你的_Bearer_Token>'

Q3:启动后收不到消息

按顺序排查:

  1. 确认 allow_from 是否包含你的用户 ID
  2. 确认进程已重启(修改配置后需要重启)
  3. 确认已完成首次 context_token 关联(向机器人发一条消息)

Q4:如何同时运行多个微信账号

在同一项目下添加多个 weixin 平台时,用 account_id 区分:

[[projects.platforms]]
type = "weixin"

[projects.platforms.options]
token = "账号1的token"
account_id = "account_1"   # 隔离本地状态目录

[[projects.platforms]]
type = "weixin"

[projects.platforms.options]
token = "账号2的token"
account_id = "account_2"

--platform-index 参数指定扫码写入到哪个平台:

cc-connect weixin setup --project eutopian --platform-index 2

Q5:如何排除微信通道(精简编译)

go build -tags no_weixin ./cmd/cc-connect

微信通道能力一览

能力支持情况
文字消息收发
引用消息
语音转写文本(STT)✅(需配置语音转写 + ffmpeg)
图片接收(AES-128-ECB 解密)✅(需配置 cdn_base_url
文件接收
视频接收
出站图片发送✅(通过 cc-connect send --image
出站文件发送✅(通过 cc-connect send --file

可选配置项速查

[projects.platforms.options]
token = ""                        # 必填,Bearer Token
base_url = "https://ilinkai.weixin.qq.com"  # 可选,默认同左
cdn_base_url = "https://novac2c.cdn.weixin.qq.com/c2c"  # 可选,媒体 CDN
allow_from = ""                   # 建议填写,限制使用者
admin_from = ""                   # 建议填写,开启管理命令
account_id = "default"            # 多账号时区分状态目录
route_tag = ""                    # 运营商要求时填写
long_poll_timeout_ms = 35000      # 长轮询超时,默认 35s
proxy = ""                        # 可选 HTTP 代理

相关资源

  • cc-connect 仓库:github.com/chenhg5/cc-connect
  • 微信通道文档:docs/weixin.md
  • 企业微信通道(不同协议):docs/wecom.md
  • 完整配置示例:config.example.toml

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员Terry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值