Skip to content

HTTP 服务

PyWeWork 提供了基于 FastAPI 的 HTTP API 服务模式,方便与其他系统集成。

安装依赖

bash
pip install fastapi uvicorn

启动服务

bash
python server.py

服务默认运行在 http://127.0.0.1:8000,访问 http://127.0.0.1:8000/docs 查看 Swagger 文档。

使用流程

1. 设置企业微信版本

bash
curl -X POST "http://127.0.0.1:8000/set_wework_version?version=5.0.0.6008"

2. 设置消息回调地址(可选)

bash
curl -X POST "http://127.0.0.1:8000/set_callback_url?url=http://your-server/callback"

3. 获取已接管的客户端列表

bash
curl http://127.0.0.1:8000/clients

4. 发送消息

bash
curl -X POST "http://127.0.0.1:8000/send_text/1" \
  -H "Content-Type: application/json" \
  -d '{"conversation_id": "xxx", "content": "Hello!"}'

API 分类

分类说明
客户端版本设置、接管、多开
登录二维码、登录状态
联系人联系人增删改查
群聊群聊管理
消息各类消息发送
CDN文件上传下载
其他数据存储路径等

消息回调

设置回调地址后,所有接收到的消息都会 POST 到该地址:

python
# 你的回调服务
from fastapi import FastAPI, Body

app = FastAPI()

@app.post("/callback")
def callback(data: dict = Body(...)):
    print(f"收到消息: {data}")
    return {"status": "ok"}

Released under the MIT License.