一个依赖于 [ComWeChatRobot](https://github.com/ljc545w/ComWeChatRobot)提供的Com接口的微信机器人
Project description
WhoChat
一个依赖于 ComWeChatRobot提供的Com接口的微信机器人,在此之上提供了:
- 发布至PyPI,可以一键安装
- 命令行支持,可以方便通过命令操作(见下面使用说明)
- WebSocket消息推送
- JSON-RPC2.0方法调用,支持WebSocket和HTTP
- 简单的定时任务支持
- 其他
安装:
pip install whochat
若需要HTTP RPC支持,则是pip install whochat[httprpc]
安装完成之后尝试使用whochat
命令,理应看到以下输出:
D:\
> whochat --help
Usage: whochat [OPTIONS] COMMAND [ARGS]...
微信机器人
使用<子命令> --help查看使用说明
Options:
--help Show this message and exit.
Commands:
list-wechat 列出当前运行的微信进程
regserver 注册COM
serve-message-ws 运行接收微信消息的Websocket服务
serve-rpc-http 运行微信机器人RPC服务(JSON-RPC2.0), 使用HTTP接口
serve-rpc-ws 运行微信机器人RPC服务(JSON-RPC2.0), 使用Websocket
show-rpc-docs 列出RPC接口
version 显示程序和支持微信的版本信息
使用
- 列出当前运行的微信进程:
> whochat list-wechat
PID: 102852
启动时间: 2022-08-27T22:22:02.290700
运行状态: running
用户名: wxid_hjkafa123a
---
- 注册COM服务:
> whochat regserver # 注册
> whochat regserver --unreg # 取消注册
注册一次就可以使用服务了。
- 开启微信消息转发WebSocket服务
> whochat serve-message-ws --help
Usage: whochat serve-message-ws [OPTIONS] [WX_PIDS]...
运行接收微信消息的Websocket服务
WX_PIDS: 微信进程PID
Options:
-h, --host TEXT Server host. [default: localhost]
-p, --port INTEGER Server port [default: 9001]
--help Show this message and exit.
该子命令接受一或多个微信PID作为位置参数,可以指定地址
> whochat serve-message-ws 102852
注册SIGINT信号处理程序: WechatWebsocketServer.shutdown
开始运行微信消息接收服务
开始向客户端广播接收到的微信消息
开始运行微信Websocket服务,地址为:<localhost:9001>
{'wxId': 'wxid_hjkafa123a', 'wxNumber': 'wxid_hjkafa123a', 'wxNickName': 'Cider', 'Sex': '男', 'wxSignature': 'null', 'wxBigAvatar': 'http://wx.qlogo.cn/mmhead/ver_1/R50J6cxxTRzE28sY32DVJibeRUZPiaPotzPVjuReXZsONBdNZXQChSfrK0rDWh8RKS5ibt7VJdK0p22YJrOGjRA051lY9mwkt6ONruLmYTyBAA/0', 'wxSmallAvatar': 'http://wx.qlogo.cn/mmhead/ver_1/R50J6cxxTRzE28sY32DVJibeRUZPiaPotzPVjuReXZsONBdNZXQChSfrK0rDWh8RKS5ibt7VJdK0p22YJrOGjRA051lY9mwkt6ONruLmYTyBAA/132', 'wxNation': 'CN', 'wxProvince': 'Anhui', 'wxCity': 'Hefei', 'PhoneNumber': 'null'}
开启Robot消息推送
默认地址为localhost:9001
,连接测试:
- 开启WebSocket RPC服务进行方法调用:
> whochat serve-rpc-ws
PID: 28824
注册SIGINT信号处理程序: run.<locals>.shutdown
运行微信机器人RPC websocket服务, 地址为<localhost:9002>
默认地址为localhost:9002
,测试发送消息给文件,记得先调用start_robot_service
注入dll
RPC所有方法和参数可通过whochat show-rpc-docs
命令查看或者whochat show-rpc-docs --json > docs.json
生成JSON文档:
> whochat show-rpc-docs --help
Usage: whochat show-rpc-docs [OPTIONS]
列出RPC接口
whochat show-rpc-docs
or
whochat show-rpc-docs --json > docs.json
Options:
--json JSON文档
--help Show this message and exit.
- 定时任务:
在每天上午6点整喊基友起床,同样使用RPC调用schedule_a_job
(获取接口文档见4),
{
"jsonrpc": "2.0",
"method": "schedule_a_job",
"params": {
"name": "GETUP",
"unit": "days",
"every": 1,
"at": "08:00:00",
"do": {
"func": "send_text",
"args": [
102852,
"jiyou",
"GET UP!"
]
},
"description": "",
"tags": [
"jiyou"
]
},
"id": 4
}
欢迎学习交流
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
whochat-1.0.0.tar.gz
(121.3 kB
view details)
Built Distribution
whochat-1.0.0-py3-none-any.whl
(123.2 kB
view details)
File details
Details for the file whochat-1.0.0.tar.gz
.
File metadata
- Download URL: whochat-1.0.0.tar.gz
- Upload date:
- Size: 121.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85f61bb85dda8a707eb5c7ad53f66c16b04031f8fe421431382aae5a7d88af1c |
|
MD5 | d181ae7b9551219f5332c745688c895c |
|
BLAKE2b-256 | 71fa45d7a1abc1b15f914ce265e254d4f04c85a362cf3881aa551db95e1caf72 |
Provenance
File details
Details for the file whochat-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: whochat-1.0.0-py3-none-any.whl
- Upload date:
- Size: 123.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72471f481a6c277faa100a8882fa67d5464665671793532089e6ffb0e3f1c0ad |
|
MD5 | aab86825334b6b58f6768d93c3b213d4 |
|
BLAKE2b-256 | 38c825941a7877eea1b9315fd0f989a5958678cb5cdd481524770dc380c8cf5d |