Skip to main content

wechat robot framework.

Project description

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(faked_wechat_version="3.9.10.19", smart=False)

# 等待登录
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(faked_wechat_version="3.9.10.19", smart=False)

# 等待登录
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(faked_wechat_version="3.9.10.19", smart=False)


# 注册消息回调
@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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ntchat2-1.0.0.tar.gz (7.9 MB view details)

Uploaded Source

File details

Details for the file ntchat2-1.0.0.tar.gz.

File metadata

  • Download URL: ntchat2-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for ntchat2-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9f3fdae299599f71ea5d9b1af6c24e0806ecaaf1d1895938eb9b7d1d24ee3c44
MD5 c9c045db532fdd523527ee99b1d227f0
BLAKE2b-256 a49f52c0fc19f3f2dc4455dea86f872270915f49e00bffb682b904e25cfd9b1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page