feat: 新增交通银行数据导出插件及测试通道机制
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""xq0076 端到端验证:全新 profile 开浏览器 → 自动填账号 → 人工输密码 →
|
||||
自动处理政策页/跳过扫码 → 取票据 → 接口导出 → 下载解压。
|
||||
|
||||
用法(仓库根):
|
||||
.venv\\Scripts\\python.exe tests\\bankcomm_probe\\xq0076_e2e.py [账号] [导出日期 yyyy-MM-dd]
|
||||
默认账号 MER02797919、日期 2026-10-31。
|
||||
"""
|
||||
import datetime
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, os.path.join(REPO, 'plugins', 'XQ0001-0100'))
|
||||
sys.path.insert(0, os.path.join(REPO, 'desktop', 'electron-shell', 'python'))
|
||||
|
||||
PKG = 'XQ0076 交通银行数据导出'
|
||||
cfg = importlib.import_module(PKG + '.config')
|
||||
api = importlib.import_module(PKG + '.data.bank_api')
|
||||
exp = importlib.import_module(PKG + '.data.bank_export')
|
||||
lg = importlib.import_module(PKG + '.data.bank_login')
|
||||
|
||||
cfg.set_log(lambda m, lv='INFO': print(f'[{lv}] {m}', flush=True))
|
||||
cfg.set_debug(True)
|
||||
|
||||
account = sys.argv[1] if len(sys.argv) > 1 else 'MER02797919'
|
||||
day = sys.argv[2] if len(sys.argv) > 2 else '2026-10-31'
|
||||
d = datetime.datetime.strptime(day, '%Y-%m-%d').date()
|
||||
out_dir = os.path.join(REPO, 'logs', 'bankcomm_probe', 'e2e_out')
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
|
||||
print('=' * 70, flush=True)
|
||||
print('启动浏览器(独立 profile),请在弹出的窗口里输入密码', flush=True)
|
||||
print('=' * 70, flush=True)
|
||||
|
||||
page = lg.open_browser()
|
||||
page.get(cfg.LOGIN_URL)
|
||||
time.sleep(3)
|
||||
api.install_auth_hook(page)
|
||||
lg._fill_username(page, account)
|
||||
print('已填账号,等待你输入密码(最多 300 秒)…', flush=True)
|
||||
|
||||
|
||||
def pwd_ready():
|
||||
for el in page.eles('css:input[type="password"]'):
|
||||
try:
|
||||
if el.states.is_displayed and (el.value or '').strip():
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
deadline = time.time() + 300
|
||||
while time.time() < deadline:
|
||||
if pwd_ready():
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
if not pwd_ready():
|
||||
print('等待密码超时,退出', flush=True)
|
||||
try:
|
||||
page.quit()
|
||||
except Exception:
|
||||
pass
|
||||
sys.exit(1)
|
||||
|
||||
print('检测到密码已输入,提交登录…', flush=True)
|
||||
lg.click_button(page, cfg.TXT_LOGIN_BTN, timeout=8)
|
||||
ok = lg._login_flow(page)
|
||||
print('登录流程结果:', ok, flush=True)
|
||||
if not ok:
|
||||
try:
|
||||
page.quit()
|
||||
except Exception:
|
||||
pass
|
||||
sys.exit(1)
|
||||
|
||||
token = api.wait_token(page, timeout=60)
|
||||
print('票据长度:', len(token), flush=True)
|
||||
|
||||
t0 = time.time()
|
||||
try:
|
||||
result = exp.export_trade_flow(page, d, d, save_dir=out_dir,
|
||||
mcht_id='', mcht_acc=account)
|
||||
print('RESULT:', json.dumps(result, ensure_ascii=False, indent=2)[:1200], flush=True)
|
||||
except Exception as e:
|
||||
print('FAILED:', type(e).__name__, e, flush=True)
|
||||
try:
|
||||
page.quit()
|
||||
except Exception:
|
||||
pass
|
||||
sys.exit(1)
|
||||
print(f'耗时 {time.time() - t0:.1f}s', flush=True)
|
||||
|
||||
try:
|
||||
page.quit()
|
||||
except Exception:
|
||||
pass
|
||||
print('DONE', flush=True)
|
||||
Reference in New Issue
Block a user