Appearance
WeWork 核心类
构造函数
python
WeWork(
version: str,
smart: bool = True,
mutex: bool = True,
host: str = "127.0.0.1",
port: int = 19089,
server_host: str = "127.0.0.1",
server_port: int = 19000,
max_retry: int = 10,
retry_interval: int = 1,
timeout: int = 10
)参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
version | str | 必填 | 企业微信版本号 |
smart | bool | True | 自动接管/多开 |
mutex | bool | True | 启动时终止已有 ww.exe |
host | str | "127.0.0.1" | API 服务监听地址 |
port | int | 19089 | API 服务监听端口 |
server_host | str | "127.0.0.1" | 回调服务地址 |
server_port | int | 19000 | 回调服务端口 |
max_retry | int | 10 | API 请求最大重试次数 |
retry_interval | int | 1 | 重试间隔(秒) |
timeout | int | 10 | 同步请求超时时间(秒) |
基础方法
handle
注册事件处理函数。
python
@wework.handle(event_type: int)
def handler(bot: WeWork, event: dict):
passrun
启动机器人主循环(阻塞)。
python
wework.run()stop
停止机器人。
python
wework.stop()open
接管已运行的企业微信进程。
python
result = wework.open()
# {"code": 0, "message": "pid"}multi_open
多开企业微信。
python
result = wework.multi_open(wework_executable_path: Optional[str] = None)
# {"code": 0, "message": "pid"}inject
注入到指定 PID 的企业微信进程。
python
result = wework.inject(pid: int)destroy
卸载注入。
python
result = wework.destroy()get_wework_version
获取企业微信版本号。
python
result = wework.get_wework_version()get_client_id
根据条件获取客户端 ID。
python
client_id = wework.get_client_id(
by: Literal["index", "account", "user_id", "nickname", "username", "pid"],
value: Union[int, str]
)send
发送数据到指定客户端(异步)。
python
result = wework.send(client_id: int, data: dict)send_sync
同步发送数据到指定客户端(等待响应)。
python
result = wework.send_sync(
client_id: int,
data: dict,
timeout: Optional[int] = None
)数据存储
get_data_location_path
获取数据存储路径。
python
result = wework.get_data_location_path()set_data_location_path
设置数据存储路径。
python
result = wework.set_data_location_path(data_location_path: str)