From 1fafb4ca381642c4167eb5aa0ecfe6ac9ab60e2a Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Tue, 14 Aug 2018 22:36:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/common.js | 24 ++++++++++++++ pages/coupons/details/index.js | 58 ++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/common/common.js b/common/common.js index 8c2677c..bbf2914 100755 --- a/common/common.js +++ b/common/common.js @@ -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; \ No newline at end of file diff --git a/pages/coupons/details/index.js b/pages/coupons/details/index.js index 39c7f53..f36441f 100644 --- a/pages/coupons/details/index.js +++ b/pages/coupons/details/index.js @@ -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,