APP支持本机号码一键登录
parent
a18922b266
commit
0eb6b9ff5e
194
App.vue
194
App.vue
|
|
@ -356,96 +356,124 @@
|
||||||
|
|
||||||
// app登录处理
|
// app登录处理
|
||||||
app_login_handle(self, object, method, params) {
|
app_login_handle(self, object, method, params) {
|
||||||
// 是否存在一键登录服务
|
// 是否开启一键登录服务
|
||||||
uni.getProvider({
|
if(self.get_config('plugins_base.thirdpartylogin.data.apponekeyusermobile_is_enable') == 1) {
|
||||||
service: 'oauth',
|
uni.getProvider({
|
||||||
success: function (res) {
|
service: 'oauth',
|
||||||
if(res.provider.includes('univerify')) {
|
success: function (res) {
|
||||||
// 预登录检查
|
if(res.provider.includes('univerify')) {
|
||||||
uni.preLogin({
|
// 预登录检查
|
||||||
provider: 'univerify',
|
uni.preLogin({
|
||||||
success(res) {
|
provider: 'univerify',
|
||||||
// 显示一键登录弹窗
|
success(res) {
|
||||||
var theme_color = self.get_theme_color();
|
// 显示一键登录弹窗
|
||||||
var theme_color_light = self.get_theme_color(null, true);
|
var theme_color = self.get_theme_color();
|
||||||
uni.login({
|
var theme_color_light = self.get_theme_color(null, true);
|
||||||
provider: 'univerify',
|
uni.login({
|
||||||
univerifyStyle: {
|
provider: 'univerify',
|
||||||
authButton: {
|
univerifyStyle: {
|
||||||
// 授权按钮正常状态背景颜色 默认值:#3479f5
|
authButton: {
|
||||||
normalColor: theme_color,
|
// 授权按钮正常状态背景颜色 默认值:#3479f5
|
||||||
// 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
|
normalColor: theme_color,
|
||||||
highlightColor: theme_color_light,
|
// 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
|
||||||
// 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
|
highlightColor: theme_color_light,
|
||||||
disabledColor: theme_color_light,
|
// 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
|
||||||
|
disabledColor: theme_color_light,
|
||||||
|
// 授权按钮文案 默认值:“本机号码一键登录”
|
||||||
|
title: '本机号码一键登录',
|
||||||
|
},
|
||||||
|
otherLoginButton: {
|
||||||
|
// 其他登录方式按钮文字 默认值:“其他登录方式”
|
||||||
|
title: '其他登录方式',
|
||||||
|
},
|
||||||
|
privacyTerms: {
|
||||||
|
// 条款前的文案 默认值:“我已阅读并同意”
|
||||||
|
prefix: '我已阅读并同意',
|
||||||
|
// 条款后的文案 默认值:“并使用本机号码登录”
|
||||||
|
suffix: '并使用本机号码登录',
|
||||||
|
// 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
|
||||||
|
privacyItems: [
|
||||||
|
{
|
||||||
|
url: self.get_config('config.agreement_userregister_url'),
|
||||||
|
title: '服务协议'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: self.get_config('config.agreement_userprivacy_url'),
|
||||||
|
title: '隐私权政策'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
privacyTerms: {
|
success(res) {
|
||||||
// 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
|
// 在得到access_token和openid后,通过callfunction调用云函数
|
||||||
privacyItems: [
|
uniCloud.callFunction({
|
||||||
{
|
name: 'getPhoneNumber',
|
||||||
url: self.get_config('config.agreement_userregister_url'),
|
data: {
|
||||||
title: '服务协议'
|
access_token: res.authResult.access_token,
|
||||||
},
|
openid: res.authResult.openid
|
||||||
{
|
|
||||||
url: self.get_config('config.agreement_userprivacy_url'),
|
|
||||||
title: '隐私权政策'
|
|
||||||
}
|
}
|
||||||
]
|
}).then(res => {
|
||||||
|
uni.request({
|
||||||
|
url: self.get_request_url('apponekeyusermobile', 'index', 'thirdpartylogin'),
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
mobile: res.result
|
||||||
|
},
|
||||||
|
dataType: 'json',
|
||||||
|
success: (res) => {
|
||||||
|
uni.closeAuthView();
|
||||||
|
if(res.data.code == 0) {
|
||||||
|
uni.setStorageSync(self.data.cache_user_info_key, res.data.data);
|
||||||
|
if (typeof object === 'object' && (method || null) != null) {
|
||||||
|
object[method](params);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.showToast(res.data.msg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
uni.closeAuthView();
|
||||||
|
self.showToast('网络开小差了哦~');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
uni.closeAuthView();
|
||||||
|
self.showToast('本机号码组件调起失败');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
fail(res) {
|
||||||
success(res) {
|
|
||||||
// 登录成功
|
|
||||||
// {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
|
|
||||||
console.log(res.authResult, 'success');
|
|
||||||
// 在得到access_token后,通过callfunction调用云函数
|
|
||||||
uniCloud.callFunction({
|
|
||||||
name: 'uni-id-cf',
|
|
||||||
data: {
|
|
||||||
access_token: res.authResult.access_token,
|
|
||||||
openid: res.authResult.openid
|
|
||||||
}
|
|
||||||
}).then(res => {
|
|
||||||
// res.result = {
|
|
||||||
// code: '',
|
|
||||||
// message: ''
|
|
||||||
// }
|
|
||||||
// 登录成功,可以关闭一键登录授权界面了
|
|
||||||
console.log(res, 'success')
|
|
||||||
}).catch(err=>{
|
|
||||||
// 处理错误
|
|
||||||
console.log(err, 'error')
|
|
||||||
});
|
|
||||||
},
|
|
||||||
fail(res) {
|
|
||||||
// 用户点击了其他登录方式、则进入登录页面
|
|
||||||
if(res.errCode == 30002) {
|
|
||||||
// 关闭一键登录弹窗
|
// 关闭一键登录弹窗
|
||||||
uni.closeAuthView();
|
uni.closeAuthView();
|
||||||
// 进入独立登录注册页面
|
// 用户点击了其他登录方式、则进入登录页面
|
||||||
uni.navigateTo({
|
if(res.errCode == 30002) {
|
||||||
url: '/pages/login/login',
|
// 进入独立登录注册页面
|
||||||
});
|
uni.navigateTo({
|
||||||
} else {
|
url: '/pages/login/login',
|
||||||
// 用户不是点击关闭验证界面则提示错误
|
});
|
||||||
if(res.errCode != 30003) {
|
} else {
|
||||||
app.globalData.showToast(res.errMsg+'('+res.errCode+')');
|
// 用户不是点击关闭验证界面则提示错误
|
||||||
|
if(res.errCode != 30003) {
|
||||||
|
self.showToast(res.errMsg+'('+res.errCode+')');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
},
|
||||||
},
|
fail(res) {
|
||||||
fail(res) {
|
self.login_confirm_tips_modal();
|
||||||
self.login_confirm_tips_modal();
|
}
|
||||||
}
|
});
|
||||||
});
|
} else {
|
||||||
} else {
|
self.login_confirm_tips_modal();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
self.login_confirm_tips_modal();
|
self.login_confirm_tips_modal();
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
fail(res) {
|
} else {
|
||||||
self.login_confirm_tips_modal();
|
self.login_confirm_tips_modal();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 确认提示登录弹窗
|
// 确认提示登录弹窗
|
||||||
|
|
@ -2019,7 +2047,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
fail: (res) => {
|
||||||
app.globalData.showToast('请先获取授权');
|
self.showToast('请先获取授权');
|
||||||
if (typeof object === 'object' && (method || null) != null) {
|
if (typeof object === 'object' && (method || null) != null) {
|
||||||
object[method](0);
|
object[method](0);
|
||||||
}
|
}
|
||||||
|
|
@ -2032,7 +2060,7 @@
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-KUAISHOU
|
// #ifdef MP-KUAISHOU
|
||||||
app.globalData.showToast('不支持地理位置选择!');
|
self.showToast('不支持地理位置选择!');
|
||||||
if (typeof object === 'object' && (method || null) != null) {
|
if (typeof object === 'object' && (method || null) != null) {
|
||||||
object[method](0);
|
object[method](0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- #ifndef H5 -->
|
<!-- #ifndef H5 -->
|
||||||
<view v-if="item.index == 0" class="scan-item border-radius-main tc pa right-0 top-0" :data-index="index" @tap="search_icon_event">
|
<view v-if="item.key == 0" class="scan-item border-radius-main tc pa right-0 top-0" :data-index="index" @tap="search_icon_event">
|
||||||
<iconfont name="icon-mendian-sousuosm" size="36rpx" propClass="lh-il va-m" color="#02b3c2"></iconfont>
|
<iconfont name="icon-mendian-sousuosm" size="36rpx" propClass="lh-il va-m" color="#02b3c2"></iconfont>
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
|
|
|
||||||
|
|
@ -904,7 +904,7 @@
|
||||||
form_input_image_verify_value: '',
|
form_input_image_verify_value: '',
|
||||||
});
|
});
|
||||||
this.image_verify_event(image_verify_type);
|
this.image_verify_event(image_verify_type);
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -958,7 +958,7 @@
|
||||||
this.setData({
|
this.setData({
|
||||||
form_submit_loading: false,
|
form_submit_loading: false,
|
||||||
});
|
});
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1001,7 +1001,7 @@
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1074,7 +1074,7 @@
|
||||||
this.setData({
|
this.setData({
|
||||||
form_submit_loading: false,
|
form_submit_loading: false,
|
||||||
});
|
});
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1143,7 +1143,7 @@
|
||||||
this.setData({
|
this.setData({
|
||||||
form_submit_loading: false,
|
form_submit_loading: false,
|
||||||
});
|
});
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1201,7 +1201,7 @@
|
||||||
this.setData({
|
this.setData({
|
||||||
form_submit_loading: false,
|
form_submit_loading: false,
|
||||||
});
|
});
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1239,7 +1239,7 @@
|
||||||
this.setData({
|
this.setData({
|
||||||
form_submit_loading: false,
|
form_submit_loading: false,
|
||||||
});
|
});
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1517,7 +1517,7 @@
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
fail: (res) => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -225,9 +225,9 @@
|
||||||
self.setData({
|
self.setData({
|
||||||
data_list_loding_status: 2,
|
data_list_loding_status: 2,
|
||||||
data_bottom_line_status: false,
|
data_bottom_line_status: false,
|
||||||
data_list_loding_msg: this.$t('common.internet_error'),
|
data_list_loding_msg: this.$t('common.internet_error_tips'),
|
||||||
});
|
});
|
||||||
app.globalData.showToast(this.$t('common.internet_error'));
|
app.globalData.showToast(this.$t('common.internet_error_tips'));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
'use strict';
|
||||||
|
exports.main = async(event, context) => {
|
||||||
|
const res = await uniCloud.getPhoneNumber({
|
||||||
|
provider: 'univerify',
|
||||||
|
access_token: event.access_token,
|
||||||
|
openid: event.openid
|
||||||
|
});
|
||||||
|
return (res.code == 0) ? res.phoneNumber : null;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "getPhoneNumber",
|
||||||
|
"dependencies": {},
|
||||||
|
"extensions": {
|
||||||
|
"uni-cloud-verify": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue