feat: 收款与提现商户拆分,支持后台上传证书

收款仍用 mch_id/mch_key;提现优先 withdraw_mch_id(空则回落);证书分 pay/withdraw 目录落盘。退款逻辑未改。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-21 03:52:55 +08:00
parent 98b58f8058
commit 8e82a8457d
6 changed files with 328 additions and 16 deletions

View File

@@ -226,12 +226,20 @@ def get_wechat_v2_config(club_id=None):
cid, mch_id,
)
# 收款商户证书(供退款等对齐收款商户;未配时留空,调用方可回落 settings
pay_cert = _pick_club_field(club, cfg_json, 'pay_cert_path')
pay_key = _pick_club_field(club, cfg_json, 'pay_key_path')
return {
'appid': appid,
'mch_id': mch_id,
'key': mch_key,
'club_id': cid,
'_key_source': key_source,
# 明确标记:这是点单/会员收款商户
'merchant_role': 'pay',
'cert_path': pay_cert,
'key_path': pay_key,
}
@@ -378,16 +386,26 @@ def get_wechat_v3_config(club_id=None):
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', '')
# 提现商户号:优先 withdraw_mch_id空则回落收款 mch_id兼容旧数据
mch_id = (
_pick_club_field(club, cfg_json, 'withdraw_mch_id')
or _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 路径 + 同目录 apiclient_cert.pem
# 共用商户的俱乐部:默认用 settings 私钥;仅当库中路径存在且文件在盘上才覆盖
# (避免旧库里曾填过、但原先被忽略的无效路径突然接管提现)
private_key_path = path_defaults['PRIVATE_KEY_PATH']
if cid not in SHARED_WX_MERCHANT_CLUBS:
private_key_path = (
_pick_club_field(club, cfg_json, 'private_key_path')
or private_key_path
)
elif club:
uploaded_key = (getattr(club, 'private_key_path', None) or '').strip()
if uploaded_key and os.path.isfile(uploaded_key):
private_key_path = uploaded_key
platform_cert_dir = (
_pick_club_field(club, cfg_json, 'platform_cert_dir')
@@ -405,7 +423,10 @@ def get_wechat_v3_config(club_id=None):
# 序列号必须从与私钥配对的 apiclient_cert.pem 读取,禁止盲用数据库/写死值
cert_serial = resolve_merchant_cert_serial(private_key_path, '')
if not cert_serial:
cert_serial = xq.get('cert_serial_no', '')
cert_serial = (
_pick_club_field(club, cfg_json, 'cert_serial_no')
or xq.get('cert_serial_no', '')
)
cfg = {
'APPID': appid,
@@ -416,6 +437,7 @@ def get_wechat_v3_config(club_id=None):
'PLATFORM_CERT_DIR': platform_cert_dir,
'TRANSFER_SCENE_ID': transfer_scene_id,
'club_id': cid,
'merchant_role': 'withdraw',
}
_log_v3_config(cfg, source='club_db' if club else 'xq_fallback')
return cfg