refactor(tests): 探针脚本凭据改为从根 .env 读取,移除硬编码账号密码
- 新增 tests/_env.py:统一读仓库根 .env(仅标准库,进程内缓存) - tianque 探针 6 个脚本改读 tq_login_username / tq_login_password,account.json 仅兜底 - workflows/share/erp_login.py 的 __main__ 去掉硬编码 ERP 账号密码(改由 .env 提供) - docs/需求单/README.md 的负责人手机号做脱敏
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"""天阙会生活商户平台(mch-web.tianquetech.com)接口登录联调脚本。
|
||||
|
||||
用法:
|
||||
1. 在下面「配置区」填 ACCOUNT / PASSWORD(也可写在同目录 account.json)
|
||||
1. 在仓库根 `.env` 配置 `tq_login_username` / `tq_login_password`
|
||||
(也可写在同目录 account.json,作为兜底)
|
||||
2. 运行:d:\\work\\code\\37duAutomation\\.venv\\Scripts\\python.exe tests/tianque_probe/tianque_login_test.py
|
||||
|
||||
流程:imageCode 取图(imageKey + captchaBase64)→ ddddocr 识别(同一 imageKey 只能用一次)
|
||||
@@ -41,8 +42,12 @@ if hasattr(sys.stdout, "reconfigure"):
|
||||
pass
|
||||
|
||||
# ==================== 配置区 ====================
|
||||
ACCOUNT = "***REMOVED***" # 663 账号或手机号
|
||||
PASSWORD = "***REMOVED***" # 登录密码(明文,脚本内部加密)
|
||||
# 账号密码只放仓库根 .env(已 gitignore,不入库):tq_login_username / tq_login_password
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from _env import get as _env_get # noqa: E402
|
||||
|
||||
ACCOUNT = _env_get("tq_login_username") # 663 账号或手机号
|
||||
PASSWORD = _env_get("tq_login_password") # 登录密码(明文,脚本内部加密)
|
||||
MAX_ATTEMPTS = 5 # 提交轮次上限(服务端不区分验证码错/密码错,只能换图重试)
|
||||
SAVE_TOKEN = True # 登录成功后把用户信息落到临时文件,便于后续接口联调
|
||||
VERIFY_TOKEN = True # 登录成功后调用一次交易汇总接口验证 token 是否可用
|
||||
@@ -81,6 +86,10 @@ if os.path.exists(_ACC_FILE):
|
||||
except Exception as exc: # 配置写坏不应阻断,直接提示
|
||||
print(f"读取 account.json 失败:{exc}")
|
||||
|
||||
if not ACCOUNT or not PASSWORD:
|
||||
raise SystemExit("未取到天阙账号密码:请在仓库根 .env 配置 "
|
||||
"tq_login_username / tq_login_password(或同目录 account.json)")
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(f"[{datetime.now():%H:%M:%S}] {msg}", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user