WinddSnow

OpenClaw-Installation-and-WeChat-ClawBot-Connection

字数统计: 2.3k阅读时长: 10 min
2026/03/25

OpenClaw 安装与微信 ClawBot 连接完整教程

概述

OpenClaw 是一个功能强大的开源 AI 助手框架,支持通过多种渠道(微信、Telegram、Discord、WhatsApp 等)与 AI 助手交互。本教程将详细介绍如何安装 OpenClaw 并配置微信 ClawBot,让你能够通过微信与 AI 助手进行对话。

官方资源

建议在安装前先查阅官方文档,了解最新安装方法和配置选项。

环境要求

  • 操作系统: Ubuntu 20.04+ / CentOS 7+ / macOS 10.15+ / Windows 10+ (WSL2 推荐)
  • Node.js: 22.16+ (推荐 Node 24+)
  • npm: 10.x+
  • Git: 用于版本控制(可选)
  • 网络环境: 需要访问 GitHub、npm 等资源,国内用户可能需要配置代理或使用镜像源

步骤一:推荐安装方法 - 使用官方脚本

OpenClaw 官方提供了便捷的一键安装脚本,推荐优先使用此方法:

1. 官方脚本安装(推荐)

1
curl -fsSL https://openclaw.ai/install.sh | bash

这个脚本会自动:

  1. 检查系统环境
  2. 安装或更新 Node.js(如果需要)
  3. 安装 OpenClaw 核心包
  4. 设置必要的环境变量

2. 中国网络环境注意事项

如果由于网络原因无法访问官方资源,可以尝试以下方法:

使用国内镜像源

1
2
3
4
5
6
7
8
# 临时使用淘宝 npm 镜像
npm config set registry https://registry.npmmirror.com/

# 安装 OpenClaw
npm install -g openclaw

# 恢复默认源(可选)
npm config set registry https://registry.npmjs.org/

使用代理(如果已有代理配置):

1
2
3
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
curl -fsSL https://openclaw.ai/install.sh | bash

3. 手动安装方法(备选)

如果官方脚本不适用,可以手动安装:

先安装 Node.js

1
2
3
4
5
6
7
8
9
10
11
12
# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

# CentOS/RHEL
curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
sudo yum install -y nodejs

# macOS (使用 Homebrew)
brew install node

# Windows (使用 nvm-windows 或官方安装包)

安装 OpenClaw

1
npm install -g openclaw

4. 验证安装

无论使用哪种方法,安装后验证:

1
2
3
node --version    # 应该显示 v22.x.x 或更高
npm --version # 应该显示 10.x.x 或更高
openclaw --version # 显示 OpenClaw 版本号

步骤三:初始化 OpenClaw 配置

首次运行 OpenClaw 会自动创建配置文件:

1
openclaw init

这会创建 ~/.openclaw/ 目录,包含配置文件 openclaw.json

步骤四:启动 OpenClaw 网关服务

OpenClaw 需要网关服务来处理请求:

1
2
3
4
5
6
7
8
# 启动网关服务
openclaw gateway start

# 查看网关状态
openclaw gateway status

# 如果服务未运行,手动启动
openclaw gateway start --port 18789

网关默认运行在 http://127.0.0.1:18789/,可以通过浏览器访问控制界面。

步骤五:安装微信插件

OpenClaw 的微信插件需要通过独立的 CLI 工具安装:

1
npx -y @tencent-weixin/openclaw-weixin-cli@latest install

这个命令会:

  1. 下载并安装微信插件
  2. ~/.openclaw/plugins/ 目录中创建微信插件配置
  3. 注册微信插件到 OpenClaw 系统

中国网络注意事项
如果 npx 命令下载缓慢或失败,可以尝试:

1
2
3
4
5
6
7
8
9
# 使用淘宝 npm 镜像
npm config set registry https://registry.npmmirror.com/
npx -y @tencent-weixin/openclaw-weixin-cli@latest install
npm config set registry https://registry.npmjs.org/

# 或者使用代理
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
npx -y @tencent-weixin/openclaw-weixin-cli@latest install

步骤六:配置微信插件

安装完成后,需要配置微信账号。OpenClaw 提供了交互式配置向导:

1
openclaw configure weixin

按照提示操作:

  1. 选择 “启用微信插件”
  2. 设置账号标识(如 personal-wechat
  3. 选择登录方式(推荐 qrcode 二维码登录)
  4. 配置其他选项(保持默认或根据需求调整)

也可以手动编辑配置文件 ~/.openclaw/openclaw.json

1
2
3
4
5
6
7
8
9
10
11
{
"plugins": {
"openclaw-weixin": {
"enabled": true,
"accountId": "your-weixin-account",
"loginType": "qrcode",
"autoAcceptFriendRequests": true,
"autoAcceptRoomInvitations": true
}
}
}

步骤七:启动微信 ClawBot 并登录

配置完成后,启动微信插件:

1
2
3
4
5
# 启动微信插件
openclaw weixin start

# 或者使用守护进程模式
openclaw weixin start --daemon

第一次启动会显示二维码,使用微信手机客户端扫码登录。注意事项:

  • 确保手机和安装 OpenClaw 的机器在同一网络环境下
  • 扫码后可能需要手机端确认登录
  • 登录成功后,控制台会显示登录成功信息

验证微信插件状态

1
2
3
4
5
6
7
8
# 查看插件状态
openclaw weixin status

# 查看运行日志
openclaw logs weixin

# 实时查看日志
tail -f ~/.openclaw/logs/weixin.log

步骤八:配置 AI 模型(可选)

OpenClaw 支持多种 AI 模型提供商。配置模型有两种方式:

1. 使用交互式向导(推荐)

1
openclaw configure models

向导会引导你:

  1. 选择模型提供商(OpenAI、Anthropic、DeepSeek、Google、等)
  2. 输入 API 密钥
  3. 选择默认模型
  4. 设置其他参数

2. 使用 openclaw config 命令配置

OpenClaw 提供了强大的配置管理命令:

查看当前配置

1
openclaw config get providers

配置 DeepSeek 模型

1
2
3
openclaw config set providers.deepseek.apiKey "your-deepseek-api-key"
openclaw config set providers.deepseek.model "deepseek-chat"
openclaw config set providers.deepseek.baseURL "https://api.deepseek.com"

配置 OpenAI 模型

1
2
openclaw config set providers.openai.apiKey "your-openai-api-key"
openclaw config set providers.openai.model "gpt-4"

配置 Anthropic Claude 模型

1
2
openclaw config set providers.anthropic.apiKey "your-anthropic-api-key"
openclaw config set providers.anthropic.model "claude-3-opus-20240229"

配置 Google Gemini 模型

1
2
openclaw config set providers.google.apiKey "your-google-api-key"
openclaw config set providers.google.model "gemini-1.5-pro"

3. 多模型配置与回退策略

可以配置多个模型提供商,并设置回退顺序:

1
2
3
4
5
# 设置模型优先级
openclaw config set models.order '["openai", "anthropic", "deepseek"]'

# 设置默认模型
openclaw config set models.default "openai"

4. 验证模型配置

1
2
3
4
5
6
7
8
# 测试模型连接
openclaw test-model

# 查看可用模型列表
openclaw models list

# 检查 API 密钥有效性
openclaw health check

5. 中国用户特别提醒

  • DeepSeek:对中国用户友好,无需特殊网络环境
  • OpenAI/Anthropic:需要稳定的国际网络连接
  • 国内替代:可以考虑使用百度文心、阿里通义、智谱AI等国内模型(如果 OpenClaw 支持)

步骤九:高级配置

1. 开机自启动

创建 systemd 服务文件:

1
sudo nano /etc/systemd/system/openclaw.service

内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=OpenClaw Gateway Service
After=network.target

[Service]
Type=simple
User=your-username
WorkingDirectory=/home/your-username
ExecStart=/usr/bin/openclaw gateway start
Restart=always

[Install]
WantedBy=multi-user.target

启用服务:

1
2
sudo systemctl enable openclaw
sudo systemctl start openclaw

2. 多账号配置

可以配置多个微信账号,管理个人和工作账号:

方法一:使用配置向导多次运行

1
2
3
4
5
6
7
# 配置第一个微信账号
openclaw configure weixin
# 设置 accountId 为 "personal-wechat"

# 配置第二个微信账号
openclaw configure weixin
# 设置 accountId 为 "work-wechat"

方法二:手动编辑配置文件
编辑 ~/.openclaw/openclaw.json,配置多个微信插件实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"plugins": {
"openclaw-weixin-personal": {
"enabled": true,
"accountId": "personal-wechat",
"loginType": "qrcode"
},
"openclaw-weixin-work": {
"enabled": true,
"accountId": "work-wechat",
"loginType": "qrcode"
}
}
}

启动不同账号:

1
2
3
4
5
# 启动个人账号
openclaw weixin start --account-id personal-wechat

# 启动工作账号
openclaw weixin start --account-id work-wechat

步骤十:故障排除

常见问题

  1. 网关无法启动

    1
    2
    3
    4
    5
    # 检查端口占用
    sudo lsof -i :18789

    # 停止占用进程
    sudo kill -9 <PID>
  2. 微信扫码失败

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # 重启微信插件,重新生成二维码
    openclaw weixin restart

    # 查看详细日志,了解失败原因
    openclaw logs weixin --tail 50

    # 清除登录缓存(谨慎使用,需要重新扫码)
    rm -rf ~/.openclaw/weixin-session/

    # 检查网络连接,确保手机和电脑在同一网络
    ping -c 4 $(hostname -I | awk '{print $1}')

    # 尝试使用不同的登录方式(如果有其他选项)
    openclaw configure weixin # 重新配置,选择其他登录方式
  3. 消息无回复

    1
    2
    3
    4
    5
    # 检查模型配置
    openclaw config get providers.deepseek

    # 测试模型连接
    openclaw test-model
  4. 更新 OpenClaw

    1
    2
    npm update -g openclaw
    openclaw gateway restart

步骤十一:使用技巧

1. 快捷命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 查看所有命令
openclaw --help

# 查看插件列表
openclaw plugins list

# 查看会话记录
openclaw sessions list

# 配置管理相关
openclaw config get providers # 查看模型配置
openclaw config set gateway.port 19001 # 修改网关端口
openclaw config set cache.enabled true # 启用缓存
openclaw config file # 查看配置文件路径

# 诊断和健康检查
openclaw health check # 检查系统健康状态
openclaw doctor # 诊断常见问题
openclaw status # 查看系统状态

2. 安全建议

  • 定期更新 OpenClaw 版本
  • 使用强密码保护 API 密钥
  • 限制可访问的微信账号
  • 启用日志审计

3. 性能优化

1
2
3
4
5
# 调整内存限制
export NODE_OPTIONS="--max-old-space-size=4096"

# 启用缓存
openclaw config set cache.enabled true

总结

通过以上步骤,你已经成功安装 OpenClaw 并配置了微信 ClawBot。现在可以通过微信与 AI 助手进行自然对话,享受智能助手带来的便利。

OpenClaw 还支持许多其他功能,如:

  • 多平台集成(Telegram、Discord、Slack 等)
  • 自定义技能开发
  • 自动化工作流
  • 定时任务调度

建议参考 OpenClaw 官方文档 了解更多高级功能。


作者:winddsnow
最后更新:2026-03-25
版权声明:本文采用 CC BY-NC-SA 4.0 协议

CATALOG
  1. 1. OpenClaw 安装与微信 ClawBot 连接完整教程
    1. 1.1. 概述
      1. 1.1.1. 官方资源
    2. 1.2. 环境要求
    3. 1.3. 步骤一:推荐安装方法 - 使用官方脚本
      1. 1.3.1. 1. 官方脚本安装(推荐)
      2. 1.3.2. 2. 中国网络环境注意事项
      3. 1.3.3. 3. 手动安装方法(备选)
      4. 1.3.4. 4. 验证安装
    4. 1.4. 步骤三:初始化 OpenClaw 配置
    5. 1.5. 步骤四:启动 OpenClaw 网关服务
    6. 1.6. 步骤五:安装微信插件
    7. 1.7. 步骤六:配置微信插件
    8. 1.8. 步骤七:启动微信 ClawBot 并登录
    9. 1.9. 步骤八:配置 AI 模型(可选)
      1. 1.9.1. 1. 使用交互式向导(推荐)
      2. 1.9.2. 2. 使用 openclaw config 命令配置
      3. 1.9.3. 3. 多模型配置与回退策略
      4. 1.9.4. 4. 验证模型配置
      5. 1.9.5. 5. 中国用户特别提醒
    10. 1.10. 步骤九:高级配置
      1. 1.10.1. 1. 开机自启动
      2. 1.10.2. 2. 多账号配置
    11. 1.11. 步骤十:故障排除
      1. 1.11.1. 常见问题
    12. 1.12. 步骤十一:使用技巧
      1. 1.12.1. 1. 快捷命令
      2. 1.12.2. 2. 安全建议
      3. 1.12.3. 3. 性能优化
    13. 1.13. 总结