fix: 加固支付宝充值回调幂等履约,避免付成功不到账与误删单

禁止 Czjilu 回调地址回落到订单 notify;回调失败回 fail 重试;取消支付改关单不删;客服补单走同一履约防多加。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-20 22:59:59 +08:00
parent 48d2e13037
commit 1ab59efddb
13 changed files with 283 additions and 106 deletions

View File

@@ -33,22 +33,43 @@ def get_alipay_config(club_id=None):
else:
cfg = getattr(settings, 'ALIPAY_PROD', {})
# 注意NOTIFY_URL_CZJILU 不得静默回落到订单 NOTIFY_URL否则充值回调会打进订单回调被吞掉
czjilu_notify = (cfg.get('NOTIFY_URL_CZJILU') or '').strip()
order_notify = (cfg.get('NOTIFY_URL') or '').strip()
return {
'APP_ID': cfg.get('APP_ID', ''),
'PID': cfg.get('PID', ''),
'APP_PRIVATE_KEY': cfg.get('APP_PRIVATE_KEY', ''),
'ALIPAY_PUBLIC_KEY': cfg.get('ALIPAY_PUBLIC_KEY', ''),
'GATEWAY': cfg.get('GATEWAY', 'https://openapi.alipay.com/gateway.do'),
'NOTIFY_URL': cfg.get('NOTIFY_URL', ''),
'NOTIFY_URL_CZJILU': cfg.get('NOTIFY_URL_CZJILU', '') or cfg.get('NOTIFY_URL', ''),
'NOTIFY_URL': order_notify,
'NOTIFY_URL_CZJILU': czjilu_notify,
'RETURN_URL': cfg.get('RETURN_URL', ''),
'sandbox': sandbox,
}
def get_czjilu_notify_url(club_id=None):
"""获取 Czjilu 类充值(押金/积分/会员/商家/考核/罚款)的支付宝异步回调地址。"""
return get_alipay_config(club_id)['NOTIFY_URL_CZJILU']
"""获取 Czjilu 类充值的支付宝异步回调地址;未单独配置则抛错,禁止回落到订单回调"""
cfg = get_alipay_config(club_id)
notify_url = (cfg.get('NOTIFY_URL_CZJILU') or '').strip()
if not notify_url:
raise Exception(
'支付宝配置缺少 NOTIFY_URL_CZJILU须指向 /shangpin/alipay-czjilu-notify/'
'禁止使用订单回调地址,否则充值到账会失败'
)
order_notify = (cfg.get('NOTIFY_URL') or '').strip()
if order_notify and notify_url.rstrip('/') == order_notify.rstrip('/'):
raise Exception(
'NOTIFY_URL_CZJILU 不能与订单 NOTIFY_URL 相同,'
'请配置为 .../shangpin/alipay-czjilu-notify/'
)
if 'alipay-czjilu-notify' not in notify_url:
logger.warning(
'NOTIFY_URL_CZJILU=%s 未包含 alipay-czjilu-notify请确认是否配错',
notify_url,
)
return notify_url
def generate_alipay_czjilu_pay_params(dingdanid, jine, subject, club_id=None, expire_minutes=30):