← 返回
开发者工具

wxauto

微信自动化操作。通过 wxautox4 RESTful API 实现发送消息、获取聊天记录、监听消息、好友管理等功能。Use when: (1) 发送微信消息给好友或群聊,(2) 读取微信聊天记录,(3) 监听新消息,(4) 获取好友列表或群聊列表,(5) 接受好友申请,(6) 切换聊天窗口等微信操作。
微信自动化操作。通过 wxautox4 RESTful API 实现发送消息、获取聊天记录、监听消息、好友管理等功能。Use when: (1) 发送微信消息给好友或群聊,(2) 读取微信聊天记录,(3) 监听新消息,(4) 获取好友列表或群聊列表,(5) 接受好友申请,(6) 切换聊天窗口等微信操作。
cluic
开发者工具 clawhub v1.0.0 1 版本 99716.2 Key: 无需
★ 7
Stars
📥 3,022
下载
💾 965
安装
1
版本
#latest

概述

微信自动化

通过本地 HTTP 服务操作微信,支持消息收发、监听、好友管理等功能。

前置要求

  1. 安装 wxautox4

```bash

pip install wxautox4

```

> 注意:需windows系统,python3.9,3.10,3.11,3.12 64位,其他python版本暂不支持

  1. 激活 wxautox4

```bash

wxautox4 -a your-activation-code

```

> 获取:https://docs.wxauto.org/plus

  1. 部署 API 服务
  • 克隆项目:https://github.com/cluic/wxauto-restful-api
  • 配置 config.yaml
  • 启动服务:python run.py

服务配置

  • 认证:Bearer Token(见 config.yamlauth.token,默认值为 token
  • 服务状态文件:~/.wxautox/service_status.json(服务启动时自动生成,请查看该文件获取服务信息)

自动配置检测

服务启动后会自动将运行信息写入 ~/.wxautox/service_status.json。wxapi.py 脚本会:

  1. 自动读取此文件获取连接配置
  2. 验证服务是否真的在运行(通过 API 健康检查)
  3. 如果服务未运行,自动启动服务(需要服务目录存在)

服务目录搜索顺序:

  • ../wxauto-restful-api(相对于 skill 目录)
  • ~/wxauto-restful-api
  • WXAPI_SERVICE_DIR 环境变量指定的路径

手动配置方式(可选)

如果需要覆盖自动配置,优先级从高到低:

  1. 命令行参数

```powershell

python wxapi.py --base-url "http://localhost:9000" --token "my-token" send "好友" "消息"

```

  1. 环境变量

```powershell

$env:WXAPI_BASE_URL = "http://localhost:9000"

$env:WXAPI_TOKEN = "my-token"

# 或者

$env:WXAPI_PORT = "9000"

$env:WXAPI_SERVICE_DIR = "/path/to/wxauto-restful-api"

```

  1. service_status.json - 自动检测(推荐)
  1. config.yaml - 服务目录下的配置文件
  1. 默认值 - http://localhost:8000, token 为 token

启动服务

首次使用前需要启动服务:

# 进入服务目录
cd /path/to/wxauto-restful-api

启动服务

python run.py

或后台启动(Windows):

Start-Process python -ArgumentList "run.py" -WorkingDirectory "C:\path\to\wxauto-restful-api" -WindowStyle Hidden

如果服务已运行,脚本会自动连接;如果服务未运行且配置了服务目录,脚本会自动启动服务。

脚本路径

Python 调用脚本位于 skill 目录下的 scripts/wxapi.py

使用 {baseDir} 引用 skill 目录:

python "{baseDir}/scripts/wxapi.py" send "好友" "消息"

可用命令

初始化和状态

# 初始化微信实例
python wxapi.py init

# 获取服务状态
python wxapi.py status

# 检查是否在线
python wxapi.py online

# 获取我的信息
python wxapi.py myinfo

发送消息

# 主窗口发送
python wxapi.py send "好友名" "消息内容"

# 精确匹配
python wxapi.py send "好友名" "消息内容" --exact

# @群成员
python wxapi.py send "群名" "开会了" --at "张三,李四"

# 子窗口发送
python wxapi.py send-chat "好友名" "消息内容"

读取消息

# 获取聊天记录(主窗口)
python wxapi.py getmsg "好友名"

# 获取聊天记录(子窗口)
python wxapi.py getmsg-chat "好友名"

# 获取历史消息
python wxapi.py history "好友名" --count 100

# 获取新消息(主窗口轮询)
python wxapi.py newmsg

# 获取新消息(子窗口)
python wxapi.py newmsg-chat "好友名"

监听管理

# 添加监听(打开子窗口)
python wxapi.py listen "好友名"

会话管理

# 获取会话列表
python wxapi.py session

# 获取所有子窗口
python wxapi.py windows

# 切换聊天窗口
python wxapi.py chatwith "好友名" --exact

获取列表

# 好友列表
python wxapi.py friends

# 群聊列表
python wxapi.py groups

页面控制

# 切换到聊天页面
python wxapi.py switch-chat

# 切换到联系人页面
python wxapi.py switch-contact

查看帮助

python wxapi.py --help

API 接口列表

根据 wxauto-restful-api 服务:

微信功能接口

接口说明
------------
POST /v1/wechat/initialize初始化微信实例
GET /v1/wechat/status获取微信状态
POST /v1/wechat/send发送消息
POST /v1/wechat/sendfile发送文件
POST /v1/wechat/sendurlcard发送 URL 卡片
POST /v1/wechat/getallmessage获取当前窗口消息
POST /v1/wechat/gethistorymessage获取历史消息
POST /v1/wechat/getnextnewmessage获取新消息
POST /v1/wechat/getsession获取会话列表
POST /v1/wechat/getsubwindow获取指定子窗口
POST /v1/wechat/getallsubwindow获取所有子窗口
POST /v1/wechat/chatwith切换聊天窗口
POST /v1/wechat/getfriends获取好友列表
POST /v1/wechat/getmyinfo获取我的信息
POST /v1/wechat/getrecentgroups获取群聊列表
POST /v1/wechat/switch/chat切换到聊天页面
POST /v1/wechat/switch/contact切换到联系人页面
POST /v1/wechat/isonline检查在线状态

聊天接口(子窗口)

接口说明
------------
POST /v1/chat/send子窗口发送消息
POST /v1/chat/getallmessage获取子窗口所有消息
POST /v1/chat/getnewmessage获取子窗口新消息
POST /v1/chat/msg/quote发送引用消息
POST /v1/chat/close关闭子窗口

直接 API 调用(备选)

如需直接调用 HTTP API,用 Python(不要用 PowerShell,有中文编码问题):

import requests

headers = {"Authorization": "Bearer token", "Content-Type": "application/json"}
body = {"who": "好友名", "msg": "消息内容"}
resp = requests.post("http://localhost:8000/v1/wechat/send", headers=headers, json=body)
print(resp.json())

响应格式

所有 API 返回统一格式:

{
  "success": true,
  "message": "操作成功",
  "data": { ... }
}

注意事项

  1. 微信客户端需要保持打开状态
  2. wxautox4 需要激活后才能使用
  3. 不要用 PowerShell 直接调用 API(中文编码问题),请使用 Python 脚本
  4. 修改 config.yaml 中的 auth.token 以增强安全性

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 10:18 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 67 📥 180,038
developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,771
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 668 📥 324,006