diff --git a/jituan/management/commands/wx_v3_pay_diag.py b/jituan/management/commands/wx_v3_pay_diag.py index 2497a0e..07efcad 100644 --- a/jituan/management/commands/wx_v3_pay_diag.py +++ b/jituan/management/commands/wx_v3_pay_diag.py @@ -19,7 +19,7 @@ class Command(BaseCommand): help = '诊断微信 V3 提现签名:私钥、证书序列号、商户号是否一致' def add_arguments(self, parser): - parser.add_argument('--club', default=CLUB_ID_DEFAULT, help='俱乐部 ID,默认 xq') + parser.add_argument('--club', default=CLUB_ID_DEFAULT, help='俱乐部 ID:xq 或 xzj') def handle(self, *args, **options): club_id = (options.get('club') or CLUB_ID_DEFAULT).strip() diff --git a/jituan/services/wechat_pay.py b/jituan/services/wechat_pay.py index 1bd7422..ceff180 100644 --- a/jituan/services/wechat_pay.py +++ b/jituan/services/wechat_pay.py @@ -20,6 +20,9 @@ XQ_WX_PAY = { 'wx_appid': 'wx0e4be86faac4a8d1', } +# 与星阙共用同一微信商户号/证书目录的俱乐部(AppID 各读各的 club 表) +SHARED_WX_MERCHANT_CLUBS = frozenset({CLUB_ID_DEFAULT, 'xzj'}) + # 兼容旧引用 WX_V3_CERT_SERIAL_NO_OVERRIDE = XQ_WX_PAY['cert_serial_no'] @@ -161,7 +164,7 @@ def _resolve_v2_mch_key(club, cfg_json, fallback_key, club_id=None): if val: return val, f'club.config_json.{field}' cid = (club_id or '').strip() or CLUB_ID_DEFAULT - if cid == CLUB_ID_DEFAULT and XQ_WX_PAY['mch_key']: + if cid in SHARED_WX_MERCHANT_CLUBS and XQ_WX_PAY['mch_key']: return XQ_WX_PAY['mch_key'], 'XQ_WX_PAY.mch_key' fb = (fallback_key or '').strip() if fb: @@ -209,9 +212,10 @@ def get_wechat_v2_config(club_id=None): cid, ) appid = '' + pay_fb = XQ_WX_PAY if cid in SHARED_WX_MERCHANT_CLUBS else {} mch_id = ( _pick_club_field(club, cfg_json, 'mch_id') - or (XQ_WX_PAY['mch_id'] if cid == CLUB_ID_DEFAULT else '') + or pay_fb.get('mch_id', '') or fallback['mch_id'] ) @@ -372,14 +376,14 @@ def get_wechat_v3_config(club_id=None): except Club.DoesNotExist: logger.warning('club %s 不存在,使用星阙兜底或路径默认', cid) - xq = XQ_WX_PAY if cid == CLUB_ID_DEFAULT else {} + xq = XQ_WX_PAY if cid in SHARED_WX_MERCHANT_CLUBS else {} mch_id = _pick_club_field(club, cfg_json, 'mch_id') or xq.get('mch_id', '') api_v3_key = _pick_club_field(club, cfg_json, 'api_v3_key') or xq.get('api_v3_key', '') - # 星阙私钥路径固定用 settings(club 表可能填了旧商户 1746545364 的证书路径) + # 共用商户的俱乐部:私钥/证书目录与星阙相同(settings 路径 + 同目录 apiclient_cert.pem) private_key_path = path_defaults['PRIVATE_KEY_PATH'] - if cid != CLUB_ID_DEFAULT: + if cid not in SHARED_WX_MERCHANT_CLUBS: private_key_path = ( _pick_club_field(club, cfg_json, 'private_key_path') or private_key_path @@ -395,8 +399,8 @@ def get_wechat_v3_config(club_id=None): ) appid = get_club_miniapp_appid(club) if club else '' - if not appid and cid == CLUB_ID_DEFAULT: - appid = xq.get('wx_appid', '') + if not appid and cid in SHARED_WX_MERCHANT_CLUBS: + appid = xq.get('wx_appid', '') if cid == CLUB_ID_DEFAULT else '' # 序列号必须从与私钥配对的 apiclient_cert.pem 读取,禁止盲用数据库/写死值 cert_serial = resolve_merchant_cert_serial(private_key_path, '')