mirror of
				https://github.com/smallevilbeast/ntchat.git
				synced 2025-11-01 04:46:06 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			833 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			833 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| # -*- coding: utf-8 -*-
 | |
| import sys
 | |
| import ntchat
 | |
| import xml.dom.minidom
 | |
| 
 | |
| wechat = ntchat.WeChat()
 | |
| 
 | |
| # 打开pc微信, smart: 是否管理已经登录的微信
 | |
| wechat.open(smart=False)
 | |
| 
 | |
| 
 | |
| # 注册消息回调
 | |
| @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))
 | |
| 
 | |
| 
 | |
| try:
 | |
|     while True:
 | |
|         pass
 | |
| except KeyboardInterrupt:
 | |
|     ntchat.exit_()
 | |
|     sys.exit()
 | 
