使用二维码进行支付宝交易
This commit is contained in:
@@ -969,6 +969,13 @@ class CreateOrderView(APIView):
|
||||
KEY = pay_cfg['key']
|
||||
NOTIFY_URL = getattr(settings, 'WEIXIN_NOTIFY_URL', '')
|
||||
|
||||
# NOAUTH 诊断日志:打印生效的 club_id / appid / mchid / openid 指纹
|
||||
_oid_preview = (openid or '')[:6] + '...' + (openid or '')[-4:] if (openid or '') else '(empty)'
|
||||
logger.warning(
|
||||
"[WX_PAY_NOAUTH_DIAG] dingdanid=%s club_id=%s appid=%s mch_id=%s openid_preview=%s openid_len=%d",
|
||||
dingdanid, club_id, APPID, MCHID, _oid_preview, len(openid or ''),
|
||||
)
|
||||
|
||||
if not all([APPID, MCHID, KEY, NOTIFY_URL]):
|
||||
raise Exception('微信支付配置不完整')
|
||||
|
||||
@@ -1029,6 +1036,7 @@ class CreateOrderView(APIView):
|
||||
)
|
||||
|
||||
# 解析返回的XML
|
||||
logger.warning("[WX_PAY_NOAUTH_DIAG] wechat_raw_response=%s", response.content.decode('utf-8', errors='replace'))
|
||||
root = ET.fromstring(response.content)
|
||||
|
||||
return_code = root.find('return_code').text
|
||||
@@ -1087,22 +1095,23 @@ class CreateOrderView(APIView):
|
||||
|
||||
def generate_alipay_pay_params(self, dingdanid, jine, subject, club_id=None):
|
||||
"""
|
||||
生成支付宝 wap.pay 跳转 URL,存入 cache 供中转页取用。
|
||||
同时返回 pay_url 供前端直接加载(绕过中转页跳转限制)。
|
||||
生成支付宝当面付二维码支付参数。
|
||||
返回 qr_image(base64 PNG)供前端 image 直接展示,用户用支付宝扫码支付。
|
||||
适用于微信小程序 web-view 无法跳转 alipay:// scheme 的场景。
|
||||
"""
|
||||
try:
|
||||
from jituan.services.alipay_pay import build_wap_pay_url
|
||||
pay_url = build_wap_pay_url(
|
||||
from jituan.services.alipay_pay import build_precreate_qr, qr_link_to_base64
|
||||
result = build_precreate_qr(
|
||||
out_trade_no=dingdanid,
|
||||
amount=jine,
|
||||
subject=subject,
|
||||
club_id=club_id,
|
||||
)
|
||||
# 存入 cache,30 分钟过期(供中转页/查询接口判断支付方式)
|
||||
cache_key = f'alipay_pay_url_{dingdanid}'
|
||||
cache.set(cache_key, pay_url, 60 * 30)
|
||||
qr_code = result['qr_code']
|
||||
qr_image = qr_link_to_base64(qr_code)
|
||||
return {
|
||||
'pay_url': pay_url,
|
||||
'qr_code': qr_code,
|
||||
'qr_image': qr_image,
|
||||
'pay_method': 'alipay',
|
||||
}
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user