pay_alipay_wap.html 2.08 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
    <title>支付测试页</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<div>点击如下按钮,发起支付的测试</div>
<div>
    <button id="alipay_wap">支付宝手机网站支付</button>
</div>
<div id="dynamic_form"></div>
</body>
<script>

    let shopOrderId = undefined;
    let payOrderId = undefined;
     let server = 'http://127.0.0.1:48080';
    //let server = 'http://niubi.natapp1.cc';

    $(function() {
        // 自动发起商城订单编号
        $.ajax({
            url: server + "/app-api/shop/order/create",
            method: 'POST',
            success: function( result ) {
                if (result.code !== 0) {
                    alert('创建商城订单失败,原因:' + result.msg)
                    return;
                }
                shopOrderId = result.data.id;
                payOrderId = result.data.payOrderId;
                console.log("商城订单:" + shopOrderId)
                console.log("支付订单:" + payOrderId)
            }
        })
    });

    $( "#alipay_wap").on( "click", function() {
        // 提交支付
        $.ajax({
            url: server + "/app-api/pay/order/submit",
            method: 'POST',
            dataType: "json",
            contentType: "application/json",
            data: JSON.stringify({
                "id": payOrderId,
                "channelCode": 'alipay_wap'
            }),
            success: function( result ) {
                if (result.code !== 0) {
                    alert('提交支付订单失败,原因:' + result.msg)
                    return;
                }
                alert('点击确定,开始支付');
                //支付宝 手机WAP 返回表单,自动跳到支付宝支付页面
                let data = result.data.invokeResponse;
                $("#dynamic_form").html(data.body);
            }
        })
    });
</script>
</html>