wcferry.client

Module Contents

Classes

Wcf

WeChatFerry, 一个玩微信的工具。

class wcferry.client.Wcf(host: str = None, port: int = 10086, debug: bool = True)

WeChatFerry, 一个玩微信的工具。

参数:
  • host (str) -- wcferry RPC 服务器地址,默认本地启动;也可以指定地址连接远程服务

  • port (int) -- wcferry RPC 服务器端口,默认为 10086,接收消息会占用 port+1 端口

  • debug (bool) -- 是否开启调试模式(仅本地启动有效)

contacts

联系人缓存,调用 get_contacts 后更新

Type:

list

self_wxid

登录账号 wxid

Type:

str

accept_new_friend(v3: str, v4: str, scene: int = 30) int

通过好友申请

参数:
  • v3 (str) -- 加密用户名 (好友申请消息里 v3 开头的字符串)

  • v4 (str) -- Ticket (好友申请消息里 v4 开头的字符串)

  • scene -- 申请方式 (好友申请消息里的 scene); 为了兼容旧接口,默认为扫码添加 (30)

返回:

1 为成功,其他失败

返回类型:

int

add_chatroom_members(roomid: str, wxids: str) int

添加群成员

参数:
  • roomid (str) -- 待加群的 id

  • wxids (str) -- 要加到群里的 wxid,多个用逗号分隔

返回:

1 为成功,其他失败

返回类型:

int

cleanup() None

关闭连接,回收资源

decrypt_image(src: str, dst: str) bool

解密图片:

参数:
  • src (str) -- 加密的图片路径

  • dst (str) -- 解密的图片路径

返回:

是否成功

返回类型:

bool

disable_recv_msg() int

停止接收消息

enable_receiving_msg() bool

允许接收消息,成功后通过 get_msg 读取消息

enable_recv_msg(callback: Callable[[wcferry.wxmsg.WxMsg], None] = None) bool

(不建议使用)设置接收消息回调,消息量大时可能会丢失消息

自 3.7.0.30.13 版本弃用.

get_contacts() List[dict]

获取完整通讯录

get_dbs() List[str]

获取所有数据库

get_friends() List[dict]

获取好友列表

get_msg(block=True) wcferry.wxmsg.WxMsg

从消息队列中获取消息

参数:

block (bool) -- 是否阻塞,默认阻塞

返回:

微信消息

返回类型:

WxMsg

抛出:

Empty -- 如果阻塞并且超时,抛出空异常,需要用户自行捕获

get_msg_types() dict

获取所有消息类型

get_self_wxid() str

获取登录账户的 wxid

get_tables(db: str) List[dict]

获取 db 中所有表

参数:

db (str) -- 数据库名(可通过 get_dbs 查询)

返回:

db 下的所有表名及对应建表语句

返回类型:

List[dict]

get_user_info() dict

获取登录账号个人信息

is_login() bool

是否已经登录

is_receiving_msg() bool

是否已启动接收消息功能

keep_running()

阻塞进程,让 RPC 一直维持连接

query_sql(db: str, sql: str) List[dict]

执行 SQL,如果数据量大注意分页,以免 OOM

参数:
  • db (str) -- 要查询的数据库

  • sql (str) -- 要执行的 SQL

返回:

查询结果

返回类型:

List[dict]

receive_transfer(wxid: str, transferid: str) int

接收转账

参数:
  • wxid (str) -- 转账消息里的发送人 wxid

  • transferid (str) -- 转账消息里的 transferid

返回:

1 为成功,其他失败

返回类型:

int

send_emotion(path: str, receiver: str) int

发送表情

参数:
  • path (str) -- 本地表情路径,如:C:/Projs/WeChatRobot/emo.gif

  • receiver (str) -- 消息接收人,wxid 或者 roomid

返回:

0 为成功,其他失败

返回类型:

int

send_file(path: str, receiver: str) int

发送文件

参数:
  • path (str) -- 本地文件路径,如:C:/Projs/WeChatRobot/README.MD

  • receiver (str) -- 消息接收人,wxid 或者 roomid

返回:

0 为成功,其他失败

返回类型:

int

send_image(path: str, receiver: str) int

发送图片,非线程安全

参数:
  • path (str) -- 图片路径,如:C:/Projs/WeChatRobot/TEQuant.jpeghttps://raw.githubusercontent.com/lich0821/WeChatRobot/master/TEQuant.jpeg

  • receiver (str) -- 消息接收人,wxid 或者 roomid

返回:

0 为成功,其他失败

返回类型:

int

send_text(msg: str, receiver: str, aters: str | None = '') int

发送文本消息

参数:
  • msg (str) -- 要发送的消息,换行使用 n;如果 @ 人的话,需要带上跟 aters 里数量相同的 @

  • receiver (str) -- 消息接收人,wxid 或者 roomid

  • aters (str) -- 要 @ 的 wxid,多个用逗号分隔;@所有人 只需要 nofity@all

返回:

0 为成功,其他失败

返回类型:

int

send_xml(receiver: str, xml: str, type: int, path: str = None) int

发送 XML

参数:
  • receiver (str) -- 消息接收人,wxid 或者 roomid

  • xml (str) -- xml 内容

  • type (int) -- xml 类型,如:0x21 为小程序

  • path (str) -- 封面图片路径

返回:

0 为成功,其他失败

返回类型:

int