fix: 微信扫码固定官方Native付款码,支持复制链接,去掉本机支付路径

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQueandCursor committed 2026-08-09 07:21:18 +08:00
1 parent ec08885eca
commit ef1da8b81a
2 files changed
+62 -363

No files matched your search

+4 -69
View File
@@ -652,80 +652,15 @@ def wx_native_pay_page(request):
class WxNativeScanPayView(APIView):
"""相册扫小程序码落地:用当前用户 openid 对未付款单做 JSAPI,直接出密码。"""
"""已废弃:现统一走 Native 付款码 + 复制链接,不再用小程序码落地支付。"""
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
def post(self, request):
from jituan.services.wechat_native_pay import (
build_mini_jsapi_pay_params,
get_native_pay_session,
resolve_scene_to_dingdanid,
)
scene = (request.data.get('scene') or '').strip()
dingdanid = (request.data.get('dingdanid') or request.data.get('out_trade_no') or '').strip()
if scene and not dingdanid:
dingdanid = resolve_scene_to_dingdanid(scene)
if not dingdanid:
return Response({'code': 400, 'message': '无效支付码'}, status=status.HTTP_400_BAD_REQUEST)
session = get_native_pay_session(dingdanid)
if not session:
return Response({'code': 400, 'message': '支付已过期,请返回重新发起'}, status=status.HTTP_400_BAD_REQUEST)
club_id = (session.get('club_id') or '').strip()
notify_url = (session.get('notify_url') or '').strip()
if not notify_url:
if dingdanid.startswith('CzHY'):
notify_url = getattr(settings, 'HUIYUAN_PAY_NOTIFY_URL', '')
elif dingdanid.startswith('CzYJ'):
notify_url = getattr(settings, 'YAJIN_PAY_NOTIFY_URL', '')
elif dingdanid.startswith('CzJF'):
notify_url = getattr(settings, 'JIFEN_PAY_NOTIFY_URL', '')
elif dingdanid.startswith('CzSJ'):
notify_url = getattr(settings, 'SHANGJIA_CZ_PAY_NOTIFY_URL', '')
elif dingdanid.startswith('FK'):
notify_url = getattr(settings, 'FAKUAN_PAY_NOTIFY_URL', '')
elif dingdanid.startswith('KH'):
notify_url = getattr(settings, 'KAOHE_PAY_NOTIFY_URL', '')
elif dingdanid.startswith('CzZP'):
notify_url = getattr(settings, 'ZHUANPAN_PAY_NOTIFY_URL', '')
else:
notify_url = getattr(settings, 'WEIXIN_NOTIFY_URL', '')
pay_openid, _ = get_payment_openid(request, club_id=club_id or None)
if not pay_openid:
return Response({
'code': 400,
'message': '当前小程序未绑定微信,请退出后重新登录再支付',
}, status=status.HTTP_400_BAD_REQUEST)
xff = request.META.get('HTTP_X_FORWARDED_FOR')
client_ip = (xff.split(',')[0].strip() if xff else '') or request.META.get('REMOTE_ADDR') or '127.0.0.1'
try:
pay_params = build_mini_jsapi_pay_params(
dingdanid=dingdanid,
jine=session.get('jine'),
body=session.get('body') or '微信支付',
notify_url=notify_url,
openid=pay_openid,
club_id=club_id or None,
client_ip=client_ip,
)
except Exception as exc:
logger.exception('小程序码扫码 JSAPI 下单失败 dingdan=%s', dingdanid)
return Response({
'code': 500,
'message': f'下单失败:{exc}',
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response({
'code': 200,
'message': 'ok',
'dingdanid': dingdanid,
'payParams': pay_params,
})
'code': 410,
'message': '请返回使用付款码扫码或复制支付链接支付',
}, status=status.HTTP_410_GONE)
class PaymentVerifyView(APIView):