收藏
回答

midasGetBalance接口中的access_token指的是什么


midasGetBalance:https://developers.weixin.qq.com/minigame/dev/document/midas-payment/midasGetBalance.html?t=2018329


我想问一下请求接口中的access_token指的是session_key吗?


我用的是cocos creator,我用下面的代码请求,但是总是返回:查询失败

{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [tk100729vr60!]"}

我可以确定获取到的wx_session_key是正确的

//wx_openid 和 wx_session_key都是通过wx.login的code换取的

let data = {

openid:wx_openid,

        appid: appid,

        midasSecret:midasSecret,

        offer_id: offer_id,

        ts: ts,

        zone_id: '1',

        pf: 'android',

        session_key:wx_session_key

};




let stringA = 'appid='+data.appid

            +'&offer_id=' + data.offer_id

            +'&openid=' + data.openid

            +'&pf='+data.pf

            +'&ts='+data.ts

            +'&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.session_key

            +'&appid='+data.appid

            +'&offer_id=' + data.offer_id

            +'&openid=' + data.openid

            +'&pf='+data.pf

            +'&sig='+data.sig

            +'&ts='+data.ts

            +'&zone_id='+data.zone_id;

let mp_sigTemp=stringB+"&org_loc=/cgi-bin/midas/getbalance&method=POST&session_key="+data.session_key;

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.session_key;

xhr.open('POST',url, true);

xhr.onreadystatechange = function () {

   if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {

       let response = JSON.parse(xhr.responseText);

       if(response.errcode === 0){

           //查询成功

           console.log('查询成功');

           console.log(JSON.stringify(response));

       }else{

           //查询失败

           console.log('查询失败');

           console.log('errcode: '+response.errcode);

           console.log('errmsg: '+response.errmsg);

       }

   }

};


//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.session_key
           +'&mp_sig='+resultData.mp_sig;
xhr.send(form);


最后一次编辑于  2018-03-30
回答关注问题邀请回答
收藏

3 个回答