From 302fc69a762de458e9305ce36e5058a204199c54 Mon Sep 17 00:00:00 2001 From: dalong306 <304592994@qq.com> Date: Wed, 19 Jan 2022 14:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E7=A0=81=20aps=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20=E7=BA=BF=E4=B8=8A=E7=BA=BF=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/templates/alipayaps/v1/payment.js | 43 ++++++++++++++++++ .../static/templates/alipayaps/v4/payment.js | 44 +++++++++++++++++++ .../static/templates/alipayaps/v5/payment.js | 43 ++++++++++++++++++ 3 files changed, 130 insertions(+) diff --git a/src/main/ui/static/templates/alipayaps/v1/payment.js b/src/main/ui/static/templates/alipayaps/v1/payment.js index 0a49f9143..d28df875c 100644 --- a/src/main/ui/static/templates/alipayaps/v1/payment.js +++ b/src/main/ui/static/templates/alipayaps/v1/payment.js @@ -264,6 +264,10 @@ $(function () { contentType: 'application/json', dataType: 'json', success: function (pay) { + if (pay.jsapi) { + callAlipayAps(pay); + return; + } if (pay.direct_paid) { location.href = '/api/v1.0/alipay_aps/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result'; return; @@ -441,4 +445,43 @@ $(function () { } } + function callApp(scheme_seq, index, timeout) { + let timer, start = new Date().getTime() + let promise = new Promise(((resolve, reject) => { + location.href = scheme_seq[index] + window.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'hidden') { + clearTimeout(timer); + resolve() + } + }); + timer = setTimeout(() => { + let end = new Date().getTime() + if (end - start > timeout + 1000) { + clearTimeout(timer) + resolve() + } else { + if (index + 1 < scheme_seq.length) { + callApp(scheme_seq, index + 1, timeout).then(resolve, reject) + } else { + reject() + } + } + }, timeout) + })) + return promise + } + function callAlipayAps(order) { + if(order.jsapi){ + let try_sequence = [order.jsapi.scheme_url, order.jsapi.applink_url, order.jsapi.normal_url] + try_sequence = try_sequence.filter(v => v != null) + callApp(try_sequence, 0, 5000).then(() => { + alert('redirect success') + }, () => { + alert('redirect failure') + }) + }else { + location.href = order.web_url + } + } }); diff --git a/src/main/ui/static/templates/alipayaps/v4/payment.js b/src/main/ui/static/templates/alipayaps/v4/payment.js index be2d64c9a..536543928 100644 --- a/src/main/ui/static/templates/alipayaps/v4/payment.js +++ b/src/main/ui/static/templates/alipayaps/v4/payment.js @@ -309,6 +309,10 @@ $(function () { contentType: 'application/json', dataType: 'json', success: function (pay) { + if (pay.jsapi) { + callAlipayAps(pay); + return; + } if (pay.direct_paid) { location.href = '/api/v1.0/alipay_aps/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result'; return; @@ -485,4 +489,44 @@ $(function () { } } + function callApp(scheme_seq, index, timeout) { + let timer, start = new Date().getTime() + let promise = new Promise(((resolve, reject) => { + location.href = scheme_seq[index] + window.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'hidden') { + clearTimeout(timer); + resolve() + } + }); + timer = setTimeout(() => { + let end = new Date().getTime() + if (end - start > timeout + 1000) { + clearTimeout(timer) + resolve() + } else { + if (index + 1 < scheme_seq.length) { + callApp(scheme_seq, index + 1, timeout).then(resolve, reject) + } else { + reject() + } + } + }, timeout) + })) + return promise + } + function callAlipayAps(order) { + if(order.jsapi){ + let try_sequence = [order.jsapi.scheme_url, order.jsapi.applink_url, order.jsapi.normal_url] + try_sequence = try_sequence.filter(v => v != null) + callApp(try_sequence, 0, 5000).then(() => { + alert('redirect success') + }, () => { + alert('redirect failure') + }) + }else { + location.href = order.web_url + } + } + }); diff --git a/src/main/ui/static/templates/alipayaps/v5/payment.js b/src/main/ui/static/templates/alipayaps/v5/payment.js index 759356aff..6814cc8ee 100644 --- a/src/main/ui/static/templates/alipayaps/v5/payment.js +++ b/src/main/ui/static/templates/alipayaps/v5/payment.js @@ -272,6 +272,10 @@ $(function () { contentType: 'application/json', dataType: 'json', success: function (pay) { + if (pay.jsapi) { + callAlipayAps(pay); + return; + } if (pay.direct_paid) { location.href = '/api/v1.0/alipay_aps/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result'; return; @@ -449,4 +453,43 @@ $(function () { } } + function callApp(scheme_seq, index, timeout) { + let timer, start = new Date().getTime() + let promise = new Promise(((resolve, reject) => { + location.href = scheme_seq[index] + window.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'hidden') { + clearTimeout(timer); + resolve() + } + }); + timer = setTimeout(() => { + let end = new Date().getTime() + if (end - start > timeout + 1000) { + clearTimeout(timer) + resolve() + } else { + if (index + 1 < scheme_seq.length) { + callApp(scheme_seq, index + 1, timeout).then(resolve, reject) + } else { + reject() + } + } + }, timeout) + })) + return promise + } + function callAlipayAps(order) { + if(order.jsapi){ + let try_sequence = [order.jsapi.scheme_url, order.jsapi.applink_url, order.jsapi.normal_url] + try_sequence = try_sequence.filter(v => v != null) + callApp(try_sequence, 0, 5000).then(() => { + alert('redirect success') + }, () => { + alert('redirect failure') + }) + }else { + location.href = order.web_url + } + } });