import
re
import
time
import
uiautomation as automation
import
requests
import
hashlib
from
art
import
text2art
last_matched_info
=
None
SecretKey
=
'自己设置,例如:52pojie'
server_url
=
'https://域名/路径/Notify.php'
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):
timestamp_forsign
=
int
(time.mktime(time.strptime(timestamp,
"%Y-%m-%d %H:%M:%S"
)))
sign_str
=
f
"{SecretKey}{amount}{timestamp_forsign}"
signature
=
hashlib.md5(sign_str.encode(
'utf-8'
)).hexdigest()
try
:
response
=
requests.post(server_url, data
=
{
'amount'
: amount,
'sender'
: sender,
'timestamp'
: timestamp,
'signature'
: signature
})
print
(
"回调成功!持续监控中..."
)
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)}"
)
try
:
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
)
except
KeyboardInterrupt:
print
(
"\n收款监控服务已关闭!"
)
if
__name__
=
=
"__main__"
:
text
=
"liKeYunKeji"
ascii_art
=
text2art(text)
print
(ascii_art)
print
(
"-------------------------------------------------------"
)
print
(
"欢迎使用liKeYun微信赞赏码支付插件PC监控端"
)
print
(
"-------------------------------------------------------"
)
main()