mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-05-23 05:16:07 +08:00
36 lines
971 B
Python
36 lines
971 B
Python
# -*- coding: utf-8 -*-
|
||
import sys
|
||
import time
|
||
import ntchat
|
||
import xml.dom.minidom
|
||
|
||
wechat = ntchat.WeChat()
|
||
|
||
# 打开pc微信, smart: 是否管理已经登录的微信
|
||
wechat.open(smart=True)
|
||
|
||
|
||
# 注册消息回调
|
||
@wechat.msg_register(ntchat.MT_RECV_FRIEND_MSG)
|
||
def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
|
||
xml_content = message["data"]["raw_msg"]
|
||
dom = xml.dom.minidom.parseString(xml_content)
|
||
|
||
# 从xml取相关参数
|
||
encryptusername = dom.documentElement.getAttribute("encryptusername")
|
||
ticket = dom.documentElement.getAttribute("ticket")
|
||
scene = dom.documentElement.getAttribute("scene")
|
||
|
||
# 自动同意好友申请
|
||
wechat_instance.accept_friend_request(encryptusername, ticket, int(scene))
|
||
|
||
|
||
# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
|
||
try:
|
||
while True:
|
||
time.sleep(0.5)
|
||
except KeyboardInterrupt:
|
||
ntchat.exit_()
|
||
sys.exit()
|
||
|