diff --git a/pages.json b/pages.json
index f57c135..cfba92c 100644
--- a/pages.json
+++ b/pages.json
@@ -75,6 +75,12 @@
"navigationBarTitleText": "我的钱包"
}
},
+ {
+ "path": "pages/alipay-payment/alipay-payment",
+ "style": {
+ "navigationBarTitleText": "支付宝支付"
+ }
+ },
{
"path": "pages/error/error",
"style": {
@@ -89,4 +95,4 @@
"backgroundColor": "#F8F8F8"
},
"uniIdRouter": {}
-}
\ No newline at end of file
+}
diff --git a/pages/alipay-payment/alipay-payment.vue b/pages/alipay-payment/alipay-payment.vue
new file mode 100644
index 0000000..eb9fc00
--- /dev/null
+++ b/pages/alipay-payment/alipay-payment.vue
@@ -0,0 +1,155 @@
+
+
+
+ 支付链接已失效
+ 请返回后重新发起支付宝支付
+ 返回
+
+
+
+
+
+ 点击右上角三个点,使用浏览器打开
+
+
+
+
+
+
+
+
+ 截图保存二维码,打开支付宝扫一扫即可支付
+
+
+
+
+
+
+
+
diff --git a/static/tips.png b/static/tips.png
new file mode 100644
index 0000000..5265a0f
Binary files /dev/null and b/static/tips.png differ
diff --git a/utils/payment.js b/utils/payment.js
index ffbbc73..2b3f5b4 100644
--- a/utils/payment.js
+++ b/utils/payment.js
@@ -1,4 +1,5 @@
const ALIPAY_PENDING_REFRESH_KEY = 'pending_alipay_payment_refresh';
+const ALIPAY_PAYMENT_DATA_KEY = 'pending_alipay_payment_data';
export const PAYMENT_REFRESH_TARGETS = {
PACKAGE_ORDER: 'package-order',
@@ -13,8 +14,22 @@ export function isValidWechatPayConfig(payConfig) {
}
export function getAlipayPaymentUrl(paymentLink) {
- if (!paymentLink) return '';
- return paymentLink.copy_link || paymentLink.qr_link || '';
+ return getAlipayPaymentUrls(paymentLink).copyUrl;
+}
+
+export function getAlipayPaymentUrls(paymentLink) {
+ if (!paymentLink) {
+ return { copyUrl: '', qrUrl: '' };
+ }
+
+ if (typeof paymentLink === 'string') {
+ return { copyUrl: paymentLink, qrUrl: paymentLink };
+ }
+
+ return {
+ copyUrl: paymentLink.copy_link || paymentLink.qr_link || '',
+ qrUrl: paymentLink.qr_link || paymentLink.copy_link || ''
+ };
}
export function isValidAlipayPaymentLink(paymentLink) {
@@ -39,28 +54,73 @@ export function consumePendingPaymentRefresh(target) {
return true;
}
+export function getPendingAlipayPaymentData() {
+ return uni.getStorageSync(ALIPAY_PAYMENT_DATA_KEY) || null;
+}
+
+function getAlipayPaymentPageUrl(refreshTarget) {
+ const params = [`t=${Date.now()}`];
+ if (refreshTarget) {
+ params.push(`from=${encodeURIComponent(refreshTarget)}`);
+ }
+
+ return `/pages/alipay-payment/alipay-payment?${params.join('&')}`;
+}
+
+function getAlipayPaymentBrowserUrl(pageUrl) {
+ if (typeof window === 'undefined' || !window.location) {
+ return pageUrl;
+ }
+
+ const { origin, pathname } = window.location;
+ const pagePath = pageUrl.replace(/^\//, '');
+ const basePath = pathname.includes('/pages/')
+ ? pathname.slice(0, pathname.indexOf('/pages/'))
+ : pathname.replace(/\/[^/]*$/, '');
+
+ return `${origin}${basePath}/${pagePath}`;
+}
+
+function navigateToAlipayPaymentPage(pageUrl, resolve, reject) {
+ uni.navigateTo({
+ url: pageUrl,
+ success: () => resolve({ redirecting: true }),
+ fail: () => {
+ uni.redirectTo({
+ url: pageUrl,
+ success: () => resolve({ redirecting: true }),
+ fail: () => {
+ if (typeof window !== 'undefined' && window.location) {
+ window.location.href = getAlipayPaymentBrowserUrl(pageUrl);
+ resolve({ redirecting: true });
+ return;
+ }
+
+ reject(new Error('\u6253\u5f00\u652f\u4ed8\u5b9d\u652f\u4ed8\u9875\u5931\u8d25'));
+ }
+ });
+ }
+ });
+}
+
export function openAlipayPayment(paymentLink, refreshTarget) {
return new Promise((resolve, reject) => {
- const paymentUrl = getAlipayPaymentUrl(paymentLink);
+ const { copyUrl, qrUrl } = getAlipayPaymentUrls(paymentLink);
- if (!paymentUrl) {
+ if (!copyUrl && !qrUrl) {
reject(new Error('\u652f\u4ed8\u94fe\u63a5\u65e0\u6548'));
return;
}
markPendingPaymentRefresh(refreshTarget);
-
- if (typeof window !== 'undefined' && window.location) {
- window.location.href = paymentUrl;
- resolve({ redirecting: true });
- return;
- }
-
- uni.setClipboardData({
- data: paymentUrl,
- success: () => resolve({ copied: true }),
- fail: () => reject(new Error('\u5f53\u524d\u73af\u5883\u6682\u4e0d\u652f\u6301\u6253\u5f00\u652f\u4ed8\u94fe\u63a5'))
+ uni.setStorageSync(ALIPAY_PAYMENT_DATA_KEY, {
+ copyUrl,
+ qrUrl,
+ refreshTarget,
+ timestamp: Date.now()
});
+
+ navigateToAlipayPaymentPage(getAlipayPaymentPageUrl(refreshTarget), resolve, reject);
});
}