坑一:调用支付jsapi缺少参数 total_fee
修正后的uniapp代码如下:
uni.requestPayment({
provider: 'wxpay',
timeStamp: String(data.timestamp),
nonceStr: data.nonceStr,
package: 'prepay_id=' + data.prepayId,
signType: 'HMAC-SHA256',
paySign: data.sign,
success: (res) => {
console.log('success:' + JSON.stringify(res));
uni.showToast({
title: '支付成功!',
duration: 2000
});
uni.reLaunch({
url: '/pages/order/list'
})
},
fail: (err) => {
console.log('fail:' + JSON.stringify(err));
uni.showToast({
title: '已取消支付!',
icon: 'none',
duration: 2000
});
}
});
解决方案:
其中package: ‘prepay_id=’ + data.prepayId,这一行代码,必须拼接‘prepay_id=’
坑二:小程序支付报错:支付签名验证失败
修正后的后台代码:
/**
* 按照前端签名文档规范进行排序,\n是换行
*
* @param appid
* @param timestamp
* @param nonceStr
* @param prepay_id
* @return
*/
public static String buildMessage(String appid, long timestamp, String nonceStr, String prepay_id) {
return appid + "\n"
+ timestamp + "\n"
+ nonceStr + "\n"
+ "prepay_id=" + prepay_id + "\n";
}
文档官方文档:
https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/jsapi-transfer-payment.html
$ echo -n -e \
"wx8888888888888888\n1414561699\n5K8264ILTKCH16CQ2502SI8ZNMTM67VS\nprepay_id=wx201410272009395522657a690389285100\n" \
| openssl dgst -sha256 -sign apiclient_key.pem \
| openssl base64 -A
uOVRnA4qG/MNnYzdQxJanN+zU+lTgIcnU9BxGw5dKjK+VdEUz2FeIoC+D5sB/LN+nGzX3hfZg6r5wT1pl2ZobmIc6p0ldN7J6yDgUzbX8Uk3sD4a4eZVPTBvqNDoUqcYMlZ9uuDdCvNv4TM3c1WzsXUrExwVkI1XO5jCNbgDJ25nkT/c1gIFvqoogl7MdSFGc4W4xZsqCItnqbypR3RuGIlR9h9vlRsy7zJR9PBI83X8alLDIfR1ukt1P7tMnmogZ0cuDY8cZsd8ZlCgLadmvej58SLsIkVxFJ8XyUgx9FmutKSYTmYtWBZ0+tNvfGmbXU7cob8H/4nLBiCwIUFluw==
解决方案:
注意看,后台生成sign时候,拼接的字符串中,也需要加上"prepay_id="文章来源:https://www.toymoban.com/news/detail-762923.html
tips:
app支付和小程序支付的代码之前还有这种差别和坑…腾讯的开发文档真是抵不上阿里文档的一个脚趾头…文章来源地址https://www.toymoban.com/news/detail-762923.html
到了这里,关于微信小程序demo 调用支付jsapi缺少参数 total_fee,支付签名验证失败 究极解决方案的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!