from wxauto import *
import pyautogui
class Send():
# 获取当前微信客户端
wx = WeChat()
# 获取会话列表
wx.GetSessionList()
'''
# 用户发送单个文件或消息(文件可以是png、txt等)
'''
def send_file_to_user(self,file, message,who):
# 向某人发送文件,以'文件传输助手'为例
try:
print(f"开始向用户`{who}`发送文件:{file}")
self.wx.ChatWith(who) # 打开`文件传输助手`聊天窗口
if message!="":
self.wx.SendMsg(message)
if file != "":
self.wx.SendFiles(file)
print("发送完毕")
except Exception as e:
print("发送失败,原因为:", e)
# 关闭微信
pyautogui.hotkey('alt', 'f4')
if __name__ == '__main__':
se = Send()
file1 = r'E:\picture\结果.png' # 文件路径
who = '文件传输助手' # 适用于中文版的微信
se.send_file_to_single_user(file=file1,message="文件到了,请查收~" ,who=who)
自动发送消息至微信(适用于中文版微信)
最新推荐文章于 2024-07-26 00:14:15 发布