// 确定支付
Consumer(item) {
console.log(item, 'item');
let data = {
orderId: item.id
};
tools
.myPro({
url: tools.baseUrl + `****`,
method: 'post',
data
})
.then(
res => {
if (res && res.data.success) {
let result = res.data.result;
console.log('付款预支付码:', result);
// this.valueCard = res.data.result.buyCard;
this.prepayId = result.prepayId;
if (this.prepayId) {
this.openWxPay(item);
}
} else {
wx.showToast({
title: res.data.error.message, //提示的内容,
icon: 'none', //图标,
duration: 2000, //延迟时间,
mask: true, //显示透明蒙层,防止触摸穿透,
success: res => {}
});
}
},
err => {
wx.hideLoading();
wx.showToast({
title: err.data.error.message, //提示的内容,
icon: 'none', //图标,
duration: 2000, //延迟时间,
mask: true, //显示透明蒙层,防止触摸穿透,
success: res => {}
});
}
);
},
// 调起微信支付
openWxPay(item) {
console.log('预支付码:', this.prepayId);
let that = this;
that.discounts = item.discounts;
// 获取到的数据
let data = JSON.parse(this.prepayId);
console.log(data, '111');
// 获取当前时间
let appid = data.appid;
let timestamp = '' + data.timestamp;
let nonceStr = data.noncestr;
let prepayid = 'prepay_id=' + data.prepayid;
let keys = 'gS8NoVGODkOCtuEisN8ZmN6qeSbSF4y9'; //商户支付密钥
const str = `appId=${appid}&nonceStr=${nonceStr}&package=${data.package}&signType=MD5&timeStamp=${timestamp}&key=${keys}`;
console.log('拼接后字段:', str);
let paysign = cj.MD5(str).toString();
// 调用微信的支付
wx.requestPayment({
timeStamp: timestamp,
nonceStr: nonceStr,
package: data.package,
signType: 'MD5',
paySign: paysign,
success: function(res) {
console.log('调用微信成功:', res);
setTimeout(() => {
that.arr = [];
that.pageObj = {
row: 10,
page: 1,
totalPage: 0
};
that.Myorder();
wx.hideLoading();
if (item.discounts == 0) {
that.dialogOrder = false;
} else {
that.dialogOrder = true;
}
wx.navigateTo({
url: `/pagesA/PaymentSuccessful/PaymentSuccessful?orderId=${item.orderGoods[0].orderId}&dialogOrder=${that.dialogOrder}&goodsImgUrl=${
item.orderGoods[0].goodsImgUrl
}&isEvaluate=${false}`
});
wx.showToast({
title: '支付成功!', //提示的内容,
icon: 'success', //图标,
duration: 2000, //延迟时间,
mask: true, //显示透明蒙层,防止触摸穿透,
success: res => {}
});
}, 300);
},
fail: function(res) {
console.log('支付失败:', res);
wx.hideLoading();
}
});
},
微信小程序调用微信支付
最新推荐文章于 2024-07-19 08:54:58 发布