Python实现微信电脑版微信支付收款监听及支付回调通知

图形学
• 阅读 937

摘要

为什么要监听收款?那是因为现在还有人在使用微信的收款码、商业码、赞赏码实现免签支付,这类实现方法的最终方案还是监听收款结果。

技术原理

通过Python实时解析微信电脑版控件的文本内容来获取信息。不需要Hook和抓包,也不是走任何的协议,就是非常简单的界面信息获取和解析。

如何使用

  1. 登录电脑版微信;
  2. 找到微信支付公众号;
  3. 双击,让微信支付公众号单独显示,如下图;
  4. WxPayPcNotify.py修改你的接收通知的Url;
  5. cmd运行WxPayPcNotify.py即可开启监听。

Python实现微信电脑版微信支付收款监听及支付回调通知

接收支付结果通知

WxPayPcNotify.py监听到收款通知后,会向你服务器POST三个参数:

amount:收款金额
sender:微信昵称
timestamp:到账时间

nitify.php示例

<?php
    
    // 收款金额
    $amount = trim($_POST['amount']);

    // 微信昵称
    $sender = trim($_POST['sender']);

    // 到账时间
    $timestamp = trim($_POST['timestamp']);

    // 编写你的逻辑

?>

代码

WxPayPcNotify.py

import re
import time
import uiautomation as automation
import requests

last_matched_info = None

def explore_control(control, depth, target_depth):
    global last_matched_info
    try:
        name = control.Name
        if name:
            if depth == target_depth:
                # 匹配收款金额信息
                match = re.search(r'收款金额¥([\d.]+)', name)
                if match:
                    global amount
                    amount = match.group(1)
                    last_matched_info = f"收款金额: ¥{amount}, "

                # 匹配来自、到账时间信息
                match = re.search(r'来自(.+?)到账时间(.+?)备注', name)
                if match:
                    global sender
                    sender = match.group(1)
                    global timestamp
                    timestamp = match.group(2)
                    last_matched_info += f"来自: {sender}, 到账时间: {timestamp}"
                return
        # 递归处理子控件
        for child in control.GetChildren():
            explore_control(child, depth + 4, target_depth)
    except Exception as e:
        print(f"发生错误: {str(e)}")

def process_wechat_window(wechat_window, prev_info):
    global last_matched_info
    if wechat_window.Exists(0):
        explore_control(wechat_window, 0, 60)
        if last_matched_info and last_matched_info != prev_info:
            print(last_matched_info)
            print("-----------------------------------------------------------------")
            print("持续监听中...")
            print("-----------------------------------------------------------------")
            prev_info = last_matched_info
            
            # 向服务器发送请求
            send_http_request(last_matched_info,amount,sender,timestamp)

    else:
        print("无法获取到窗口,请保持微信支付窗口显示...")
    return prev_info

def send_http_request(info,amount,sender,timestamp):

    # 接收通知的Url
    server_url = 'https://www.yourdomain.com/notify.php'
    try:
        # 将金额、来自、到账时间POST给服务器
        response = requests.post(server_url, data={'amount': amount,'sender': sender,'timestamp': timestamp})
        # 通知成功
        # print("通知成功")
    except Exception as e:
        # 通知失败
        print(f"通知服务器失败...: {str(e)}")

def main():
    global last_matched_info
    prev_info = None
    try:
        # 获取微信窗口
        wechat_window = automation.WindowControl(searchDepth=1, ClassName='ChatWnd')
        prev_info = process_wechat_window(wechat_window, prev_info)
    except Exception as e:
        print(f"发生错误: {str(e)}")

    while True:
        try:
            # 持续监听微信窗口
            wechat_window = automation.WindowControl(searchDepth=1, ClassName='ChatWnd')
            prev_info = process_wechat_window(wechat_window, prev_info)
        except Exception as e:
            print(f"发生错误: {str(e)}")

        time.sleep(2)

if __name__ == "__main__":
    print("-----------------------------------------------------------------")
    print("欢迎使用liKeYun_WxPayPcNotify微信电脑版收款监控脚本...")
    print("-----------------------------------------------------------------")
    main()

作者

TANKING

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
vue h5 对接支付宝,微信支付,微信js支付
vueh5实现支付(支付宝,微信)h5端实现支付难度不大,只是有些小的点需要注意下,其他的看文档撸就行了。支付宝很简单,后端返回一个html,前端插入调用就行了,微信支付分两种:1、微信内支付(jsapi,微信内浏览器)2、微信外支付(h5支付)。一、支付宝支付//前端啥都不用管,交给后端去干,返回html调用点击就好了/
ThinkPHP V5.0 接入微信支付+回调
ThinkPHPV5.0接入微信支付微信支付接口组装访问数组$data'body''商城购买商品';//订单标题$data'outtradeno'generaterandstr(8,0);//平台订单号(非小程序订单,自己平台生成的)$data'notifyurl'$thisrequestdomain().'';//微信支付
Easter79 Easter79
3年前
thinkcmf+jsapi 实现微信支付
首先从小程序端接收订单号、金额等参数,然后后台进行统一下单,把微信支付的订单号返回,在把订单号发送给前台,前台拉起支付,返回参数后更改支付状态。。。回调publicfunctionnotify(){$wechatDb::name('wechat')where('status',1)find();
梦
4年前
微信小程序new Date()转换时间异常问题
微信小程序苹果手机页面上显示时间异常,安卓机正常问题image(https://imghelloworld.osscnbeijing.aliyuncs.com/imgs/b691e1230e2f15efbd81fe11ef734d4f.png)错误代码vardate'2021030617:00:00'vardateT
liam liam
1年前
Postman 调试微信支付接口教程,一看就会
前期准备在使用Postman调试微信支付接口之前,你需要做好以下准备:安装客户端应用,或使用网页版;成为;已申请。当你已经具备这三个条件,就可以进入微信支付接口调试之旅了脚本导入方式一:通过fork方式为了帮助商户开发者快速上手,微信官方将调试微信支付接口
Wesley13 Wesley13
3年前
Oracle ADG究竟是否收费?
!(https://oscimg.oschina.net/oscnet/faaf5c218b3045fe9a38ffa00c48a996.png)前两天微信群中,有位朋友问了,OracleDatabaseStandardEdition11gR2标准版支持activedataguard么?可能平时
Stella981 Stella981
3年前
Chrome扩展推荐:微信变弹幕,追剧也不错过新消息
!(https://oscimg.oschina.net/oscnet/0d0a4825f8c04848a39a1b965e4a19f2.png)微信弹幕虽然微信网页版可以让用户在使用电脑上网时减少查看手机的频率,但不管是微信网页版还是PC客户端,都有它的不便之处。缺少了手机顶部通知栏类似的功能,我们在用电脑登陆微
Wesley13 Wesley13
3年前
h5 接入微信支付
我们公司,现在用ping做h5接入,用的是h5"壹收款"准备:如果公司,现在还没有公众号的话,支付宝。可以把这些工作,给ping来做这些事情 1.注册微信公众号,开通支付功能。2.注册ping (如果是自己开开通的微信支付,要填写相关信息)3.微信设置网页授权获取用户基本信
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
美凌格栋栋酱 美凌格栋栋酱
4个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
图形学
图形学
Lv1
爱情最初红了脸,最后红了眼。
文章
2
粉丝
0
获赞
0