uniapp的小程序支付是不需要申请各种东西的,直接请求后端参数调用官方API即可实现
this.$api.addBlindBox(data).then((res) => { //这里是我封装的请求接口
console.log(res);
uni.requestPayment({ //官方API,后端返回的数据接入
provider: "wxpay",
timeStamp: res.timeStamp,
nonceStr: res.nonceStr,
package: res.package,
signType: res.signType,
paySign: res.paySign,
success: (response) => {
if (response.errMsg == "requestPayment:ok") { //成功调用
this.$u.toast("支付成功~");
setTimeout(() => {
this.popupShow = false;
this.getBlindBoxInfo();
}, 500);
}
},
fail: (error) => {
if (error.errMsg == "requestPayment:fail cancel") { //失败调用
this.$u.toast("支付失败~");
}
},
});
});