收藏
回答

微信支付APIv3 post接口body为json时报错签名错误该怎么解决?

// 下单接口
const url = `/v3/pay/transactions/app`;
        const body = {
            amount: {
                total0.01,
                currency"CNY"
            },
            appid: appID,
            description'app下单测试',
            mchid: mchid,
            notify_url'https://mprobe-health-dev-1e389x3d07a8c4-1304890945.ap-shanghai.app.tcloudbase.com/wechatPayNotifyUrl',
            out_trade_no'20210910123456789'
        };


       const result = await wxpay.v3.pay.transactions.native.post(body)
       console.info('[下单结果]',result)


        const timestamp = generateTimestamp();
        const nonceStr = nonce();
        const signature = buildAuth({ method'POST', body, uri: url, timestamp, nonceStr });
        console.log('[签名]', signature)


        const result = await fetch('https://api.mch.weixin.qq.com' + url, {
            bodyJSON.stringify(body),
            method'POST',
            dataType'json',
            headers: {
                'Authorization': authorization(mchid, apiCertSerialNo, timestamp, nonceStr, signature),
                'Content-Type''application/json',
                'Accept''application/json'
            }
        });
        const resultJson = await result.json();
        console.log('[微信支付下单信息]', resultJson)


代码如上,当fetch请求中的body为json对象时,将返回SIGN_ERROR,sign not match,当body为json string时,接口返回”法将 JSON 输入源“/body/amount/total”映射到目标字段“总金额”中,此字段需要一个合法的 64 位有符号整数”错误,该如何解决?



回答关注问题邀请回答
收藏

1 个回答

  • Memory (私信不回复)
    Memory (私信不回复)
    2021-09-13

    要认真看文档,total字段参数是分,你来个0.01?

    2021-09-13
    有用 1
    回复 1
    • Bob·杜
      Bob·杜
      2021-09-14
      谢谢,是这个问题,看文档看漏了。。。
      2021-09-14
      回复
登录 后发表内容