midasGetBalance:https://developers.weixin.qq.com/minigame/dev/document/midas-payment/midasGetBalance.html?t=2018329
我想问一下请求接口中的access_token指的是session_key吗?
我用的是cocos creator,微信小程序 超过2048kb 无法上传-微信小程序开发。我用下面的代码请求,但是总是返回:查询失败
{"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);
本文来自微信小程序开发者论坛 微信小程序工厂 http://www.xcxgc.com 转载请保留。
微信小程序开发者回答:
田***:
没人遇到这个问题吗
风***:
刚弄完 掉这个接口得到 https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s
51微信小程序从商家系统跳转到微信卡包
空***:
对的,就是使用https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s 获得
本文网址:http://www.91bianli.com/weixinxiaochengxu/54869.html