wx.setStorageSync 真机测试与开发工具正常,体验版失效。
wx.login({
success (res) {
if (res.code) {
// console.log(res)
//声明CODE,获取小程序传过来的CODE
const code = res.code;
//配置appid
const appid = "";
//配置appscret
const secret = "";
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session',
method: 'GET',
data: {
appid: appid,
js_code: res.code,
secret: secret,
grant_type: 'authorization_code',
},
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
console.log(res)
var openId = res.data.openid;
var sessionKey = res.data.session_key;
// sessionKey + openid存储到本地
console.log(openId)
Notify({ type: 'danger', message: openId});
if(openId){
wx.setStorageSync('openId', openId);
wx.setStorageSync('sessionKey', sessionKey);
global.globalData.openId = openId
global.globalData.sessionKey = sessionKey
}
}
})
} else {
console.log('登录失败!' + res.errMsg)
Notify({ type: 'danger', message: res.errMsg});
}
}
})