Bläddra i källkod

支付订单

tags/2.2.4
Stormeye.Wu 6 år sedan
förälder
incheckning
1fafb4ca38
2 ändrade filer med 73 tillägg och 9 borttagningar
  1. +24
    -0
      common/common.js
  2. +49
    -9
      pages/coupons/details/index.js

+ 24
- 0
common/common.js Visa fil

@@ -156,5 +156,29 @@ const func = {
})
})
},
payOrderCreate: function (orderId) {
return new Promise((resolve, reject) => {
wx.request({
url: config.api.payOrderCreate,
header: {
"token": app.globalData.token
},
method: "Post",
data: {
orderId: orderId,
token: app.globalData.token
},
success: function (res) {
resolve(res)
},
fail: function (err) {
reject(err)
},
complete: function (res) {
console.log(res)
}
})
})
},
}
module.exports = func;

+ 49
- 9
pages/coupons/details/index.js Visa fil

@@ -26,16 +26,56 @@ Page({
wx.hideLoading();
console.log(res)
if (res.data.code == 200) {
wx.showToast({
title: '购买成功',
duration: 2000
})
setTimeout(() => {
wx.hideToast();
}, 2000)
wx.navigateBack({
delta: 2
Common.payOrderCreate(res.data.data.id)
.then(res =>{
wx.requestPayment({
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: res.data.data.package,
signType: 'MD5',
paySign: res.data.data.paySign,
'success': function (res) {
console.log('支付成功');
wx.showToast({
title: '购买成功',
duration: 2500
})
wx.navigateBack({
delta: 2
})
},
'fail': function (res) {
console.log('支付失败');
console.log(res)
return;
},
'complete': function (res) {
console.log('支付完成');
var url = that.data.url;
console.log('get url', url)
if (res.errMsg == 'requestPayment:ok') {
wx.showModal({
title: '提示',
content: '支付成功'
});
if (url) {
setTimeout(function () {
wx.redirectTo({
url: '/pages' + url
});
}, 2000)
} else {
setTimeout(() => {
wx.navigateBack()
}, 2000)
}
}
return;
}
})
})
} else {
wx.showToast({
title: res.data.message,


Laddar…
Avbryt
Spara