uni-app微信支付失败{“errMsg”:“requestPayment:fail errors”}
// 微信支付
// data为后端获取到的支付信息
let postInfo = {
sign: data.sign,prepayid: data.prepayId,partnerid: data.partnerId,appid: data.appId,timestamp: data.timeStamp,noncestr: data.nonceStr,package: data.package,}
let postDataInfo = JSON.stringfy(postInfo) // 微信支付orderInfo需要json支付串格式
let _this = this
uni.requestPayment({
provider: 'wxpay',orderInfo: postDataInfo, signType: 'HMAC-SHA256', // 签名类型必须与后端解密方式一致success: function(res) {
uni.navigateTo({
url: './pay-success?money?=' + _this.postData.hjjkPayOrderRo.totalMoney})},fail: function(err) {
console.log('微信支付失败', err);},complete(res) {
console.log('微信支付完成', res);}
});
// 支付宝支付
aliPay(data) {
let _this = thisuni.requestPayment({
provider: 'alipay',orderInfo: data, //支付宝订单数据 支付宝订单信息为一串包含支付信息的支付串success: function(res) {
let total = _this.postData.hjjkPayOrderRo.totalMoneyuni.navigateTo({
url: `/pages/hjjk/modules/service/pay/pay-success?money=${
total}`})},fail: function(err) {
console.log('支付宝支付失败' + JSON.stringify(err));}});
}
{"errMsg":"requestPayment:fail errors"}
错误的原因是如果signType
不指定默认为MD5加密,可能与后端的加密方式不一致导致错误