From df416b8284351279281d0a676f8020595ee664bd Mon Sep 17 00:00:00 2001 From: XingQue Date: Fri, 10 Jul 2026 20:17:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=B1=E4=B9=90=E9=83=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8E=A5=E5=8F=A3=E5=8C=BA=E5=88=86=20V2=20=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=AF=86=E9=92=A5=E4=B8=8E=20APIv3=20?= =?UTF-8?q?=E5=AF=86=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 返回 pay_config 说明实际支付生效字段,避免后台仅展示 api_v3_key 造成误导。 Co-authored-by: Cursor --- jituan/views.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/jituan/views.py b/jituan/views.py index 6bb5102..0630833 100644 --- a/jituan/views.py +++ b/jituan/views.py @@ -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,