176 lines
5.6 KiB
Python
176 lines
5.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""完整链路抓参数:汇总页设条件(门店全选+自定义日期+查询) → 商户验券「查看详情」
|
|
→ 流水页「导出」,捕获 0002 / 0012 / 0013 / downloadMchtFile 的明文参数。"""
|
|
import json
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
try:
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
except Exception:
|
|
pass
|
|
|
|
from DrissionPage import ChromiumPage
|
|
|
|
REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
OUT = os.path.join(REPO, 'logs', 'bankcomm_probe', 'export_api2.json')
|
|
SUMMARY = 'https://merchantapp.bankcomm.com/mm/#/MENU30060301'
|
|
DAY = '2026年10月31日'
|
|
|
|
|
|
def log(m):
|
|
print(f'[{time.strftime("%H:%M:%S")}] {m}', flush=True)
|
|
|
|
|
|
HOOK = r"""
|
|
window.__ev = [];
|
|
var K = window.KeyouCryptography;
|
|
var parse = K.util.UTF8.parse;
|
|
K.util.UTF8.parse = function(s) {
|
|
try {
|
|
var t = String(s);
|
|
if (t.length > 2 && (t.charAt(0) === '{' || t.charAt(0) === '[')) window.__ev.push({k:'plain', v:t.slice(0,1200)});
|
|
} catch(e){}
|
|
return parse.apply(this, arguments);
|
|
};
|
|
var op = XMLHttpRequest.prototype.open;
|
|
XMLHttpRequest.prototype.open = function(m,u){ this.__u=u; return op.apply(this, arguments); };
|
|
var sd = XMLHttpRequest.prototype.send;
|
|
XMLHttpRequest.prototype.send = function(b){
|
|
try { if (String(b).indexOf('plainText')===0) window.__ev.push({k:'req', url:String(this.__u||''), body:String(b).slice(0,120)}); } catch(e){}
|
|
return sd.apply(this, arguments);
|
|
};
|
|
var sh = XMLHttpRequest.prototype.setRequestHeader;
|
|
XMLHttpRequest.prototype.setRequestHeader = function(k,v){
|
|
try { if (String(k).toLowerCase()==='authorization') window.__auth=String(v); } catch(e){}
|
|
return sh.apply(this, arguments);
|
|
};
|
|
return 'ok';
|
|
"""
|
|
|
|
JS_MARK = r"""
|
|
var t = arguments[0];
|
|
var p = document.querySelector('.ant-calendar-picker-container');
|
|
if (!p || !p.offsetWidth) return 'no-panel';
|
|
var tds = [].slice.call(p.querySelectorAll('td[title]'));
|
|
for (var i=0;i<tds.length;i++){
|
|
if ((tds[i].getAttribute('title')||'')===t){ var o=document.getElementById('__pick_day__'); if(o)o.id=''; tds[i].id='__pick_day__'; return 'ok'; }
|
|
}
|
|
return 'not-found';
|
|
"""
|
|
|
|
JS_STEP = r"""
|
|
var d = arguments[0];
|
|
var p = document.querySelector('.ant-calendar-picker-container');
|
|
if (!p) return false;
|
|
var b = d === 'next' ? p.querySelector('.ant-calendar-next-month-btn') : p.querySelector('.ant-calendar-prev-month-btn');
|
|
if (b) { b.click(); return true; }
|
|
return false;
|
|
"""
|
|
|
|
page = ChromiumPage('127.0.0.1:9333')
|
|
page.get(SUMMARY)
|
|
time.sleep(7)
|
|
log(f'URL {page.url}')
|
|
page.run_js(HOOK)
|
|
|
|
# ① 门店全选
|
|
multi = page.ele('css:.ant-select-selection--multiple', timeout=10)
|
|
multi.click()
|
|
time.sleep(1.2)
|
|
for wrap in page.eles('css:.ant-select-dropdown .ant-checkbox-wrapper'):
|
|
try:
|
|
if '全选' in (wrap.text or ''):
|
|
inp = wrap.ele('css:input.ant-checkbox-input')
|
|
if not inp.states.is_checked:
|
|
inp.click()
|
|
log('已点全选')
|
|
break
|
|
except Exception:
|
|
pass
|
|
time.sleep(1)
|
|
try:
|
|
page.actions.click((900, 130))
|
|
except Exception:
|
|
pass
|
|
time.sleep(1)
|
|
|
|
# ② 自定义日期 + 选日期
|
|
for b in page.eles('tag:button'):
|
|
try:
|
|
if b.states.is_displayed and '自定义日期' in ''.join((b.text or '').split()):
|
|
b.click()
|
|
log('已点自定义日期')
|
|
break
|
|
except Exception:
|
|
pass
|
|
time.sleep(1.5)
|
|
|
|
for idx in (0, 1):
|
|
boxes = [e for e in page.eles('css:input.ant-calendar-picker-input') if e.states.is_displayed]
|
|
if len(boxes) < 2:
|
|
log('日期框不足')
|
|
break
|
|
boxes[idx].click()
|
|
time.sleep(1)
|
|
mark = page.run_js(JS_MARK, DAY)
|
|
n = 0
|
|
while mark == 'not-found' and n < 30:
|
|
page.run_js(JS_STEP, 'prev')
|
|
time.sleep(0.35)
|
|
n += 1
|
|
mark = page.run_js(JS_MARK, DAY)
|
|
if mark != 'ok':
|
|
log(f'日期框 {idx} 找不到 {DAY}')
|
|
break
|
|
el = page.ele('#__pick_day__', timeout=3)
|
|
el.click()
|
|
time.sleep(0.8)
|
|
page.run_js("var e=document.getElementById('__pick_day__'); if(e) e.id='';")
|
|
log('日期:' + page.run_js(
|
|
"var a=[].slice.call(document.querySelectorAll('input.ant-calendar-picker-input'));"
|
|
"return JSON.stringify(a.map(function(e){return e.value;}));"))
|
|
|
|
# ③ 查询
|
|
for b in page.eles('tag:button'):
|
|
try:
|
|
if b.states.is_displayed and ''.join((b.text or '').split()) == '查询':
|
|
b.click()
|
|
log('已点查询')
|
|
break
|
|
except Exception:
|
|
pass
|
|
time.sleep(6)
|
|
|
|
# ④ 点第 2 个「查看详情」(商户验券)
|
|
btns = [b for b in page.eles('css:button.onClickShowDetail') if b.states.is_displayed]
|
|
log(f'可见详情按钮 {len(btns)}')
|
|
if len(btns) >= 2:
|
|
btns[1].click()
|
|
log('已点商户验券查看详情')
|
|
time.sleep(7)
|
|
log(f'跳转后 URL {page.url}')
|
|
|
|
# ⑤ 导出
|
|
for b in page.eles('tag:button'):
|
|
try:
|
|
if b.states.is_displayed and ''.join((b.text or '').split()) == '导出':
|
|
b.click()
|
|
log('已点导出')
|
|
break
|
|
except Exception:
|
|
pass
|
|
time.sleep(20)
|
|
|
|
ev = page.run_js('return JSON.stringify(window.__ev||[])')
|
|
data = json.loads(ev) if ev else []
|
|
with open(OUT, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
log(f'捕获 {len(data)} 条 -> {OUT}')
|
|
for item in data:
|
|
if item.get('k') == 'req':
|
|
print(f"[REQ] {item.get('url')}", flush=True)
|
|
else:
|
|
print(f"[PLAIN] {item.get('v')[:500]}", flush=True)
|