吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8086|回复: 116
上一主题 下一主题
收起左侧

[Python 原创] Python uiautomation获取微信内容!聊天记录、聊天列表、全都可获取

    [复制链接]
跳转到指定楼层
楼主
yuupuu 发表于 2023-11-17 17:00 回帖奖励
本帖最后由 yuupuu 于 2023-11-17 18:55 编辑

Python uiautomation 是一个用于自动化 GUI 测试和操作的库,它可以模拟用户操作来执行各种任务。
通过这个库,可以使用Python脚本模拟人工点击,人工操作界面。本文使用 Python uiautomation 进行微信电脑版的操作。

以下是本次实验的版本号。




你需要安装 uiautomation

[Asm] 纯文本查看 复制代码
pip install uiautomation


示例代码

[Python] 纯文本查看 复制代码
import time
import uiautomation as auto
import re
from plyer import notification

notification_history = {}  # 历史消息

def check_wechat_messages():

    # 获取微信窗口
    wechat_win = auto.WindowControl(Name="微信", ClassName="WeChatMainWndForPC")

    shoukuanWin = wechat_win.ListControl(Name="会话")
    bbb = shoukuanWin.GetChildren()

    for chatMsg in bbb:
        if "条新消息" in chatMsg.Name:

            # 计算消息条数
            match = re.match(r'([a-zA-Z0-9]+)(\d+)条新消息', chatMsg.Name)

            if match:
                nickname = match.group(1)
                message_count = int(match.group(2))

                printInfo = f"{nickname} 给你发送了 {message_count} 条消息"
                print(printInfo)
                print("------------")

                # 获取消息列表控件
                xiaoxis = wechat_win.ListControl(Name="消息")
                
                # 获取消息列表控件的子控件
                xiaoxi_children = xiaoxis.GetChildren()

                # 获取最后一个子控件
                last_xiaoxi = xiaoxi_children[-1]

                # 打印最后一条消息的内容
                print(last_xiaoxi.Name)

                # 在指定时间内不重发
                last_notification_time = notification_history.get((nickname, message_count), 0)
                current_time = time.time()

                if current_time - last_notification_time > 15:

                    # 依次发送
                    notification_title = f"来自 {nickname} 的 {message_count} 条消息"
                    notification_message = f"{last_xiaoxi.Name}"

                    notification.notify(
                        title=notification_title,
                        message=notification_message,
                        app_name="WeChat"
                    )

                    # 更新日志
                    notification_history[(nickname, message_count)] = current_time

if __name__ == "__main__":
    try:
        while True:
            check_wechat_messages()
            time.sleep(2)  #2秒检测一次UI组件
    except KeyboardInterrupt:
        print("程序退出~")
    except Exception as e:
        print(f"程序执行出现了问题: {str(e)}")


代码解析:

以上代码使用 uiautomation 实时获取微信聊天列表的消息状态,一旦有消息发过来,就会获取到发送人的微信昵称以及发送的消息内容、消息个数。





每2秒获取一次UI控件的内容,实测挂在后台对CPU和内存占用并无明显影响,结合Python uiautomation的各种用法,可以做成自动回复的功能。使用这款软件,可以获取到微信电脑版大部分控件的内容。例如:微信聊天列表、群名称、好友微信昵称、群人数、微信号等。





还可以获取到群内的每一条聊天内容,获取到你跟好友的聊天记录。





只要 UISpy.exe 可获取到的控件内容,那么你用 Python就可以获取到。

拓展

还可以用来做收款监控。将【微信收款助手】这个公众号单独窗口出来,然后监控这个窗口。

妥妥的实现了一个PC收款监控。可以用来做收款码的支付回调。





[Python] 纯文本查看 复制代码
import uiautomation as auto
import re
import time

def get_children_at_depth(control, target_depth, current_depth=0):
    children = control.GetChildren()
    result = []

    for child in children:
        if current_depth == target_depth:
            result.append(child)
        else:
            result.extend(get_children_at_depth(child, target_depth, current_depth + 1))

    return result

def process_last_child_information(previous_info):
    weixin = auto.WindowControl(Name="微信收款助手", ClassName="ChatWnd")
    xiaoxi = weixin.ListControl(Name="消息")

    target_depth = 5
    depth_5_children = get_children_at_depth(xiaoxi, target_depth)

    # 正则表达式模式
    pattern = r'收款到账通知(\d+月\d+日 \d+:\d+)收款金额¥([0-9.]+)汇总'

    last_child = None

    for child in depth_5_children:
        match = re.search(pattern, child.Name)
        if match:
            last_child = child  # 保存最后一条子控件的引用

    # 在循环结束后,提取最后一条子控件的信息
    if last_child:
        match = re.search(pattern, last_child.Name)
        if match:
            date_time = match.group(1)
            amount = match.group(2)

            # 监听下一笔
            if (date_time, amount) != previous_info:
                print("收款回调:")
                print(date_time)
                print("金额:", amount)
                print("正在等待下一笔...")
                print("----------")

                previous_info = (date_time, amount)

    return previous_info

# 循环
previous_info = None

while True:
    previous_info = process_last_child_information(previous_info)
    # 每2秒执行一次循环
    time.sleep(2)


UISpy.zip (122.86 KB, 下载次数: 656)

请勿使用这种技术用于非法行为,仅供大家开发一写小工具自己用。如果使用这种技术来进行违法行为所带来的责任自行负责,与工具、教程作者、发布的平台无关。

免费评分

参与人数 34吾爱币 +35 热心值 +28 收起 理由
carlosclb + 1 用心讨论,共获提升!
SFTiger2022 + 1 + 1 谢谢@Thanks!
MirrorAjie + 1 + 1 谢谢@Thanks!
sexcat + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
miniport + 1 谢谢@Thanks!
萌新表示是小白 + 1 + 1 太厉害了,学习下
ffrank + 1 谢谢@Thanks!
bobo2017365 + 1 谢谢@Thanks!
零如风 + 1 + 1 谢谢@Thanks!
flyable01 + 1 + 1 用心讨论,共获提升!
池塘春草 + 1 我很赞同!
f1984 + 1 + 1 谢谢@Thanks!
liuzhiwei90 + 1 谢谢@Thanks!
chengane + 1 用心讨论,共获提升!
EHOOD + 1 + 1 谢谢@Thanks!
IMRE + 1 + 1 谢谢@Thanks!
Lyluky + 1 热心回复!
lggjlpph + 1 用心讨论,共获提升!
千年的希望 + 1 + 1 谢谢@Thanks!
ouiazrael + 1 + 1 谢谢@Thanks!
zhixiangwangluo + 1 + 1 用心讨论,共获提升!
激动的石榴 + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
youbudenibuxiao + 1 用心讨论,共获提升!
liuminpu + 1 + 1 已经处理,感谢您对吾爱破解论坛的支持!
yanglinman + 1 谢谢@Thanks!
cshadow + 1 用心讨论,共获提升!
happyxuexi + 1 + 1 谢谢@Thanks!
墨玫醉 + 2 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
xinyangtuina + 1 + 1 用心讨论,共获提升!
52628975 + 1 + 1 这也太牛了吧
得不到的在骚动 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
旗袍妹妹 + 1 + 1 潜力无穷呀
绝版聊神 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
wapj小新手 发表于 2023-11-23 20:53
我运行失败了,下载附件看看
推荐
 楼主| yuupuu 发表于 2024-1-17 17:59 |楼主
rxxcy 发表于 2024-1-15 09:31
我这就研究一下收款

我已经写了。

[Python] 纯文本查看 复制代码
import uiautomation as auto
import re
import time

def get_children_at_depth(control, target_depth, current_depth=0):
    children = control.GetChildren()
    result = []

    for child in children:
        if current_depth == target_depth:
            result.append(child)
        else:
            result.extend(get_children_at_depth(child, target_depth, current_depth + 1))

    return result

def process_last_child_information(previous_info):
    weixin = auto.WindowControl(Name="微信收款助手", ClassName="ChatWnd")
    xiaoxi = weixin.ListControl(Name="消息")

    target_depth = 5
    depth_5_children = get_children_at_depth(xiaoxi, target_depth)

    # 正则表达式模式
    pattern = r'收款到账通知(\d+月\d+日 \d+:\d+)收款金额¥([0-9.]+)汇总'

    last_child = None

    for child in depth_5_children:
        match = re.search(pattern, child.Name)
        if match:
            last_child = child  # 保存最后一条子控件的引用

    # 在循环结束后,提取最后一条子控件的信息
    if last_child:
        try:
            match = re.search(pattern, last_child.Name)
            if match:
                date_time = match.group(1)
                amount = match.group(2)

                # Check if the information is different from the previous one
                if (date_time, amount) != previous_info:
                    print("支付回调:")
                    print(date_time)
                    print("金额:", amount)
                    print("----------")

                    # 添加一个GET请求将amount发送给服务器

                    # Update previous_info with the new values
                    previous_info = (date_time, amount)

        except Exception as e:
            print(f"An error occurred while processing information: {e}")

    return previous_info

# Initialize previous_info to None
previous_info = None

while True:
    try:
        previous_info = process_last_child_information(previous_info)
    except Exception as e:
        print(f"系统错误: {e}")

    # 每3秒执行一次循环
    time.sleep(3) 
沙发
旗袍妹妹 发表于 2023-11-17 17:12
是不是意味着可以通过关键字监控来接收有效的消息
3#
 楼主| yuupuu 发表于 2023-11-17 17:13 |楼主
旗袍妹妹 发表于 2023-11-17 17:12
是不是意味着可以通过关键字监控来接收有效的消息

完全可以
4#
绝版聊神 发表于 2023-11-17 17:16
大佬~牛~~
5#
抱着丨枕头睡 发表于 2023-11-17 17:17
厉害了,可以开展新的东西了
6#
52628975 发表于 2023-11-17 17:19
芜湖老哥牛逼
7#
ycz0030 发表于 2023-11-17 17:20
不错,多谢分享
8#
cz4621698 发表于 2023-11-17 17:21
谢谢Tanking大佬
9#
Vvvvvoid 发表于 2023-11-17 17:23
旗袍妹妹 发表于 2023-11-17 17:12
是不是意味着可以通过关键字监控来接收有效的消息

妹妹你不对劲
10#
yrycw 发表于 2023-11-17 17:23
这个工具好,是不是可以监控微信记录了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 13:07

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表