自动发送消息至微信(适用于中文版微信)

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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值