博主你好,我跟你一样的问题,请问大佬你最后是怎么解决的?
node接入v3微信支付接口报错:SIGN_ERROR,已反复核对文档wxOrder(params, userAgent) { return new Promise(async resolve => { const buildMessage = (method, url, timestamp, nonceStr, body) => { // 生成签名字符串 return `${method}\n ${url}\n ${timestamp}\n ${nonceStr}\n ${body}\n` } const sign = message => { // 签名 const hash = crypto.createHmac('sha256', private_key) .update(message, 'utf8') .digest('hex') return new Buffer(hash).toString('base64') } const payParams = { appid: wxConfig.wxAppId, mchid: wxConfig.wxMchId, description: obj.description, out_trade_no: JSON.stringify(dayjs().valueOf()), // 订单号 notify_url: obj.notify_url, // 微信付款后的回调地址 amount: { total: 1, }, payer: { openid: params.openid, }, } const url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi' // 小程序统一下单接口 const nonce_str = Math.random().toString(36).substr(2, 15) const timestamp = dayjs().valueOf() const message = buildMessage('POST', '/v3/pay/transactions/jsapi', timestamp, nonce_str, payParams) const signature = sign(message) const authorization = `WECHATPAY2-SHA256-RSA2048 mchid=${payParams.mchid},serial_no=${wxConfig.serial_no},nonce_str=${nonce_str},timestamp=${timestamp},signature=${signature}` console.log('authorization', authorization) request.post({ url, body: payParams, json: true, headers: { Accept: '*/*', 'Content-Type': 'application/json', 'User-Agent': userAgent, Authorization: authorization, }, }, (error, response, body) => { console.log('微信小程序下单接口返回数据') console.log('error', error) console.log('body', body) resolve(body) }) }) } [图片] [图片] 在官方提供的 微信支付API v3 Postman脚本 中签名能通过,可以正常调用支付接口
2021-07-25