随笔 - 16, 文章 - 0, 评论 - 0, 阅读 - 4704

pyhton自动发送微信信息

Posted on   听雨轩!  阅读(594)  评论(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下测试成功
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示