修复 URL 过长的问题
This commit is contained in:
@@ -461,6 +461,11 @@ def alipay_pay_page(request):
|
||||
pay_url = request.GET.get('pay_url', '')
|
||||
out_trade_no = request.GET.get('out_trade_no', '')
|
||||
|
||||
# 优先从 cache 取 pay_url(前端传订单号,避免 URL 过长)
|
||||
if not pay_url and out_trade_no:
|
||||
cache_key = f'alipay_pay_url_{out_trade_no}'
|
||||
pay_url = cache.get(cache_key) or ''
|
||||
|
||||
if pay_url:
|
||||
# 中转模式:自动跳转到支付宝
|
||||
return render(request, 'alipay/pay.html', {'pay_url': pay_url})
|
||||
@@ -1078,8 +1083,8 @@ class CreateOrderView(APIView):
|
||||
|
||||
def generate_alipay_pay_params(self, dingdanid, jine, subject, club_id=None):
|
||||
"""
|
||||
生成支付宝 wap.pay 跳转 URL。
|
||||
返回前端用于 web-view 加载的支付参数。
|
||||
生成支付宝 wap.pay 跳转 URL,存入 cache 供中转页取用。
|
||||
前端只需传订单号构造短 URL,避免 web-view src URL 过长被拒。
|
||||
"""
|
||||
try:
|
||||
from jituan.services.alipay_pay import build_wap_pay_url
|
||||
@@ -1089,8 +1094,10 @@ class CreateOrderView(APIView):
|
||||
subject=subject,
|
||||
club_id=club_id,
|
||||
)
|
||||
# 存入 cache,30 分钟过期(与支付宝订单超时一致)
|
||||
cache_key = f'alipay_pay_url_{dingdanid}'
|
||||
cache.set(cache_key, pay_url, 60 * 30)
|
||||
return {
|
||||
'pay_url': pay_url,
|
||||
'pay_method': 'alipay',
|
||||
}
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user