Skip to main content

A Powerful Windows-PC-Wechat automation Tool

Project description

pywechat🥇

image

🍬🍬pywechat是一款基于pywinauto实现的Windows系统下PC微信自动化的Python项目。它可以帮助用户实现微信的一系列自动化操作,包括发送消息、发送文件、自动回复以及针对微信好友的所有操作,针对微信群聊的所有操作,支持单线程多个任务轮流进行,完全模拟真人操作微信。

微信版本:3.9.12.17

操作系统:🪟windows 10 🪟windows 11

python版本🐍:3.x

pywechat项目结构:

image

该项目内的函数与方法名称与PC微信英文版各界面与功能英文翻译一致。其中pywechat的open_wechat函数无论微信是否打开,是否登录(需先前登录过,手机端勾选自动登录)均可正常打开微信,你只需要将微信WeChat.exe文件地址传入pywechat各个函数,或添加到windows用户环境变量中即可开启微信自动化之旅。🗺️🗺️

注:pywechat最新版本已内置自动添加WeChat.exe为windows用户环境变量的方法。

这里强烈建议将微信Wechat.exe文件添加到windows系统环境变量中,因为pywechat默认使用windows环境变量中的Wechat.exe路径启动微信,此时调用其中的每个方法与函数无需传入wechat_path参数即可自动化操作微信。


获取方法:

pip install pywechat127==1.5.0

添加微信至windows用户环境变量:

pywechat已内置自动添加微信至用户环境变量的方法,运行下列代码即可自动添加微信路径至windows用户变量 :

from pywechat.WechatTools import Tools
Tools.set_wechat_as_environ_path()

效果演示:

Alt text

WechatTools🌪️🌪️

模块包括:

Tools:关于PC微信的一些工具,包括3个关于PC微信程序的方法和10个打开PC微信内各个界面的open系列方法。

API:打开指定微信小程序,指定公众号,打开视频号的功能,若有其他开发者想自动化操作上述程序可调用此API。

函数:该模块内所有函数为上述模块内的所有方法。


WechatAuto🛏️🛏️

模块包括:

Messages: 5种类型的发送消息方法,包括:单人单条,单人多条,多人单条,多人多条,转发消息:多人同一条。
Files: 5种类型的发送文件方法,包括:单人单个,单人多个,多人单个,多人多个,转发文件:多人同一个。发送多个文件时,你只需将所有文件放入文件夹内,将文件夹路径传入即可。
FriendSettings: 涵盖了PC微信针对某个好友的全部操作的方法。
GroupSettings: 涵盖了PC微信针对某个群聊的全部操作的方法。
Contacts: 获取3种类型通讯录好友的备注与昵称包括:微信好友,企业号微信,群聊名称与人数,数据返回格式为json。
Call: 给某个好友打视频或语音电话。
AutoReply:自动接应微信视频或语音电话。

函数:该模块内所有函数为上述模块内的所有方法。


WinSettings🔹🔹

模块包括:

Systemsettings:该模块中提供了7个修改windows系统设置和3个判断文件类型的方法。

函数:该模块内所有函数为上述模块内的所有方法。


使用示例:

(注意,微信WeChat.exe路径已添加至windows系统环境变量,故以下方法或函数无需传入wechat_path这一参数)

给某个好友发送多条信息:

from pywechat.WechatAuto import Messages
Messages.send_messages_to_friend(friend="文件传输助手",messages=['你好','我正在使用pywechat操控微信给你发消息','收到请回复'])
或者
import pywechat.WechatAuto as wechat
wechat.send_messages_to_friend(friend="文件传输助手",messages=['你好','我正在使用pywechat操控微信给你发消息','收到请回复'])

自动接听语音视频电话:

from pywechat.WechatAuto import AutoReply
AutoReply.auto_answer_call(broadcast_content='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',message='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',duration='1h',times=1)
或者
import pywechat.WechatAuto as wechat
wechat.auto_answer_call(broadcast_content='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',message='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',duration='1h',times=1)

多任务使用示例

注意,微信不支持多线程,只支持单线程多任务轮流执行,pywechat也支持单线程多任务轮流执行,在运行多个实例时尽量请将所有函数与方法内的close_wechat参数设为False(默认为True)

这样只需要打开一次微信,多个任务便可以共享资源,更加高效,否则,每个实例在运行时都会重启一次微信,较为低效。


from pywechat.WechatAuto import Messages,Files
Messages.send_messages_to_friend(friend='好友1',messages=['在测试','ok'],close_wechat=False)
Files.send_files_to_friend(friend='文件传输助手',folder_path=r"E:\OneDrive\Desktop\测试专用",with_messages=True,messages_first=True,messages=['在测试文件消息一起发,你应该先看到这条消息,后看到文件'],close_wechat=True)

效果演示:

Alt text

AI自动回复代码:

Alt text


自动回复效果:

Alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywechat127-1.5.1.tar.gz (78.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywechat127-1.5.1-py3-none-any.whl (80.5 kB view details)

Uploaded Python 3

File details

Details for the file pywechat127-1.5.1.tar.gz.

File metadata

  • Download URL: pywechat127-1.5.1.tar.gz
  • Upload date:
  • Size: 78.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for pywechat127-1.5.1.tar.gz
Algorithm Hash digest
SHA256 aeee006047e00d1a1689ee71cbdd11fa3556b5f6542290e5d42de00fe75a206f
MD5 a6517b5eaedd4931e465e62b7563ea12
BLAKE2b-256 2b38049a0cdde24b1fbca1c47216cc5df3949159a8e7c322882fa45e18748208

See more details on using hashes here.

File details

Details for the file pywechat127-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: pywechat127-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 80.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for pywechat127-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ae4a2ee43319908f1e247beb86ee3f51e8bfdd715a06a332ffb6b8890ddb309
MD5 3193dda2044c9ac898e510e0cff93e5d
BLAKE2b-256 ef5e29500b979ca66ddcee50142894a7716dbd8ecb06cd2f229f7e1546e5ebf1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page