给所有支付接口加上了支付宝
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
<text class="method-icon">💳</text>
|
||||
<text class="method-name">微信支付</text>
|
||||
</view>
|
||||
<view class="method-item" bindtap="chooseMethod" data-method="alipay">
|
||||
<text class="method-icon method-icon-alipay">支</text>
|
||||
<text class="method-name">支付宝</text>
|
||||
</view>
|
||||
<view class="method-item" bindtap="chooseMethod" data-method="balance">
|
||||
<text class="method-icon">💰</text>
|
||||
<text class="method-name">佣金抵扣</text>
|
||||
|
||||
@@ -28,6 +28,11 @@
|
||||
padding: 40rpx 30rpx; background: #f9f9f9; border-radius: 20rpx; margin-bottom: 20rpx;
|
||||
}
|
||||
.method-icon { font-size: 48rpx; margin-bottom: 12rpx; }
|
||||
.method-icon-alipay {
|
||||
width: 48rpx; height: 48rpx; line-height: 48rpx; text-align: center;
|
||||
background: #1677ff; color: #fff; font-size: 30rpx; font-weight: 700;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
.method-name { font-size: 28rpx; color: #333; }
|
||||
|
||||
.balance-item {
|
||||
|
||||
Reference in New Issue
Block a user