feat: 新增交通银行数据导出插件及测试通道机制

This commit is contained in:
2026-11-05 15:20:34 +08:00
parent b976b80d9d
commit 4e8b3e7d43
230 changed files with 19827 additions and 1440 deletions
+66
View File
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""xq0076 接口版冒烟:复用已登录浏览器(9333),走纯接口导出。
用法:.venv\\Scripts\\python.exe tests\\bankcomm_probe\\xq0076_api_smoke.py [起] [止]
默认 2026-10-31(有 1 笔商户验券交易)。
"""
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'))
from DrissionPage import ChromiumPage
PKG = 'XQ0076 交通银行数据导出'
cfg = importlib.import_module(PKG + '.config')
api = importlib.import_module(PKG + '.data.bank_api')
exp = importlib.import_module(PKG + '.data.bank_export')
cfg.set_log(lambda m, lv='INFO': print(f'[{lv}] {m}', flush=True))
cfg.set_debug(True)
day = sys.argv[1] if len(sys.argv) > 1 else '2026-10-31'
d = datetime.datetime.strptime(day, '%Y-%m-%d').date()
out_dir = os.path.join(REPO, 'logs', 'bankcomm_probe', 'api_out')
os.makedirs(out_dir, exist_ok=True)
PORT = sys.argv[3] if len(sys.argv) > 3 else '9333'
page = ChromiumPage(f'127.0.0.1:{PORT}')
page.get(cfg.SITE_URL + '#/MENU30060101')
time.sleep(7)
print('URL', page.url, flush=True)
api.install_auth_hook(page)
# 触发一次页面请求以捕获 JWT
for b in page.eles('tag:button'):
try:
if b.states.is_displayed and ''.join((b.text or '').split()) == '查询':
b.click()
break
except Exception:
pass
time.sleep(5)
token = api.wait_token(page, timeout=60)
print('token 前 30:', token[:30], flush=True)
t0 = time.time()
try:
result = exp.export_trade_flow(page, d, d, save_dir=out_dir,
mcht_id='', mcht_acc='MER02797919')
print('RESULT:', json.dumps(result, ensure_ascii=False, indent=2)[:1500], flush=True)
except Exception as e:
print('FAILED:', type(e).__name__, e, flush=True)
sys.exit(1)
print(f'耗时 {time.time() - t0:.1f}s', flush=True)