导航

pyhton自动发送微信信息

Posted on 2023-12-05 10:57  听雨轩!  阅读(426)  评论(0编辑  收藏  举报

1、由于电脑登录微信需手机进行验证,此处略过自动打开微信。

2、安装所需支撑文件:

  pip install wxChat

  pip install pyautogui

3、修改wxauto.py

  由于版本原因,需修改wxauto.py,在引入处按住ctrl,点wxchart,就可打开文件,找到class Wechart:

  
class WeChat:
    def __init__(self):
        self.UiaAPI = uia.WindowControl(ClassName='WeChatMainWndForPC')
        self.SessionList = self.UiaAPI.ListControl(Name='会话')
        # self.EditMsg = self.UiaAPI.EditControl(Name='输入')
        self.SearchBox = self.UiaAPI.EditControl(Name='搜索')
        self.MsgList = self.UiaAPI.ListControl(Name='消息')
        self.SessionItemList = []
    def control(self,ctname):
        self.EditMsg=self.UiaAPI.EditControl(name=ctname)
 
备注掉self.EditMsg = self.UiaAPI.EditControl(Name='输入')。加上    def control(self,ctname):
4、测试发送信息:
import time
from wxauto import WeChat
import pyautogui,sys
keyword="XXX" --微信备注
t_delay1=1
t_delay2=1
 
chartype=2
if chartype==1:
    chat_message="hello word!"
elif chartype==2:
    chat_file_path=r"E:\XXXXX" --指定文件位置

time.sleep(t_delay1)

# pyautogui.click(35,447)
# pyautogui.doubleClick(35,447)

wx=WeChat()
wx.GetSessionList()

who=wx.Search(keyword)
wx.control(who)
time.sleep(t_delay2)

if chartype==1:
    wx.SendMsg(chat_message)
elif chartype==2:
    wx.SendFiles(chat_file_path)
 
5 测试
  在win10,python3.11下测试成功