E企盈营销工具技术服务商 热线:4006-838-530

微信小程序实现登录功能

E企盈直播平台营销卖货系统

直接获取用户数据      wx.getUserInfo({        success: function (res) {          var userInfo = res.userInfo          console.log(“获取登录用户的所有信息”)          console.log(res.userInfo)          }        })用户拒绝提示模态框,点击确定,进入设置,再次让用户选择允许。    fail: function (res) {          wx.showModal({            title: ‘提示’,            content: ‘获取用户信息失败,这将影响您使用小程序,是否重新设置授权?’,            showCancel: true,            cancelText: “否”,            confirmText: “是”,            success: function (res) {              if (res.confirm) {   //点击是                wx.openSetting({  //打开设置                  success: function (res) {                    console.log(res)                    if (res.authSetting[‘scope.userInfo’] === true) {                      wx.getUserInfo({                        success: function (res) {                          console.log(“重新登录成功”)                          var userInfo = res.userInfo                          var nickName = userInfo.nickName  //用户名                          var avatarUrl = userInfo.avatarUrl  //头像                          console.log(“获取登录用户的所有信息”)                          console.log(res.userInfo)                          that.setData({                            imageInfo: avatarUrl,                            userName: nickName,                            hasUserInfo: true,                            isLogin: true,                          })                          t.globalData.imageInfo = avatarUrl;//全局变量表示登录用户头像                          t.globalData.userName = nickName;//登录用户名                        }                      })                    }                  }                })              } else if (res.cancel) {                console.log(‘用户取消授权个人信息’);              }            }   用户允许前台解析并显示如果点击拒绝,让你重新选择点击是,就进入设置界面点击勾选,返回即可登录。loginwx: function() {    var that = this    if(that.data.isLogin == false)    {      wx.getUserInfo({        success: function (res) {          var userInfo = res.userInfo          var nickName = userInfo.nickName  //用户名          var avatarUrl = userInfo.avatarUrl  //头像          console.log(“获取登录用户的所有信息”)          console.log(res.userInfo)          // wx.showToast({          //   title: nickName,          // });          that.setData({            imageInfo: avatarUrl,            userName: nickName,            hasUserInfo: true,            isLogin: true,          })          t.globalData.imageInfo = avatarUrl;//全局变量表示登录用户头像          t.globalData.userName = nickName;//登录用户名        },        fail: function (res) {          wx.showModal({            title: ‘提示’,            content: ‘获取用户信息失败,这将影响您使用小程序,是否重新设置授权?’,            showCancel: true,            cancelText: “否”,            confirmText: “是”,            success: function (res) {              if (res.confirm) {                wx.openSetting({                  success: function (res) {                    console.log(res)                    if (res.authSetting[‘scope.userInfo’] === true) {                      wx.getUserInfo({                        success: function (res) {                          console.log(“重新登录成功”)                          var userInfo = res.userInfo                          var nickName = userInfo.nickName  //用户名                          var avatarUrl = userInfo.avatarUrl  //头像                          console.log(“获取登录用户的所有信息”)                          console.log(res.userInfo)                          that.setData({                            imageInfo: avatarUrl,                            userName: nickName,                            hasUserInfo: true,                            isLogin: true,                          })                          t.globalData.imageInfo = avatarUrl;//全局变量表示登录用户头像                          t.globalData.userName = nickName;//登录用户名                        }                      })                    }                  }                })              } else if (res.cancel) {                console.log(‘用户取消授权个人信息’);              }            }          })        }      })    }

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序实现登录功能
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏