<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="">
    <meta name="HandheldFriendly" content="true">
    <meta name="format-detection" content="telephone=no">
    <script src="/wap/resources/js/jquery.min.js"></script>
    <script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"></script>
</head>
<body>
<input type="hidden" id="orderNumber" name="orderNumber" th:value="${orderNumber}">
<input type="hidden" id="appId" name="appId" th:value="${appId}">
<script>
    $(function() {
        if (/AlipayClient/.test(window.navigator.userAgent)) {
            // let $url = "/wap/aliPay/getAuthOpenId";
            let orderNumber = $("#orderNumber").val();
            let $payUrl = "/wap/aliPay/orderPay"
            let $appid = $("#appId").val();
            if(!$appid){
                $appid = "2019092967932477";
            }
            ap.showLoading({
                content: '加载中...'
            });
            ap.getAuthCode({
                appId: $appid,
                scopes: ['auth_base'],
            }, function(res) {
                let authCode = res.authCode;
                $.post($payUrl,{"authCode":authCode,"orderNumber":orderNumber},function (res){
                    ap.hideLoading();
                    if(res.code != 200){
                        ap.alert({title: '提示',content: res.message,buttonText: '确定'});
                        return;
                    }else{
                        ap.tradePay({
                            tradeNO : res.data.source
                        }, function(res) {
                            AlipayJSBridge.call('closeWebview');
                        });
                    }
                })
            });
        }
    })
</script>
</body>
</html>