forked from woniudiancang/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpay.js
76 lines (74 loc) · 1.87 KB
/
pay.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const WXAPI = require('apifm-wxapi')
/**
* type: order 支付订单 recharge 充值 paybill 优惠买单
* data: 扩展数据对象,用于保存参数
*/
function wxpay(type, money, orderId, redirectUrl, data) {
const postData = {
token: wx.getStorageSync('token'),
money: money,
remark: "在线充值",
}
if (type === 'order') {
postData.remark = "支付订单 :" + orderId;
postData.nextAction = {
type: 0,
id: orderId
};
}
if (type === 'paybill') {
postData.remark = "优惠买单 :" + data.money;
postData.nextAction = {
type: 4,
uid: wx.getStorageSync('uid'),
money: data.money
};
}
postData.payName = postData.remark;
if (postData.nextAction) {
postData.nextAction = JSON.stringify(postData.nextAction);
}
WXAPI.wxpay(postData).then(function (res) {
if (res.code == 0) {
// 发起支付
wx.requestPayment({
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
fail: function (aaa) {
console.error(aaa)
wx.showToast({
title: '支付失败:' + aaa
})
if (redirectUrl) {
wx.redirectTo({
url: redirectUrl,
})
}
},
success: function () {
// 提示支付成功
wx.showToast({
title: '支付成功'
})
if (redirectUrl) {
wx.redirectTo({
url: redirectUrl,
})
}
}
})
} else {
wx.showModal({
title: '出错了',
content: JSON.stringify(res),
showCancel: false
})
}
})
}
module.exports = {
wxpay: wxpay
}