mirror of
				https://github.com/smallevilbeast/ntchat.git
				synced 2025-10-25 20:16:05 +08:00 
			
		
		
		
	修复消息例子
This commit is contained in:
		
							parent
							
								
									7e1bf189ee
								
							
						
					
					
						commit
						c261a9bdf5
					
				|  | @ -1,5 +1,6 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import sys | import sys | ||||||
|  | import time | ||||||
| import ntchat | import ntchat | ||||||
| import xml.dom.minidom | 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)) |     wechat_instance.accept_friend_request(encryptusername, ticket, int(scene)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 | ||||||
| try: | try: | ||||||
|     while True: |     while True: | ||||||
|         pass |         time.sleep(0.5) | ||||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||||
|     ntchat.exit_() |     ntchat.exit_() | ||||||
|     sys.exit() |     sys.exit() | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import sys | import sys | ||||||
|  | import time | ||||||
| import ntchat | import ntchat | ||||||
| 
 | 
 | ||||||
| wechat = ntchat.WeChat() | 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']}") |         wechat_instance.send_text(to_wxid=from_wxid, content=f"你发送的消息是: {data['msg']}") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 | ||||||
| try: | try: | ||||||
|     while True: |     while True: | ||||||
|         pass |         time.sleep(0.5) | ||||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||||
|     ntchat.exit_() |     ntchat.exit_() | ||||||
|     sys.exit() |     sys.exit() | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import sys | import sys | ||||||
|  | import time | ||||||
| import ntchat | import ntchat | ||||||
| 
 | 
 | ||||||
| wechat = ntchat.WeChat() | 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) | wechat.on(ntchat.MT_RECV_TEXT_MSG, on_recv_text_msg) | ||||||
| 
 | 
 | ||||||
|  | # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 | ||||||
| try: | try: | ||||||
|     while True: |     while True: | ||||||
|         pass |         time.sleep(0.5) | ||||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||||
|     ntchat.exit_() |     ntchat.exit_() | ||||||
|     sys.exit() |     sys.exit() | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import sys | import sys | ||||||
|  | import time | ||||||
| import ntchat | import ntchat | ||||||
| 
 | 
 | ||||||
| wechat = ntchat.WeChat() | wechat = ntchat.WeChat() | ||||||
|  | @ -17,9 +18,11 @@ print("联系人列表: ") | ||||||
| print(contacts) | print(contacts) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 | ||||||
| try: | try: | ||||||
|     while True: |     while True: | ||||||
|         pass |         time.sleep(0.5) | ||||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||||
|     ntchat.exit_() |     ntchat.exit_() | ||||||
|     sys.exit() |     sys.exit() | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import sys | import sys | ||||||
|  | import time | ||||||
| import ntchat | import ntchat | ||||||
| 
 | 
 | ||||||
| wechat = ntchat.WeChat() | wechat = ntchat.WeChat() | ||||||
|  | @ -17,9 +18,11 @@ print("群列表: ") | ||||||
| print(rooms) | print(rooms) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 | ||||||
| try: | try: | ||||||
|     while True: |     while True: | ||||||
|         pass |         time.sleep(0.5) | ||||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||||
|     ntchat.exit_() |     ntchat.exit_() | ||||||
|     sys.exit() |     sys.exit() | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import sys | import sys | ||||||
|  | import time | ||||||
| import ntchat | import ntchat | ||||||
| 
 | 
 | ||||||
| wechat = ntchat.WeChat() | wechat = ntchat.WeChat() | ||||||
|  | @ -13,12 +14,14 @@ wechat.wait_login() | ||||||
| # 向文件助手发送一条消息 | # 向文件助手发送一条消息 | ||||||
| wechat.send_text(to_wxid="filehelper", content="hello, filehelper") | wechat.send_text(to_wxid="filehelper", content="hello, filehelper") | ||||||
| 
 | 
 | ||||||
|  | # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码 | ||||||
| try: | try: | ||||||
|     while True: |     while True: | ||||||
|         pass |         time.sleep(0.5) | ||||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||||
|     ntchat.exit_() |     ntchat.exit_() | ||||||
|     sys.exit() |     sys.exit() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 evilbeast
						evilbeast