官方文档:
https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7
https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html
假设订单发送给后台后,这里就是支付接口返回的数据
{ "return_code": "SUCCESS", "return_msg": "OK", "appid": "wxd678efh567hg6787", "mch_id": "12345678", "nonceStr": "5K8264ILTKCH16CQ2502SI8ZNMTM67VS", "paySign": "22D9B4E54AB1950F51E0649E8810ACD6", "result_code": "SUCCESS", "packageValue": "prepay_id=wx2017033010242291fcfe0db70013231072", "timeStamp": "1490840662" }
获取相关数据后发起微信支付
wx.requestPayment({ timeStamp: payParam.timeStamp.toString(), // 1490840662,时间戳 nonceStr: payParam.nonceStr, // 5K8264ILTKCH16CQ2502SI8ZNMTM67VS,随机字符串不长于32位 package: payParam.packageValue, // package格式:prepay_id=wx2017033010242291fcfe0db70013231072,订单接口返回的prepay_id,预支付交易会话标识 signType: 'MD5', // 签名算法类型,默认MD5,支持HMAC-SHA256和MD5 paySign: payParam.paySign, // 签名,假设已拼接,详细签名格式见下文 success: function (res) { console.log("支付过程成功"); }, fail: function (res) { console.log("支付过程失败"); }, complete: function (res) { console.log("支付过程结束"); }
具体签名方案见:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
paySign格式:paySign = MD5(appId=wxd678efh567hg6787&nonceStr=5K8264ILTKCH16CQ2502SI8ZNMTM67VS&package=prepay_id=wx2017033010242291fcfe0db70013231072&signType=MD5&timeStamp=1490840662&key=qazwsxedcrfvtgbyhnujmikolp111111) = 22D9B4E54AB1950F51E0649E8810ACD6
注释:
1.paySign中的key为商户平台设置的密钥key
2.key设置路径:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置
来源:https://www.cnblogs.com/jing-zhe/p/12177677.html