Hello-Mr-Crab/pywechat
حول
أتمتة WeChat باستخدام RPA وما زالت تعمل! تدعم سلسلة WeChat 4.0. pywechat أداة لأتمتة عمليات WeChat على سطح مكتب Windows، مبنية على pywinauto، وتنفّذ معظم العمليات المتاحة في تطبيق WeChat لأجهزة الكمبيوتر.
الإنتاجية والأتمتةالنمو المقاس للنجوم
- خلال 24 ساعة
- +٣
- خلال 7 أيام
- +١٩
- خلال 15 يومًا
- +٣٢
- خلال شهر
- +٧٦
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلpywechat🥇

🍬🍬微信RPA工具,支持4.1+微信自动化
pywechat是一个基于pywinauto实现的Windows系统下PC微信自动化(pure uiautomation)的项目(不涉及逆向Hook操作),可以用来收发消息和数据获取。 注意,本项目开发的初衷为使用UI自动化和分享UI自动化技术。 切勿将该工具用于违反微信使用条例的操作!
适用环境
- 微信版本:3.9.12.x,4.1.6+
- 操作系统:🪟7 🪟10 🪟11
- python版本:3.10+(支持TypeHint)
- 支持语言:简体中文,English,繁體中文
UI可见性相关问题
- 1.使用UI树可见的账号进行rpa
- 2.使用一些其他方法进行rpa比如OCR
pyweixin 与 pywechat 项目结构(pywechat只能用于32位x86🪟10,32位x86🪟7)
pywechat只支持旧版本微信(大部分方法仍然稳定可用),现在主要维护与更新支持4.1系列自动化的pyweixin pywechat使用说明
Skill使用
目前,可以使用的Skill的Agent主流平台:
具体使用方法可见QuickStart.md
使用示例:
实际效果:
快速上手✌️
pyweixin模块介绍(适用于4.1+微信)
pyweixin内所有方法需要先导入模块下的类然后调用内部方法☸︎
from pyweixin import xx(class)
xx(class).yy(method)
WechatTools🌪️🌪️
class包括
Tools:关于PC微信的一些工具,微信路径,运行状态,以及内部一些UI相关的判别方法。Navigator:打开微信内部一切可以打开的界面。
WechatAuto🛏️🛏️
class(类) 包括
AutoReply:自动回复操作。(一种简单的实现方式,如果对此感兴趣可以使用pyweixin内部的一些方法自行尝试)Call: 给某个好友打视频或语音电话。Contacts: 获取通讯录内各分区(联系人,企业微信联系人,公众号,服务号)好友的名称与详情。Files: 文件发送,聊天文件从本地导出等。FriendSettings: 针对某个好友的一些相关设置。Messages: 消息发送,聊天记录获取,聊天会话导出等。Moments:针对微信朋友圈的一些方法,包括朋友圈内容获取,发布朋友圈。Monitor:打开聊天窗口进行监听消息。
WinSettings🔹🔹
class(类)包括
SystemSettings:该模块中提供了一些修改windows系统设置的方法(在自动化过程中)。
utils🍬🍬
内部的一些函数主要用来二次开发,大部分传入的参数是main_window,pywinauto实例化的对象(使用Navigator.open_weixin打开)
func包括
At:在群聊中At指定的一些好友At_all:在群聊中At所有人auto_reply_to_friend_decorator:自动回复好友装饰器get_new_message_num:获取新消息总数,微信按钮上的红色数字scan_for_newMessages:会话列表遍历一遍有新消息提示的对象,返回好友名称与数量open_red_packet: 点击打开好友发送的红包language_detector:微信当前使用语言检测(不能禁用WeChatAppex.exe(涉及到公众号,微信内置浏览器,视频号等功能),原理是查询WeChatAppex.exe命令行参数)
pyweixin使用示例
所有自动化操作只需两行代码即可实现,即:
from pyweixin import xxx
xxx.yy
发送语音消息给好友
'''
微信版本>=4.1.9,且配置过虚拟驱动,并且安装sounddevice与soundfile库,具体可见
https://mrcrab.blog.csdn.net/article/details/160481307?fromshare=blogdetail&sharetype=blogdetail&sharerId=160481307&sharerefer=PC&sharesource=weixin_73953650&sharefrom=from_link
''''
from pyweixin import Messages
Messages.send_audios_to_friend(friend='小号测试',audios=[r"E:\Desktop\录音.wav",r"E:\Desktop\音乐.mp3",r"E:\Desktop\音乐.ogg"])
引用回复指定消息
按消息原文内容定位并回复,支持自动向上滚动遍历历史消息。
from pyweixin import Messages
Messages.reply_with_quote(
friend='好友备注',
quote_text='要引用的消息原文',
reply_messages=['回复内容'],
close_weixin=False
)
当引用消息高度异常(如包含引用块)时自动调整右键位置。
关于微信的基本信息输出
from pyweixin import Tools
print(Tools.about_weixin())
多线程监听几个聊天窗口消息
from concurrent.futures import ThreadPoolExecutor
from pyweixin import Navigator,Monitor
#先打开所有好友的独立窗口
dialog_windows=[]
friends=['Hello,Mr Crab','Pywechat测试群']
durations=['1min']*len(friends)
for friend in friends:
dialog_window=Navigator.open_seperate_dialog_window(friend=friend,window_minimize=True,close_weixin=True)
dialog_windows.append(dialog_window)
with ThreadPoolExecutor() as pool:
results=pool.map(lambda args: Monitor.listen_on_chat(*args),list(zip(dialog_windows,durations)))
for friend,result in zip(friends,results):
print(friend,result)
#返回值 {'新消息总数':x,'文本数量':x,'文件数量':x,'图片数量':x,'视频数量':x,'链接数量':x,'文本内容':x,'消息发送人':x}
监听会话列表内的新消息
from pyweixin import Monitor
#maxPages设置为0不滚动,只在顶部可见部分监听,全屏+maxPages为0+需要监听对象置顶=稳定安全
result=Monitor.listen_on_newMessages(duration='30s',maxPages=0)
print(result)

自动回复会话列表内的新消息
from pyweixin import AutoReply
def reply_func(friend,newMessage):
return f'我在自动回复:{friend},这是对方发送的新消息:{newMessage}'
#maxPages设置为0不滚动,只在顶部可见部分自动回复,全屏+maxPages为0+需要回复对象置顶=稳定安全
responded_detail=AutoReply.auto_reply_messages(callback=reply_func,duration='1min',maxPages=0)
print(responded_detail)
朋友圈内容导出
from pyweixin import Moments
#获取并导出今日前10个好友发布的朋友圈的具体内容
posts=Moments.dump_recent_posts(recent='Today',save_detail=True,number=10)
for dic in posts:
print(dic)
发布朋友圈
from pyweixin import Moments
Moments.post_moments(texts='''发布朋友圈测试[旺柴]''',medias=[r"E:\Desktop\test0.png",r"E:\Desktop\test1.png"])
好友朋友圈内容导出
from pyweixin import Moments
Moments.dump_friend_posts(friend='xxx',number=3,save_detail=True,target_folder=r"E:\Desktop\好友朋友圈内容导出")
好友朋友圈自定义评论
from pyweixin import Moments
def comment_func(content):
if 'xxx' in content:
return 'yyy'
return 'zzz'
Moments.like_friend_posts(friend='xxx',number=20,callback=comment_func)
公众号文章url获取
from pyweixin import Collections
Collections.collect_offAcc_articles(name='新华社',number=10)
urls=Collections.cardLink_to_url(number=10)
for url,text in urls.items():
print(f'{text}\n{url}')
收藏内的笔记导出为MarkDown
from pyweixin import Collections
Collections.save_notes(number=1)
此外pyweixin内所有方法及函数的一些位置参数支持全局设定,be like
from pyweixin import Navigator,GlobalConfig
GlobalConfig.load_delay=2.5
GlobalConfig.is_maximize=True
GlobalConfig.close_weixin=False
Navigator.search_channels(search_content='微信4.0')
Navigator.search_miniprogram(name='问卷星')
Navigator.search_official_account(name='微信')
其他使用方法可见代码中详细的文档注释以及pyweixin操作手册.docx
注意
👎👎请勿将pywechat用于任何非法商业活动,因此造成的一切后果由使用者自行承担!
本项目相关教程博客
作者CSDN主页:Hello,Mr Crab
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…