💳 applyPay — 扫码支付对接

POST /pay/applyPay
发起支付
接口对接源码(可直接复制)
HTML · 完整扫码支付页面
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>扫码支付</title>
  <style>
    .pay-box { text-align: center; padding: 40px; }
    .pay-box img { max-width: 200px; }
    .pay-box iframe { width: 100%; height: 300px; border: 1px solid #ddd; border-radius: 4px; }
    .order-no { color: #999; font-size: 14px; margin-top: 10px; }
  </style>
</head>
<body>
  <div class="pay-box">
    <h2>请扫码支付</h2>
    <div id="qrcode"></div>
    <div class="order-no" id="orderNo"></div>
    <div class="order-no" id="status"></div>
  </div>

  <script>
    async function loadQrCode() {
      const res = await fetch('/pay/applyPay', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer <your-token>',
        },
        body: JSON.stringify({
          planId: 1,
          payChannel: 'ALIPAY',
          licenseKey: 'your-license-key',
          couponCode: '',
          callbackUrl: '',
        }),
      });
      const result = await res.json();
      if (result.success && result.data) {
        const container = document.getElementById('qrcode');
        const { imgVo, webPayHtml, orderNo, payTradeStatusStr } = result.data;

        // 方式 1: base64 二维码图片
        if (imgVo && imgVo.srcBase64) {
          container.innerHTML = '<img src="data:image/png;base64,' + imgVo.srcBase64 + '" />';
        }

        // 方式 2: 支付宝返回的 HTML 表单 → iframe 渲染
        if (webPayHtml) {
          const blob = new Blob([webPayHtml], { type: 'text/html' });
          const url = URL.createObjectURL(blob);
          container.innerHTML = '<iframe src="' + url + '" sandbox="allow-forms allow-scripts allow-top-navigation allow-same-origin"></iframe>';
        }

        document.getElementById('orderNo').innerText = '订单号: ' + orderNo;
        document.getElementById('status').innerText = '状态: ' + payTradeStatusStr;
      } else {
        alert('支付请求失败: ' + (result.msg || '未知错误'));
      }
    }
    loadQrCode();
  </script>
</body>
</html>
✅ 已复制到剪贴板