feat: club 表独立 mch_key 字段,后台明确区分 APIv2 收款与 APIv3 提现
- 新增 club.mch_key 列并迁移 config_json 历史数据,api_v3_key 保持独立 - club-manage 读写 mch_key;支付读 club.mch_key 优先,兼容 config_json 回落 - 提现查单返回商户号改读俱乐部 V3 配置;不影响其他业务逻辑 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -450,31 +450,47 @@ class ClubManageView(APIView):
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
_EDITABLE_FIELDS = (
|
||||
'name', 'status', 'wx_appid', 'wx_secret', 'mch_id', 'pay_app_id', 'api_v3_key',
|
||||
'name', 'status', 'wx_appid', 'wx_secret', 'mch_id', 'pay_app_id',
|
||||
'mch_key', 'api_v3_key',
|
||||
'cert_serial_no', 'private_key_path', 'platform_cert_dir',
|
||||
'official_appid', 'official_secret', 'official_token', 'encoding_aes_key',
|
||||
'template_id', 'template_max_per_minute', 'h5_domain', 'oss_prefix',
|
||||
'goeasy_appkey', 'goeasy_secret', 'sort_order',
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _effective_mch_key(club):
|
||||
cfg_json = club.config_json or {}
|
||||
return (
|
||||
(club.mch_key or '').strip()
|
||||
or (cfg_json.get('mch_key') or '').strip()
|
||||
or (cfg_json.get('shanghumiyao') or '').strip()
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _sync_mch_key_to_config_json(club, mch_key):
|
||||
cfg = dict(club.config_json or {})
|
||||
cfg['mch_key'] = (mch_key or '').strip()
|
||||
club.config_json = cfg
|
||||
|
||||
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()
|
||||
mch_key = self._effective_mch_key(club)
|
||||
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,'
|
||||
'未配置 APIv2 密钥 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(转账)是两套不同密钥。'
|
||||
'mch_key 与 api_v3_key 内容相同:通常不正确,V2(小程序支付)与 V3(提现转账)是两套不同密钥。'
|
||||
)
|
||||
wx_a = (club.wx_appid or '').strip()
|
||||
pay_a = (club.pay_app_id or '').strip()
|
||||
@@ -490,13 +506,17 @@ class ClubManageView(APIView):
|
||||
)
|
||||
|
||||
return {
|
||||
'mch_key': mch_key,
|
||||
'mch_key_label': 'APIv2 密钥 (mch_key)',
|
||||
'mch_key_help': '微信商户平台 → API安全 → 设置APIv2密钥;用于会员/点单/押金/积分等 JSAPI 收款',
|
||||
'mch_key_configured': bool(mch_key),
|
||||
'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 支付',
|
||||
'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 接口(如转账到零钱),不用于小程序统一下单',
|
||||
'api_v3_key_help': '微信商户平台 → API安全 → 设置APIv3密钥;仅用于自动提现/转账回调解密,不用于小程序收款',
|
||||
'effective_miniapp_pay': {
|
||||
'club_id': v2_cfg.get('club_id'),
|
||||
'appid': v2_cfg.get('appid'),
|
||||
@@ -522,13 +542,11 @@ class ClubManageView(APIView):
|
||||
'sort_order': club.sort_order,
|
||||
}
|
||||
if full:
|
||||
cfg_json = club.config_json or {}
|
||||
mch_key = (cfg_json.get('mch_key') or cfg_json.get('shanghumiyao') or '').strip()
|
||||
mch_key = self._effective_mch_key(club)
|
||||
base.update({
|
||||
'wx_secret': club.wx_secret,
|
||||
'api_v3_key': club.api_v3_key,
|
||||
# 小程序 JSAPI 支付实际使用的 V2 密钥(与 api_v3_key 不是同一个)
|
||||
'mch_key': mch_key,
|
||||
'api_v3_key': club.api_v3_key,
|
||||
'pay_config': self._pay_config_meta(club),
|
||||
'cert_serial_no': club.cert_serial_no,
|
||||
'private_key_path': club.private_key_path,
|
||||
@@ -576,12 +594,13 @@ class ClubManageView(APIView):
|
||||
update_fields = []
|
||||
for field in self._EDITABLE_FIELDS:
|
||||
if field in request.data:
|
||||
setattr(club, field, request.data[field])
|
||||
val = request.data[field]
|
||||
if field in ('mch_key', 'api_v3_key', 'wx_secret'):
|
||||
val = (val or '').strip()
|
||||
setattr(club, field, val)
|
||||
update_fields.append(field)
|
||||
if 'mch_key' in request.data:
|
||||
cfg = dict(club.config_json or {})
|
||||
cfg['mch_key'] = (request.data.get('mch_key') or '').strip()
|
||||
club.config_json = cfg
|
||||
self._sync_mch_key_to_config_json(club, request.data.get('mch_key'))
|
||||
if 'config_json' not in update_fields:
|
||||
update_fields.append('config_json')
|
||||
if update_fields:
|
||||
|
||||
Reference in New Issue
Block a user