微信授权登录,获取授权凭证改为后端获取
This commit is contained in:
@@ -44,7 +44,7 @@ Page({
|
||||
if (res.success) {
|
||||
this.countDown()
|
||||
wx.showToast({
|
||||
title: '发送成功'+ res.result,
|
||||
title: '发送成功',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
@@ -272,26 +272,24 @@ Page({
|
||||
wx.login({
|
||||
success (res) {
|
||||
if (res.code) {
|
||||
//发起网络请求
|
||||
wx.request({
|
||||
url: 'https://api.weixin.qq.com/sns/jscode2session',
|
||||
data: {
|
||||
appid: 'wx24914e866df035fb',
|
||||
secret: '0d2830f26f57722716249f2b2236f409',
|
||||
js_code: res.code,
|
||||
grant_type: 'authorization_code'
|
||||
},
|
||||
success (res) { // 成功拿到openId
|
||||
let params = {
|
||||
appid: appId,
|
||||
secret: secret,
|
||||
js_code: res.code,
|
||||
grant_type: 'authorization_code'
|
||||
}
|
||||
UserApi.getWxLoginPromise(params).then(res => {
|
||||
if (res.success) { // 成功拿到openId
|
||||
// 微信和该账号绑定
|
||||
let params = {
|
||||
openId: res.openId,
|
||||
openId: res.result.openid,
|
||||
rsaPublicKey: that.data.rsaPublicKey
|
||||
}
|
||||
UserApi.wxBind(params).then(res=>{})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log('授权失败!' + res.errMsg)
|
||||
console.log('授权失败!' + res.message)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
+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
|
||||
}
|
||||
// 需要判断是否绑定过微信,再进行绑定请求
|
||||
|
||||
@@ -190,7 +190,7 @@ Page({
|
||||
// 获取openid进行手机号和微信的绑定
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
openId: res.result.openid,
|
||||
rsaPublicKey: that.data.rsaPublicKey
|
||||
}
|
||||
// 需要判断是否绑定过微信,再进行绑定请求
|
||||
|
||||
@@ -178,7 +178,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