赞
踩
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="
app支付和小程序支付的代码之前还有这种差别和坑…腾讯的开发文档真是抵不上阿里文档的一个脚趾头…
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。