fix: 使用请求 Host 头动态构建 notify_url + 迁移文档/测试
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
根因:base_url 默认硬编码为 dev.xmclassmate.top,导致支付宝通知回调 (notify_url)指向开发服务器,RSA2 签名验证失败,订单延迟 12 分钟。 修复: - 新增 get_base_url():优先用 APP_BASE_URL 环境变量,否则从请求 Host 头获取当前域名,确保 notify_url 始终指向正确的服务器 - 生产 .env 已设置 APP_BASE_URL=https://xmclassmate.top - .env.example 新增 APP_BASE_URL 文档 迁移文档: - SERVER-MIGRATION-PLAN.md 新增阶段 3 关键配置章节 - 12 项迁移检查清单 + 历史问题复盘 部署测试: - test.sh 新增 test_notify_url_domain:校验支付表单 notify_url 域名与 BASE_URL 一致,迁移后自动捕获配置错误
This commit is contained in:
39
lib/test.sh
39
lib/test.sh
@@ -471,6 +471,44 @@ test_nginx_proxy_temp() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# ---------- 支付 notify_url 校验 ----------
|
||||
|
||||
test_notify_url_domain() {
|
||||
log_info "校验支付表单 notify_url 域名..."
|
||||
local domain
|
||||
domain=$(echo "$BASE_URL" | sed 's|https://||' | sed 's|http://||' | sed 's|/||g')
|
||||
|
||||
# 获取访客 JWT
|
||||
local jwt
|
||||
jwt=$(remote "curl -sk -X POST '${BASE_URL}/api/guest-login'" 2>/dev/null | python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" 2>/dev/null)
|
||||
if [ -z "$jwt" ]; then
|
||||
log_error "获取 JWT 失败,无法校验 notify_url"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 提取支付表单的 notify_url
|
||||
local notify_url
|
||||
notify_url=$(remote "curl -sk '${BASE_URL}/payment/page?package=monthly&jwt=${jwt}'" 2>/dev/null | grep -oP 'notify_url" value="\K[^"]+' | head -1)
|
||||
|
||||
if [ -z "$notify_url" ]; then
|
||||
log_error "无法提取 notify_url(可能为 Mock 支付模式)"
|
||||
return 0 # Mock 模式下不校验
|
||||
fi
|
||||
|
||||
# 检查 notify_url 的域名是否与 BASE_URL 一致
|
||||
local notify_domain
|
||||
notify_domain=$(echo "$notify_url" | sed 's|https://||' | sed 's|http://||' | sed 's|/payment/notify||')
|
||||
|
||||
if [ "$notify_domain" != "$domain" ]; then
|
||||
log_error "notify_url 域名不匹配: 表单=${notify_domain}, 期望=${domain}"
|
||||
log_error "请检查 APP_BASE_URL 配置"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info " notify_url 域名 ${notify_domain} ✅"
|
||||
return 0
|
||||
}
|
||||
|
||||
# ---------- 主测试入口 ----------
|
||||
run_tests() {
|
||||
log_step "执行部署后测试..."
|
||||
@@ -493,6 +531,7 @@ run_tests() {
|
||||
"test_payment_maintenance:维护模式"
|
||||
"test_payment_refund:退款+会员撤销"
|
||||
"test_payment_verify_detection:验证函数检测逻辑"
|
||||
"test_notify_url_domain:支付回调域名校验"
|
||||
)
|
||||
local i=1 total=${#tests[@]}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user