修复消息例子

This commit is contained in:
evilbeast 2022-08-25 14:26:33 +08:00
parent 7e1bf189ee
commit c261a9bdf5
6 changed files with 22 additions and 6 deletions

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
import xml.dom.minidom
@ -24,9 +25,11 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
wechat_instance.accept_friend_request(encryptusername, ticket, int(scene))
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
wechat = ntchat.WeChat()
@ -22,9 +23,10 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
wechat_instance.send_text(to_wxid=from_wxid, content=f"你发送的消息是: {data['msg']}")
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
wechat = ntchat.WeChat()
@ -22,9 +23,10 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
# 监听接收文本消息
wechat.on(ntchat.MT_RECV_TEXT_MSG, on_recv_text_msg)
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
wechat = ntchat.WeChat()
@ -17,9 +18,11 @@ print("联系人列表: ")
print(contacts)
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
wechat = ntchat.WeChat()
@ -17,9 +18,11 @@ print("群列表: ")
print(rooms)
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
wechat = ntchat.WeChat()
@ -13,12 +14,14 @@ wechat.wait_login()
# 向文件助手发送一条消息
wechat.send_text(to_wxid="filehelper", content="hello, filehelper")
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()