Browse Source

[支付][修复]:api描述更新,及例子更新

tags/2.2.4
Stormeye.Wu 6 years ago
parent
commit
b48efe44b7
2 changed files with 62 additions and 15 deletions
  1. +35
    -3
      common/common.js
  2. +27
    -12
      pages/coupons/details/index.js

+ 35
- 3
common/common.js View File

@@ -137,13 +137,13 @@ const func = {
wx.request({ wx.request({
url: config.api.orderSave, url: config.api.orderSave,
header: { header: {
"token": app.globalData.token
'token': app.globalData.token
}, },
method: "Post",
data: { data: {
couponId: couponId, couponId: couponId,
token: app.globalData.token token: app.globalData.token
}, },
method: "POST",
success: function (res) { success: function (res) {
resolve(res) resolve(res)
}, },
@@ -156,6 +156,9 @@ const func = {
}) })
}) })
}, },
/**
* 支付订单
*/
payOrderCreate: function (orderId) { payOrderCreate: function (orderId) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.request({ wx.request({
@@ -163,11 +166,40 @@ const func = {
header: { header: {
"token": app.globalData.token "token": app.globalData.token
}, },
method: "Post",
data: { data: {
orderId: orderId, orderId: orderId,
token: app.globalData.token token: app.globalData.token
}, },
method: "POST",
success: function (res) {
resolve(res)
},
fail: function (err) {
reject(err)
},
complete: function (res) {
console.log(res)
}
})
})
},
/**
* 支付订单更新
*/
payOrderUpdate: function (orderId, payOrderId, status, reason) {
return new Promise((resolve, reject) => {
wx.request({
url: config.api.payOrderUpdate,
header: {
"token": app.globalData.token
},
data: {
payOrderId: payOrderId,
orderId: orderId,
status: status,
reason: reason
},
method: "POST",
success: function (res) { success: function (res) {
resolve(res) resolve(res)
}, },


+ 27
- 12
pages/coupons/details/index.js View File

@@ -26,8 +26,22 @@ Page({
wx.hideLoading(); wx.hideLoading();
console.log(res) console.log(res)
if (res.data.code == 200) { if (res.data.code == 200) {
Common.payOrderCreate(res.data.data.id)
return res;
} else {
wx.showToast({
title: res.data.message,
duration: 3000
})
}
})
.then(res => {
orderId = '' + res.data.data.id;
return Common.payOrderCreate(orderId)
})
.then(res =>{ .then(res =>{
console.log(res)
payOrderId = res.data.data.payOrderId;
if (res.data.code == 200) {
wx.requestPayment({ wx.requestPayment({
timeStamp: res.data.data.timeStamp, timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr, nonceStr: res.data.data.nonceStr,
@@ -35,6 +49,8 @@ Page({
signType: 'MD5', signType: 'MD5',
paySign: res.data.data.paySign, paySign: res.data.data.paySign,
'success': function (res) { 'success': function (res) {
Common.payOrderUpdate(orderId, payOrderId, 1); // 支付成功
console.log(res);
console.log('支付成功'); console.log('支付成功');
wx.showToast({ wx.showToast({
title: '购买成功', title: '购买成功',
@@ -45,11 +61,13 @@ Page({
}) })
}, },
'fail': function (res) { 'fail': function (res) {
console.log('支付失败');
Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败
console.log(res) console.log(res)
console.log('支付失败');
return; return;
}, },
'complete': function (res) { 'complete': function (res) {
console.log(res);
console.log('支付完成'); console.log('支付完成');
var url = that.data.url; var url = that.data.url;
console.log('get url', url) console.log('get url', url)
@@ -69,19 +87,16 @@ Page({
wx.navigateBack() wx.navigateBack()
}, 2000) }, 2000)
} }
} else {
wx.showModal({
title: '错误提示',
content: res.errMsg
});
} }
return; return;
} }
}) })
})
} else {
wx.showToast({
title: res.data.message,
duration: 3000
})
}
})
}
})
} }
}) })

Loading…
Cancel
Save