微信授权登录,获取授权凭证改为后端获取
This commit is contained in:
+6
-22
@@ -97,7 +97,6 @@ Page({
|
||||
wx.getStorage({
|
||||
key: 'authorize',
|
||||
success(result){
|
||||
console.log('result=======', result)
|
||||
// 做过查看微信用户信息
|
||||
if(result.data){ // 做过用户信息获取
|
||||
wx.showToast({
|
||||
@@ -106,7 +105,7 @@ Page({
|
||||
})
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
openId: res.result.openid,
|
||||
rsaPublicKey: that.data.rsaPublicKey
|
||||
}
|
||||
UserApi.wxLogin(params).then(res=>{
|
||||
@@ -116,14 +115,14 @@ Page({
|
||||
key: 'X-Access-Token',
|
||||
data: res.result.token
|
||||
})
|
||||
wx.switchTab({
|
||||
url: '../home/home',
|
||||
})
|
||||
wx.setStorageSync('authorize', true) // 设置有过微信授权
|
||||
wx.setStorage({
|
||||
key: 'avatarUrl',
|
||||
data: result.avatarUrl
|
||||
})
|
||||
wx.switchTab({
|
||||
url: '../home/home',
|
||||
})
|
||||
}else{ // 首次登录不能直接用微信快捷登录
|
||||
wx.showToast({
|
||||
title: '暂无授权手机号',
|
||||
@@ -138,7 +137,6 @@ Page({
|
||||
},
|
||||
fail(err){
|
||||
// 没有做过查看微信用户信息
|
||||
console.log('err========', err)
|
||||
that.getUserInfo()
|
||||
}
|
||||
})
|
||||
@@ -149,13 +147,11 @@ Page({
|
||||
wx.showModal({
|
||||
title: '温馨提示',
|
||||
content: `亲,授权微信登录后才能正常使用小程序功能`,
|
||||
cancelColor: 'cancelColor',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
wx.getUserProfile({
|
||||
desc: '获取你的昵称、头像、地区及性别',
|
||||
success(result){
|
||||
console.log('result用于完善用户信息', result)
|
||||
let userInfoTemp = JSON.parse(result.rawData)
|
||||
wx.setStorage({
|
||||
key: 'userInfoTemp',
|
||||
@@ -170,7 +166,7 @@ Page({
|
||||
})
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
openId: res.result.openid,
|
||||
rsaPublicKey: that.data.rsaPublicKey
|
||||
}
|
||||
UserApi.wxLogin(params).then(res=>{
|
||||
@@ -195,7 +191,6 @@ Page({
|
||||
})
|
||||
},
|
||||
fail(err){
|
||||
console.log('err===========', err)
|
||||
wx.setStorageSync('authorize', false)
|
||||
}
|
||||
})
|
||||
@@ -204,17 +199,6 @@ Page({
|
||||
}
|
||||
}
|
||||
})
|
||||
// wx.showModal({
|
||||
// title: '错误提示',
|
||||
// content: `图片大于${that.data.maxSize}MB`,
|
||||
// showCancel: false,
|
||||
// success(res) {
|
||||
// if (res.confirm) {
|
||||
// console.log('用户点击确定')
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
},
|
||||
// 登录
|
||||
formSubmit(e) {
|
||||
@@ -293,7 +277,7 @@ Page({
|
||||
const that = this
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
openId: res.result.openid,
|
||||
rsaPublicKey: that.data.rsaPublicKey
|
||||
}
|
||||
// 需要判断是否绑定过微信,再进行绑定请求
|
||||
|
||||
Reference in New Issue
Block a user