You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hunjianghu/杨盼成/utils/pay.js

50 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const api = require('./request.js')
function wxpay(app, money, orderId, redirectUrl) {
let remark = "在线充值";
let nextAction = {};
if (orderId != 0) {
remark = "支付订单 " + orderId;
nextAction = { type: 0, id: orderId };
}
api.fetchRequest('/pay/wx/wxapp', {
token: wx.getStorageSync('token'),
money: money,
remark: remark,
payName: "在线支付",
nextAction: nextAction
}).then(function (res) {
if (res.data.code == 0) {
// 发起支付
wx.requestPayment({
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: 'prepay_id=' + res.data.data.prepayId,
signType: 'MD5',
paySign: res.data.data.sign,
fail: function (aaa) {
wx.showToast({ title: '支付失败:' + aaa })
},
success: function () {
wx.showToast({ title: '支付成功' })
wx.redirectTo({
url: redirectUrl
});
}
})
} else {
wx.showModal({
title: '出错了',
content: res.data.code + ':' + res.data.msg + ':' + res.data.data,
showCancel: false,
success: function (res) {
}
})
}
})
}
module.exports = {
wxpay: wxpay
}