提交 49f048cf authored 作者: haodaking's avatar haodaking

fix:修复登录失败的问题

上级 24de17c8
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
}, },
"plugins": { "plugins": {
"tencentvideo": { "tencentvideo": {
"version": "1.5.2", "version": "2.0.5",
"provider": "wxa75efa648b60994b" "provider": "wxa75efa648b60994b"
} }
}, },
......
...@@ -27,38 +27,48 @@ Page({ ...@@ -27,38 +27,48 @@ Page({
}, },
// 获取用户code // 获取用户code
getCode(callback) { getCode(callback) {
wx.login({ return new Promise((resolve, reject) => {
success(res) { wx.login({
if (res.code) { success(res) {
callback && callback(res.code) if (res.code) {
} else { callback && callback(res.code)
resolve(res.code)
} else {
wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' })
reject(res)
}
},
fail(res) {
wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' }) wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' })
reject(res)
} }
}, })
fail(res) {
wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' })
}
}) })
}, },
// 获取用户信息 // 获取用户信息
getUserInfo(callback) { getUserInfo(callback) {
wx.getUserProfile({ return new Promise((resolve, reject) => {
desc: '登录注册', wx.getUserProfile({
success(res) { desc: '登录注册',
callback && callback(res) success(res) {
}, callback && callback(res)
fail(res) { resolve(res)
wx.showToast({ title: `获取用户信息失败!`, icon: 'none' }) },
} fail(res) {
wx.showToast({ title: `获取用户信息失败!`, icon: 'none' })
reject(res)
}
})
}) })
}, },
// 微信登录 // 微信登录
wechatLogin() { wechatLogin() {
// 获取code
const p1 = this.getCode()
// 获取用户信息 // 获取用户信息
this.getUserInfo(user => { const p2 = this.getUserInfo()
// 获取code Promise.all([p1, p2]).then(([code, user]) => {
this.getCode(code => { const { encryptedData, iv } = user
const { encryptedData, iv } = user
api.wechatLogin({ encryptedData, iv, code, identity: 'seg-mini' }).then(response => { api.wechatLogin({ encryptedData, iv, code, identity: 'seg-mini' }).then(response => {
if (response.code === 0) { if (response.code === 0) {
this.handleSuccess(response.data) this.handleSuccess(response.data)
...@@ -69,7 +79,6 @@ Page({ ...@@ -69,7 +79,6 @@ Page({
wx.showToast({ title: response.msg, icon: 'none' }) wx.showToast({ title: response.msg, icon: 'none' })
} }
}) })
})
}) })
}, },
// 手机号登录 // 手机号登录
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
"showES6CompileOption": false "showES6CompileOption": false
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.12.2", "libVersion": "2.21.3",
"appid": "wxeef6398b18cebb5e", "appid": "wxeef6398b18cebb5e",
"projectname": "learnOnline", "projectname": "learnOnline",
"isGameTourist": false, "isGameTourist": false,
...@@ -97,4 +97,4 @@ ...@@ -97,4 +97,4 @@
] ]
} }
} }
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论