// 下单接口
const url = `/v3/pay/transactions/app`;
const body = {
amount: {
total: 0.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, {
body: JSON.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 位有符号整数”错误,该如何解决?
要认真看文档,total字段参数是分,你来个0.01?