onLoad: function (options) {
// 获取openID
var oi=’’;
var that = this;
var user = wx.getStorageSync(‘user’) || {};
var userInfo = wx.getStorageSync(‘userInfo’) || {};
if ((!user.openid || (user.expires_in || Date.now()) < (Date.now() + 600)) && (!userInfo.nickName)) {
wx.login({
success: function(res) {
if (res.code) {
wx.getUserInfo({
success: function(res) {
var objz = {};
objz.avatarUrl = res.userInfo.avatarUrl;
objz.nickName = res.userInfo.nickName;
//console.log(objz);
wx.setStorageSync(‘userInfo’, objz); //存储userInfo
}
});
var d = that.globalData; //这里存储了appid、secret、token串
console.log(“appid” + d.appid);
console.log(“token” + res.code);
var l = ‘https://api.weixin.qq.com/sns/jscode2session?appid=’ + d.appid + ‘&secret=’ + d.secret + ‘&js_code=’ + res.code + ‘&grant_type=authorization_code’;
wx.request({
url: l,
data: {},
method: ‘GET’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
success: function(res) {
var obj = {};
obj.openid = res.data.openid;
obj.expires_in = Date.now() + res.data.expires_in;
oi = obj.openid;
console.log(“OPENID” + oi);
}
});
} else {
console.log(‘获取用户登录态失败!’ + res.errMsg)
}
}
});
}
console.log(“OPENID” + oi);
},
请问为什么最后一个oi变量输出为空,明明在前面oi = obj.openid给oi赋值了啊