From c6ad63e8bc834f8c0ceb222ed6172953541ddd3d Mon Sep 17 00:00:00 2001 From: yixian Date: Sun, 26 Sep 2021 13:57:09 +0800 Subject: [PATCH] aps jsapi gateway --- .../templates/alipay/v1/gateway_jsapi.js | 4 +- .../templates/alipayaps/v1/gateway_jsapi.js | 73 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/main/ui/static/templates/alipayaps/v1/gateway_jsapi.js diff --git a/src/main/ui/static/templates/alipay/v1/gateway_jsapi.js b/src/main/ui/static/templates/alipay/v1/gateway_jsapi.js index dddac6e4e..d2e791774 100644 --- a/src/main/ui/static/templates/alipay/v1/gateway_jsapi.js +++ b/src/main/ui/static/templates/alipay/v1/gateway_jsapi.js @@ -57,9 +57,9 @@ $(document).ready(function () { } else { // 如果没有注入则监听注入的事件 document.addEventListener('AlipayJSBridgeReady', function () { - + callPayment(pay.trade_no); }); - callPayment(pay.trade_no); + } }, diff --git a/src/main/ui/static/templates/alipayaps/v1/gateway_jsapi.js b/src/main/ui/static/templates/alipayaps/v1/gateway_jsapi.js new file mode 100644 index 000000000..c88db1939 --- /dev/null +++ b/src/main/ui/static/templates/alipayaps/v1/gateway_jsapi.js @@ -0,0 +1,73 @@ +$(document).ready(function (){ + + decode(); + + function decode() { + if (window.client_moniker == 'PINE') { + alert('debug:origin redirect:' + window.redirect); + } + let redirect = window.redirect; + if (window.redirect !=null) { + while (redirect.indexOf('://') < 0) { + redirect = decodeURIComponent(redirect); + if (redirect == window.redirect) { + break; + } + window.redirect = redirect; + } + } + + } + + let dataCache = {paying: false}; + $('#key_P').bind('touchstart', startPay); + function startPay() { + $('#wdiv').show(); + if (dataCache.paying) { + return; + } + dataCache.paying = true; + + $.ajax({ + url: './preorder', + method: 'GET', + dataType: 'json', + success: function (pay) { + if (pay.direct_paid) { + startCheckOrder(window.client_moniker, window.merchant_orderid); + return; + } + if (pay.mweb_url){ + location.href = pay.mweb_url + } + + }, + error: function (jqXhr) { + alert(jqXhr.responseJSON.message); + $('#wdiv').hide(); + dataCache.paying = false; + } + }) + + + } + + function startCheckOrder(clientMoniker, merchantOrderId) { + function checkOrderStd() { + $.ajax({ + url: '/api/v1.0/payment/clients/' + clientMoniker + '/orders/' + merchantOrderId + '/status', + method: 'GET', + dataType: 'json', + success: function (res) { + if (res.paid) { + location.href = window.redirect + (window.redirect.indexOf('?') < 0 ? '?' : '&') + 'success=true&time=' + res.time + '&nonce_str=' + res.nonce_str + '&sign=' + res.sign; + } else { + setTimeout(checkOrderStd, 500); + } + } + }) + } + + checkOrderStd(); + } +}) \ No newline at end of file