给所有支付接口加上了支付宝

This commit is contained in:
2026-07-09 22:07:20 +08:00
parent 566aeaa3b7
commit 4b60ebbc10
18 changed files with 438 additions and 38 deletions

View File

@@ -34,6 +34,8 @@ Component({
const method = e.currentTarget.dataset.method;
if (method === 'wx') {
this.wxPay();
} else if (method === 'alipay') {
this.alipayPay();
} else if (method === 'balance') {
this.fetchBalanceOptions();
}
@@ -46,7 +48,7 @@ Component({
const res = await request({
url: '/yonghu/fkjn',
method: 'POST',
data: { fadan_id: this.properties.fadan.id }
data: { fadan_id: this.properties.fadan.id, pay_method: 'wechat' }
});
if (res.data.code !== 200) throw new Error(res.data.msg || '下单失败');
@@ -62,6 +64,41 @@ Component({
}
},
// ========== 支付宝扫码支付流程 ==========
async alipayPay() {
this.setData({ step: 'loading', loadingText: '生成支付宝二维码...' });
try {
const res = await request({
url: '/yonghu/fkjn',
method: 'POST',
data: { fadan_id: this.properties.fadan.id, pay_method: 'alipay' }
});
if (res.data.code !== 200) throw new Error(res.data.msg || '下单失败');
const payParams = res.data.payParams;
const dingdanid = res.data.dingdanid;
this.setData({ dingdanid, step: 'method' });
this.triggerAlipayPayment(payParams, dingdanid);
} catch (e) {
this.setData({ step: 'method' });
wx.showToast({ title: e.message, icon: 'none' });
}
},
// 跳转支付宝二维码页(轮询 /yonghu/fkzffc
triggerAlipayPayment(payParams, orderId) {
const qrImage = payParams && payParams.qr_image ? payParams.qr_image : '';
if (!qrImage) {
wx.showToast({ title: '支付宝二维码生成失败', icon: 'none' });
return;
}
const app = getApp();
app.globalData.alipayQrImage = qrImage;
const pollUrl = encodeURIComponent('/yonghu/fkzffc');
wx.navigateTo({
url: `/pages/alipay-webview/alipay-webview?orderId=${orderId}&pollUrl=${pollUrl}`,
});
},
async requestWxPayment(payParams) {
return new Promise((resolve, reject) => {
if (!payParams || !payParams.timeStamp || !payParams.paySign) {