aps jsapi gateway

master
yixian 3 years ago
parent 732ec9f8e2
commit c6ad63e8bc

@ -57,9 +57,9 @@ $(document).ready(function () {
} else { } else {
// 如果没有注入则监听注入的事件 // 如果没有注入则监听注入的事件
document.addEventListener('AlipayJSBridgeReady', function () { document.addEventListener('AlipayJSBridgeReady', function () {
});
callPayment(pay.trade_no); callPayment(pay.trade_no);
});
} }
}, },

@ -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();
}
})
Loading…
Cancel
Save