共计 2617 个字符,预计需要花费 7 分钟才能阅读完成。
摘要
为什么要监听收款?那是因为当初还有人在应用微信的收款码、商业码、赞叹码实现免签领取,这类实现办法的最终计划还是监听收款后果。
技术原理
通过 Python 实时解析微信电脑版控件的文本内容来获取信息。不须要 Hook 和抓包,也不是走任何的协定,就是非常简单的界面信息获取和解析。
如何应用
- 登录电脑版微信;
- 找到微信领取公众号;
- 双击,让微信领取公众号独自显示,如下图;
- WxPayPcNotify.py 批改你的接管告诉的 Url;
- cmd 运行 WxPayPcNotify.py 即可开启监听。
接管领取后果告诉
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
正文完