Python implementation of the wcfLink local runtime, HTTP API, SDK, and CLI
Project description
wcflink
wcflink 是参考 lich0821/wcfLink 实现的 Python 版本地运行时。
它直接对接 iLink 通道,负责扫码登录、账号持久化、长轮询收消息、本地事件存储、媒体收发,以及对外提供本地 HTTP API 和 Python SDK。
当前实现
- 扫码登录
- 登录状态轮询
- 已登录账号持久化
- iLink
getupdates长轮询 - 文本消息发送
- 图片、视频、文件、语音发送
- 图片、语音、视频、文件接收与落盘
- 本地事件存储
context_token管理- 本地 HTTP API
- SQLite 状态存储
- Python SDK 和命令行工具
安装
pip install wcflink
运行时依赖:
pycryptodomeqrcode[pil]
它们会随着 wcflink 一起安装。
启动服务
最常见的用法是直接启动本地服务:
wcflink serve
默认监听:
127.0.0.1:17890
默认状态目录:
./data
也可以覆盖配置:
wcflink serve \
--listen-addr 127.0.0.1:28080 \
--state-dir ./runtime-data \
--upstream-base-url https://ilinkai.weixin.qq.com
Python SDK
方式一:调用本地 HTTP API
from wcflink import WcfLinkClient
client = WcfLinkClient("http://127.0.0.1:17890")
print(client.version())
print(client.list_accounts())
print(client.list_events(limit=10))
方式二:直接在进程内启动引擎
from wcflink import Engine, load_config
cfg = load_config()
engine = Engine(cfg=cfg)
engine.start_background()
session = engine.start_login()
print(session.session_id)
print(session.qr_code_url)
登录示例
from wcflink import WcfLinkClient
client = WcfLinkClient()
session = client.start_login()
print(session.session_id)
print(session.qr_code_url)
status = client.get_login_status(session.session_id)
print(status.status)
保存二维码 PNG:
png = client.get_login_qr(session.session_id)
with open("qrcode.png", "wb") as f:
f.write(png)
发送文本消息
client.send_text(
account_id="xxx@im.bot",
to_user_id="yyy@im.wechat",
text="hello",
)
注意:
- 当前发送依赖
context_token - 如果
context_token为空,会尝试从本地历史会话中查找 - 因此目标用户通常需要先给 bot 发过至少一条消息
发送媒体消息
client.send_media(
account_id="xxx@im.bot",
to_user_id="yyy@im.wechat",
file_path="/absolute/path/to/demo.jpg",
media_type="image",
text="caption",
)
media_type 当前支持:
imagevideofilevoice
HTTP API
启动服务后,可用接口与上游 Go 版保持同一思路:
GET /health/liveGET /health/readyGET /api/versionPOST /api/accounts/login/startGET /api/accounts/login/statusGET /api/accounts/login/qrGET /api/accountsGET /api/eventsGET /api/logsGET /api/settingsPOST /api/settingsPOST /api/messages/send-textPOST /api/messages/send-media
命令行
wcflink serve
wcflink version
wcflink accounts
wcflink events --limit 20
wcflink login start
wcflink login status login_xxx
wcflink send-text --account-id xxx@im.bot --to-user-id yyy@im.wechat --text "hello"
wcflink send-media --account-id xxx@im.bot --to-user-id yyy@im.wechat --file-path /abs/demo.jpg --type image
如果服务不在默认地址:
wcflink --base-url http://127.0.0.1:28080 version
构建与发布
cd wcfLink-py
python3 -m pip install --upgrade build twine
python3 -m build
python3 -m twine check dist/*
正式发布前建议确认:
pyproject.toml中的版本号已经更新- README 在 PyPI 上能正常渲染
- 本地
wcflink serve能正常启动 - 登录、轮询、发消息流程已经对真实 iLink 环境做过验证
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wcflink-0.1.0.tar.gz.
File metadata
- Download URL: wcflink-0.1.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
323d9b1c0a72dba3fc3c29a1be0c9736ef118d61dbedc02f8013725c61b907e4
|
|
| MD5 |
8f5a30036d59b99cc6d3140ad9086211
|
|
| BLAKE2b-256 |
1fa7f0c2248fa5a07e1b5569a81fea0c63472d47ae082c5b358a2f07bfcbbb37
|
File details
Details for the file wcflink-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wcflink-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d8e828d7bbac06b23b4fa4027805383faf019e8effe48a20417b42734ee19f8
|
|
| MD5 |
83a90fe6fb0ac9de4e4ac44324f31902
|
|
| BLAKE2b-256 |
1c0929a52dcc048d766522c6a7d9bc46630e8d361b4ae5affe29241dfa1393db
|