我用的php算签名: $sign = hash_hmac("sha256", $source, $secret); return $sign; 也是一直报 90009 错误{"errcode":90009,"errmsg":"mp_sig error hint: [K6oh2a02954546]"}
客户端调用midasGetBalance接口一直返回mp_sig error在客户端调用midasGetBalance接口在沙箱环境查询余额,按照文档要求进行数据签名,然后进行请求,但是一直返回 {"errcode":90009,"errmsg":"mp_sig error hint: [mdJ5.a06883102]"} 具体代码如下,其中crypto是node.js中的crypto.js模块: [代码]let ts = Math.round([代码][代码]new[代码] [代码]Date().getTime()/1000);[代码][代码]//通过wx.login的code换取的openid和session_key[代码][代码]//通过https://api.weixin.qq.com/cgi-bin/token获取的access_token[代码][代码]//appid、offer_id和midasSecret已经申请好的[代码][代码]let data = {[代码][代码] [代码][代码]openid: LoginUser.wx_openid,[代码][代码] [代码][代码]appid: appid,[代码][代码] [代码][代码]midasSecret: midasSecret,[代码][代码] [代码][代码]offer_id: offer_id,[代码][代码] [代码][代码]ts: ts,[代码][代码] [代码][代码]zone_id: [代码][代码]'1'[代码][代码],[代码][代码] [代码][代码]pf: [代码][代码]'android'[代码][代码],[代码][代码] [代码][代码]access_token: LoginUser.wx_access_token,[代码][代码] [代码][代码]session_key: LoginUser.wx_session_key[代码][代码] [代码][代码]};[代码][代码]let stringA = [代码][代码]'appid='[代码][代码]+data.appid;[代码][代码]stringA += [代码][代码]'&offer_id='[代码] [代码]+ data.offer_id;[代码][代码]stringA += [代码][代码]'&openid='[代码] [代码]+ data.openid;[代码][代码]stringA += [代码][代码]'&pf='[代码][代码]+data.pf;[代码][代码]stringA += [代码][代码]'&ts='[代码][代码]+data.ts;[代码][代码]stringA += [代码][代码]'&zone_id='[代码][代码]+data.zone_id;[代码][代码]let sigTemp = stringA+[代码][代码]"&org_loc=/cgi-bin/midas/getbalance&method=POST&secret="[代码][代码]+data.midasSecret;[代码][代码]//sig参数[代码][代码]let sig = crypto.createHmac([代码][代码]'sha256'[代码][代码],data.midasSecret).update(sigTemp).digest([代码][代码]'hex'[代码][代码]);[代码][代码]data.sig = sig;[代码][代码]let stringB = [代码][代码]'access_token='[代码] [代码]+ data.access_token;[代码][代码]stringB += [代码][代码]'&appid='[代码] [代码]+ data.appid;[代码][代码]stringB += [代码][代码]'&offer_id='[代码] [代码]+ data.offer_id;[代码][代码]stringB += [代码][代码]'&openid='[代码] [代码]+ data.openid;[代码][代码]stringB += [代码][代码]'&pf='[代码] [代码]+ data.pf;[代码][代码]stringB += [代码][代码]'&sig='[代码][代码]+ sig;[代码][代码]stringB += [代码][代码]'&ts='[代码] [代码]+ data.ts;[代码][代码]stringB += [代码][代码]'&zone_id='[代码] [代码]+ data.zone_id;[代码][代码]let mp_sigTemp = stringB+[代码][代码]"&org_loc=/cgi-bin/midas/getbalance&method=POST&session_key="[代码][代码]+data.session_key;[代码][代码]//mp_sig[代码][代码]let mp_sig = crypto.createHmac([代码][代码]'sha256'[代码][代码],data.session_key).update(mp_sigTemp).digest([代码][代码]'hex'[代码][代码]);[代码][代码]data.mp_sig = mp_sig;[代码][代码]let resultData = data;[代码][代码]let xhr = cc.loader.getXMLHttpRequest();[代码][代码]//沙箱环境[代码][代码]let url = [代码][代码]'https://api.weixin.qq.com/cgi-bin/midas/sandbox/getbalance?'[代码][代码];[代码][代码]url += [代码][代码]'access_token='[代码][代码]+resultData.access_token;[代码][代码]xhr.open([代码][代码]'POST'[代码][代码],url, [代码][代码]true[代码][代码]);[代码][代码]xhr.onreadystatechange = [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]if[代码] [代码](xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {[代码][代码] [代码][代码]let response = JSON.parse(xhr.responseText);[代码] [代码] console.log(JSON.stringify(response));[代码] [代码] [代码][代码]if[代码][代码](response.errcode === 0){[代码][代码] [代码][代码]//查询成功[代码][代码] [代码][代码]console.log([代码][代码]'查询成功'[代码][代码]);[代码][代码] [代码][代码]}[代码][代码]else[代码][代码]{[代码][代码] [代码][代码]//查询失败[代码][代码] [代码][代码]console.log([代码][代码]'查询失败'[代码][代码]);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]};[代码][代码]//POST参数[代码][代码]let form = {[代码][代码] [代码][代码]openid: resultData.openid,[代码][代码] [代码][代码]appid: resultData.appid,[代码][代码] [代码][代码]offer_id: resultData.offer_id,[代码][代码] [代码][代码]ts: resultData.ts,[代码][代码] [代码][代码]zone_id: resultData.zone_id,[代码][代码] [代码][代码]pf: resultData.pf,[代码][代码] [代码][代码]sig: resultData.sig,[代码][代码] [代码][代码]access_token: resultData.access_token,[代码][代码] [代码][代码]mp_sig: resultData.mp_sig[代码][代码] [代码][代码]}; [代码][代码]xhr.send(JSON.stringify(form));[代码] POST的数据如下: {"openid":"o6iRc5Tm5tZH7k6zRgWqBMuMpzH8","appid":"wx67f6b13c452ed6bb","offer_id":"1450014357","ts":1522721483,"zone_id":"1","pf":"android","sig":"4b9a04df8600bcbe2c24313d594820a0b865e70cff966acc28c59c6fc5825e3c","access_token":"8_8UqjUd49YcgukSHPRSfdLXrj2YsRzxUSaKgPtYZwkKGR4tVr6oAGvtOXGDTJDuI7Jkx8l8zgS9UDHpVfNaojOqvGk-2F-GdzbF3cTuVrRY6EwuQr_49Yu0bs3JEH33_IRMNVOEOqg8RNMrfkARLiAIAGXR","mp_sig":"252c78694e9ca1491e812476c4d97efcbbc89c215ab1e37f407580a70c6646b5"}
2018-10-19