前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >小程序体验版 新用户登录不了

小程序体验版 新用户登录不了

原创
作者头像
用户6663311
修改2020-04-13 10:55:34
1.1K0
修改2020-04-13 10:55:34
举报
文章被收录于专栏:登录 小程序登录 小程序

// 点击登录

getuserinfo: function (e) {

console.log(wx.getStorageSync("userInfo").id )

if (wx.getStorageSync("userInfo").id == "undefined") {//判断是否登录

this.setData({

        popping: true,

})

}

let that = this

wx.getSetting({

success: function (Setting_res) {

if (Setting_res.authSetting['scope.userInfo']) {

// 已经授权,可以直接调用 getUserInfo 获取头像昵称

wx.showLoading({

            title: '登录中...',

            mask: true

})

wx.login({

success: function (login_res) {

let code = login_res.code

console.log(2222222)

// console.log(code)

wx.getUserInfo({

                withCredentials: true, //是否带上登录状态信息,

success: function (getUserInfo_res) { //获取用户信息

console.log(getUserInfo_res)

wx.setStorageSync("userInfo", getUserInfo_res.userInfo) //存入本地

Post("api/login/login", {

code, //微信

                    iv: getUserInfo_res.iv,

                    encryptedData: getUserInfo_res.encryptedData,

}).then(res => {

wx.hideLoading()

if (res.stu == 1) {

wx.showToast({

                        title: '登录成功'

})

// 控制弹窗

that.setData({

                        popping: false,

})

wx.setStorageSync("userInfo", res.result) //将信息存到本地

that.setData({

                        userInfo: res.result

})

console.log(res.result.token)

console.log(res.result.id)

new IMController({

                        token: res.result.token,

                        account: res.result.id

})

}

})

}

})

},

fail: function (res) {

},

complete: function (res) { },

})

}

},

fail: function (res) { },

complete: function (res) { },

})

},

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档