Skip to main content

NtChat2

release License

介绍

  • 基于pc微信的api接口, 类似itchat项目
  • 支持收发文本、群@、名片、图片、文件、视频、链接卡片等
  • 支持好友和群管理

支持的微信版本下载

安装

pip install ntchat2

国内源安装

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ntchat2

简单入门实例

有了ntchat,如果你想要给文件传输助手发一条信息,只需要这样

# -*- coding: utf-8 -*-
import sys
import ntchat2

wechat = ntchat2.WeChat()

# 打开pc微信, smart: 是否管理已经登录的微信
# wechat.open(smart=False)

# 微信登录出现登录限制时,使用faked_wechat_version伪造版本号
wechat.open(smart=False, faked_wechat_version="3.9.10.19")

# 等待登录
wechat.wait_login()

# 向文件助手发送一条消息
wechat.send_text(to_wxid="filehelper", content="hello, filehelper")

try:
    while True:
        pass
except KeyboardInterrupt:
    ntchat2.exit_()
    sys.exit()

获取联系人和群列表

# -*- coding: utf-8 -*-
import sys
import ntchat2

wechat = ntchat2.WeChat()

# 打开pc微信, smart: 是否管理已经登录的微信
# wechat.open(smart=False)

# 微信登录出现登录限制时,使用faked_wechat_version伪造版本号
wechat.open(smart=False, faked_wechat_version="3.9.10.19")

# 等待登录
wechat.wait_login()

# 获取联系人列表并输出
contacts = wechat.get_contacts()

print("联系人列表: ")
print(contacts)

rooms = wechat.get_rooms()
print("群列表: ")
print(rooms)


try:
    while True:
        pass
except KeyboardInterrupt:
    ntchat2.exit_()
    sys.exit()

监听消息并自动回复

# -*- coding: utf-8 -*-
import sys
import ntchat2

wechat = ntchat2.WeChat()

# 打开pc微信, smart: 是否管理已经登录的微信
# wechat.open(smart=False)

# 微信登录出现登录限制时,使用faked_wechat_version伪造版本号
wechat.open(smart=False, faked_wechat_version="3.9.10.19")

# 注册消息回调
@wechat.msg_register(ntchat2.MT_RECV_TEXT_MSG)
def on_recv_text_msg(wechat_instance: ntchat2.WeChat, message):
    data = message["data"]
    from_wxid = data["from_wxid"]
    self_wxid = wechat_instance.get_login_info()["wxid"]

    # 判断消息不是自己发的,并回复对方
    if from_wxid != self_wxid:
        wechat_instance.send_text(to_wxid=from_wxid, content=f"你发送的消息是: {data['msg']}")


try:
    while True:
        pass
except KeyboardInterrupt:
    ntchat2.exit_()
    sys.exit()

Metadata

Release files for ntchat2 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ntchat2 1.0.3
File Size Uploaded
ntchat2-1.0.3.tar.gz 13.2 MB Details

Release files / ntchat2-1.0.3.tar.gz

Download URL ntchat2-1.0.3.tar.gz
Size 13.2 MB
Tags Source
SHA-256 checksum
How to use checksums
d32733f570490c9bdcda2d28eb2225f7f1fb4dc317de15c22c29656937976370
BLAKE2b-256 checksum
How to use checksums
2ee7ce939dba1d737905757fb68aaa3cf7eafe8734d29618a7836a6dae766ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page