手机好授权

This commit is contained in:
zoujiandong 2023-12-19 16:53:12 +08:00
parent a36ff7e890
commit a3ad5139b3
2 changed files with 43 additions and 33 deletions

View File

@ -129,37 +129,47 @@ Page({
let THIS=this; let THIS=this;
let usertype = wx.getStorageSync('usertype'); let usertype = wx.getStorageSync('usertype');
let next_url = wx.getStorageSync('next_url'); let next_url = wx.getStorageSync('next_url');
wx.login({ if(e.detail.errMsg == 'getPhoneNumber:ok'){
success (res) { wx.login({
if (res.code) { success (res) {
console.log('登录成功!' + res.errMsg) if (res.code) {
var params = { console.log('登录成功!' + res.errMsg)
phone_code: e.detail.code, var params = {
user_type: usertype, phone_code: e.detail.code,
wx_code: res.code user_type: usertype,
} wx_code: res.code
api.wechatMobileLogin(params).then(response => {
console.log(response);
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token);
wx.setStorageSync('user_id_'+usertype, response.data.user_id);
wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id);
app.globalData.config.userID = response.data.user_id;
app.globalData.isLogin=true;
let handleGo=function(){
wx.switchTab({
url: next_url
})
} }
app.imInit({path:'Pages/login/index'},1,handleGo); api.wechatMobileLogin(params).then(response => {
//跳转页面 console.log(response);
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token);
wx.setStorageSync('user_id_'+usertype, response.data.user_id);
wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id);
app.globalData.config.userID = response.data.user_id;
app.globalData.isLogin=true;
let handleGo=function(){
wx.switchTab({
url: next_url
})
}
app.imInit({path:'Pages/login/index'},1,handleGo);
//跳转页面
}).catch(errors => {
console.error(errors);
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}else if(e.detail.errMsg == 'getPhoneNumber:fail user deny'){
console.log('您拒绝手机号授权')
}else{
wx.showToast({
title: '手机号授权失败',
icon:'none'
})
}
}).catch(errors => {
console.error(errors);
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}, },
}) })

View File

@ -18,11 +18,11 @@
wx:if="{{ checked }}" wx:if="{{ checked }}"
open-type="getPhoneNumber" open-type="getPhoneNumber"
bindgetphonenumber="getPhoneNumber" bindgetphonenumber="getPhoneNumber"
color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>微信授权手机号登录</van-button> color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>手机号快捷登录</van-button>
<van-button <van-button
wx:else wx:else
bindtap="getPhoneNumber" bindtap="getPhoneNumber"
color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>微信授权手机号登录</van-button> color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>手机号快捷登录</van-button>
<view style="display: flex;margin-top: 30rpx;line-height: 50rpx;"> <view style="display: flex;margin-top: 30rpx;line-height: 50rpx;">
<van-checkbox value="{{ checked }}" bind:change="onChange"></van-checkbox> <van-checkbox value="{{ checked }}" bind:change="onChange"></van-checkbox>