fix: 俱乐部配置接口区分 V2 小程序密钥与 APIv3 密钥
返回 pay_config 说明实际支付生效字段,避免后台仅展示 api_v3_key 造成误导。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -428,6 +428,44 @@ class ClubManageView(APIView):
|
||||
'goeasy_appkey', 'goeasy_secret', 'sort_order',
|
||||
)
|
||||
|
||||
def _pay_config_meta(self, club):
|
||||
"""明确区分:小程序 V2 支付密钥 vs APIv3 密钥,避免后台误导。"""
|
||||
from jituan.services.wechat_pay import get_wechat_v2_config
|
||||
|
||||
cfg_json = club.config_json or {}
|
||||
mch_key = (cfg_json.get('mch_key') or cfg_json.get('shanghumiyao') or '').strip()
|
||||
api_v3 = (club.api_v3_key or '').strip()
|
||||
v2_cfg = get_wechat_v2_config(club.club_id)
|
||||
|
||||
warnings = []
|
||||
if not mch_key:
|
||||
warnings.append(
|
||||
'未配置 mch_key:小程序/会员/押金/点单等微信支付不会使用 api_v3_key,'
|
||||
'未填时将回落服务器 app_secrets 旧密钥,易与当前商户号不匹配导致签名错误。'
|
||||
)
|
||||
if mch_key and api_v3 and mch_key == api_v3:
|
||||
warnings.append(
|
||||
'mch_key 与 api_v3_key 内容相同:通常不正确,V2(小程序支付)与 V3(转账)是两套不同密钥。'
|
||||
)
|
||||
|
||||
return {
|
||||
'miniapp_wechat_v2_key': mch_key,
|
||||
'miniapp_wechat_v2_key_configured': bool(mch_key),
|
||||
'miniapp_wechat_v2_key_label': '小程序支付 APIv2 密钥 (mch_key)',
|
||||
'miniapp_wechat_v2_key_help': '微信商户平台 → API安全 → 设置APIv2密钥;用于会员/点单/押金/积分等 JSAPI 支付',
|
||||
'api_v3_key': api_v3,
|
||||
'api_v3_key_label': 'APIv3 密钥 (api_v3_key)',
|
||||
'api_v3_key_help': '仅用于微信 V3 接口(如转账到零钱),不用于小程序统一下单',
|
||||
'effective_miniapp_pay': {
|
||||
'club_id': v2_cfg.get('club_id'),
|
||||
'appid': v2_cfg.get('appid'),
|
||||
'mch_id': v2_cfg.get('mch_id'),
|
||||
'key_len': len(v2_cfg.get('key') or ''),
|
||||
'key_source': v2_cfg.get('_key_source'),
|
||||
},
|
||||
'warnings': warnings,
|
||||
}
|
||||
|
||||
def _serialize(self, club, full=False):
|
||||
base = {
|
||||
'club_id': club.club_id,
|
||||
@@ -444,10 +482,13 @@ class ClubManageView(APIView):
|
||||
}
|
||||
if full:
|
||||
cfg_json = club.config_json or {}
|
||||
mch_key = (cfg_json.get('mch_key') or cfg_json.get('shanghumiyao') or '').strip()
|
||||
base.update({
|
||||
'wx_secret': club.wx_secret,
|
||||
'api_v3_key': club.api_v3_key,
|
||||
'mch_key': cfg_json.get('mch_key') or cfg_json.get('shanghumiyao') or '',
|
||||
# 小程序 JSAPI 支付实际使用的 V2 密钥(与 api_v3_key 不是同一个)
|
||||
'mch_key': mch_key,
|
||||
'pay_config': self._pay_config_meta(club),
|
||||
'cert_serial_no': club.cert_serial_no,
|
||||
'private_key_path': club.private_key_path,
|
||||
'platform_cert_dir': club.platform_cert_dir,
|
||||
|
||||
Reference in New Issue
Block a user