检查了参数和接口都和文档一样,sig也是按照macsha256编码的,但就是返回失败,是什么原因呢?底部附代码,openid是“'oy-n45NTsb4S4USJgzVYMxL6JYGk”
请求post接口: https://api.weixin.qq.com/cgi-bin/midas/sandbox/getbalance?access_token=xxxxxx
请求参数: { openid: 'xxx', appid: 'xxx', offer_id:xxx, ts: 1628489729, zone_id: '1', pf: 'android', sig:'xxxxx' }
返回: { errcode: 47001, errmsg: 'data format error rid: 6110c802-0b4cc0c5-4e5289ce' }
//初始化接口参数(不带sig)
let param = {
openid: args.openid,
appid: args.appid,
offer_id: args.offer_id,
ts: parseInt(Date.now() / 1000),
zone_id:"1",
pf: "android",
amt: args.item.price,
bill_no: args.orderId
}
//拼接sig字串
let sigStr = "amt=" + param.amt + "&appid=" + param.appid + "&bill_no=" + param.bill_no + "&offer_id=" + param.offer_id + "&openid=" + param.openid + "&pf=" + param.pf + "&ts=" + param.ts + "&zone_id=" + param.zone_id + "&org_loc=/cgi-bin/midas" + (args.debug ? "/sandbox" : "") + "/pay&method=POST&secret=" + args.mdsSecret;
//将拼好的字串进行HmacSHA256编码
param.sig = HmacSHA256(sigStr, args.mdsSecret).toString();
//发出post请求
let res = await NetMgr.i.post("https://api.weixin.qq.com/cgi-bin/midas" + (args.debug ? "/sandbox" : "") + "/pay?access_token=" + TokenMgr.i.accessToken, param);
postman能调通吗