在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo" hidden="{{userinfo}}">授权登录</button>
data: {
userinfo:false,
}
onLoad:function(){
wx.getStorage({
key: 'userinfo',
success: function(res) {
that.setData({
userinfo:true
})
},
fail:function(){
that.setData({
userinfo: false
})
}
})
}
//方法
bindGetUserInfo: function(e) {
var that = this;
console.log(e);
console.log(e.detail.userInfo)
wx.login({
success: res => {
// ------ 获取凭证 ------
var code = res.code;
console.log(code);
if (code) {
// console.log('获取用户登录凭证:' + code);
// ------ 发送凭证 ------
app.util.request({
"url": "entry/wxapp/GetUid",
data: {
code: code
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function(res) {
console.log(res);
if (res.statusCode == 200) {
// console.log("获取到的openid为:" + res.data)
// that.globalData.openid = res.data
wx.setStorageSync('openid', res.data),//同步操作
wx.setStorage({//异步操作
key: 'userinfo',
data: true,
}),
that.setData({
userinfo: true
})
//设置用户信息
wx.getUserInfo({
success: res => {
var u_name = e.detail.userInfo.nickName;
var u_thumb = e.detail.userInfo.avatarUrl;
console.log(u_name);
console.log("aa" + res)
console.log("aa"+res.errMsg)
wx.setStorageSync("avatar", res.userInfo.avatarUrl)
if (res.userInfo.nickName != wx.getStorageSync("nickName")) {
app.util.request({
"url": 'entry/wxapp/TyMember',
data :{
u_name:u_name,
u_thumb:u_thumb
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res);
if (res.statusCode == 200) {
// console.log("获取到的openid为:" + res.data)
// that.globalData.openid = res.data
wx.setStorageSync('u_name', res.data)
wx.getStorageSync('u_thumb', res.data)
} else {
console.log(res.errMsg)
}
},
})
}
}
})
} else {
console.log(res.errMsg)
}
}
})
}
},
fail: function (err) {
console.info(err.errMsg);
wx: showModal({
title: '警告',
cancelText: '不授权',
confirmText: '授权',
confirmColor: '#37c31a',
content: '若不授权微信登录,则无法使用XXXXXX;点击重新获取授权,则可重新使用;' +
'若点击不授权,将无法使用便捷服务。',
success: function (res) {
if (res.confirm) {
console.log('用户点击确认');
wx.openSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
wx.getUserInfo({
success: res => {
console.log('用户同意授权' + res.userInfo.nickName)
app.util.request({
'url': 'entry/wxapp/TyMember',
data: {
u_name: u_name,
u_thumb: u_thumb
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res);
if (res.statusCode == 200) {
// console.log("获取到的openid为:" + res.data)
// that.globalData.openid = res.data
wx.setStorageSync('openid', res.data)
} else {
console.log(res.errMsg)
}
},
})
}
})
} else {
console.info('再次不允许');
}
}
})
} else if (res.cancel) {
console.log('弹出框用户点击取消')
}
}
})
}
})
},
|
请发表评论