//如果没有登陆过登录
login:function(){
var that = this;
wx.getUserInfo({//获取信息
success: function (res) {
that.setData({ info: res.userInfo });
}
});
wx.login({//登录
success: function (res) {
if (res.code) {
wx.request({
url: getApp().globalData.urlPath + ‘wxuser/getcode‘,//获取session_key
data: {
code: res.code
},
header: {
‘content-type‘: ‘application/json‘
},
success: function (res) {
wx.setStorage({//将返回的值存到storage中
key: ‘srd‘,
data: res.data,
})
wx.request({
url: getApp().globalData.urlPath + ‘wxuser/user_add‘,//信息添加到库
data: {
srd: res.data,
u_name: that.data.info.nickName,
pic: that.data.info.avatarUrl,
ip: getApp().globalData.motto,
},
header: {
‘content-type‘: ‘application/json‘,
},
success: function () {
that.setData({ show: 0 });
console.log(‘授权成功‘);
},
})
}
})
}
}
})
},