给所有支付接口加上了支付宝
This commit is contained in:
@@ -24,6 +24,8 @@ Page({
|
||||
canSubmit: false,
|
||||
isPaying: false,
|
||||
|
||||
payMethod: 'wechat',
|
||||
|
||||
orderId: '',
|
||||
payParams: null,
|
||||
checkCount: 0,
|
||||
@@ -133,6 +135,13 @@ Page({
|
||||
this.setData({ zhiding: e.detail.value.trim() })
|
||||
},
|
||||
|
||||
onSelectPayMethod(e) {
|
||||
const method = e.currentTarget.dataset.method
|
||||
if (method && method !== this.data.payMethod) {
|
||||
this.setData({ payMethod: method })
|
||||
}
|
||||
},
|
||||
|
||||
checkFormValid() {
|
||||
const { nicheng } = this.data
|
||||
this.setData({ canSubmit: nicheng && nicheng.length > 0 && nicheng.length <= 15 })
|
||||
@@ -164,7 +173,8 @@ Page({
|
||||
beizhu: beizhu || '',
|
||||
zhiding: zhiding || '',
|
||||
jine: jine * quantity,
|
||||
shuliang: quantity
|
||||
shuliang: quantity,
|
||||
pay_method: this.data.payMethod
|
||||
}
|
||||
|
||||
request({
|
||||
@@ -181,6 +191,7 @@ Page({
|
||||
if (response.code === 0 && response.data) {
|
||||
const orderId = response.data.dingdanid
|
||||
const payParams = response.data.payParams || {}
|
||||
const payMethod = response.data.payMethod || this.data.payMethod
|
||||
this.setData({
|
||||
orderId: orderId,
|
||||
payParams: payParams,
|
||||
@@ -188,7 +199,11 @@ Page({
|
||||
isPaying: true,
|
||||
checkCount: 0
|
||||
})
|
||||
this.triggerWxPayment(payParams)
|
||||
if (payMethod === 'alipay') {
|
||||
this.triggerAlipayPayment(payParams, orderId)
|
||||
} else {
|
||||
this.triggerWxPayment(payParams)
|
||||
}
|
||||
} else {
|
||||
wx.showToast({ title: response.msg || '创建订单失败', icon: 'none' })
|
||||
this.setData({ isSubmitting: false, isPaying: false })
|
||||
@@ -206,6 +221,20 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
triggerAlipayPayment(payParams, orderId) {
|
||||
const qrImage = payParams.qr_image || ''
|
||||
if (!qrImage) {
|
||||
wx.showToast({ title: '支付宝支付参数不完整', icon: 'none' })
|
||||
this.setData({ isSubmitting: false, isPaying: false })
|
||||
return
|
||||
}
|
||||
// base64 图片较大,通过 globalData 传递避免 URL 长度限制
|
||||
app.globalData.alipayQrImage = qrImage
|
||||
wx.navigateTo({
|
||||
url: `/pages/alipay-webview/alipay-webview?orderId=${orderId}`
|
||||
})
|
||||
},
|
||||
|
||||
triggerWxPayment(payParams) {
|
||||
if (!payParams || !payParams.timeStamp || !payParams.nonceStr ||
|
||||
!payParams.package || !payParams.signType || !payParams.paySign) {
|
||||
|
||||
Reference in New Issue
Block a user