APP支持本机号码一键登录

master
gongfuxiang 2023-12-16 22:30:32 +08:00
parent a18922b266
commit 0eb6b9ff5e
6 changed files with 138 additions and 94 deletions

194
App.vue
View File

@ -356,96 +356,124 @@
// app
app_login_handle(self, object, method, params) {
//
uni.getProvider({
service: 'oauth',
success: function (res) {
if(res.provider.includes('univerify')) {
//
uni.preLogin({
provider: 'univerify',
success(res) {
//
var theme_color = self.get_theme_color();
var theme_color_light = self.get_theme_color(null, true);
uni.login({
provider: 'univerify',
univerifyStyle: {
authButton: {
// #3479f5
normalColor: theme_color,
// #2861c5ios
highlightColor: theme_color_light,
// #73aaf5ios
disabledColor: theme_color_light,
//
if(self.get_config('plugins_base.thirdpartylogin.data.apponekeyusermobile_is_enable') == 1) {
uni.getProvider({
service: 'oauth',
success: function (res) {
if(res.provider.includes('univerify')) {
//
uni.preLogin({
provider: 'univerify',
success(res) {
//
var theme_color = self.get_theme_color();
var theme_color_light = self.get_theme_color(null, true);
uni.login({
provider: 'univerify',
univerifyStyle: {
authButton: {
// #3479f5
normalColor: theme_color,
// #2861c5ios
highlightColor: theme_color_light,
// #73aaf5ios
disabledColor: theme_color_light,
//
title: '本机号码一键登录',
},
otherLoginButton: {
//
title: '其他登录方式',
},
privacyTerms: {
//
prefix: '我已阅读并同意',
// 使
suffix: '并使用本机号码登录',
// 2urltitle.
privacyItems: [
{
url: self.get_config('config.agreement_userregister_url'),
title: '服务协议'
},
{
url: self.get_config('config.agreement_userprivacy_url'),
title: '隐私权政策'
}
]
},
},
privacyTerms: {
// 2urltitle.
privacyItems: [
{
url: self.get_config('config.agreement_userregister_url'),
title: '服务协议'
},
{
url: self.get_config('config.agreement_userprivacy_url'),
title: '隐私权政策'
success(res) {
// access_tokenopenidcallfunction
uniCloud.callFunction({
name: 'getPhoneNumber',
data: {
access_token: res.authResult.access_token,
openid: res.authResult.openid
}
]
}).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('本机号码组件调起失败');
});
},
},
success(res) {
//
// {openid:'',access_token:' token'}
console.log(res.authResult, 'success');
// access_tokencallfunction
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) {
fail(res) {
//
uni.closeAuthView();
//
uni.navigateTo({
url: '/pages/login/login',
});
} else {
//
if(res.errCode != 30003) {
app.globalData.showToast(res.errMsg+'('+res.errCode+')');
//
if(res.errCode == 30002) {
//
uni.navigateTo({
url: '/pages/login/login',
});
} else {
//
if(res.errCode != 30003) {
self.showToast(res.errMsg+'('+res.errCode+')');
}
}
}
}
});
},
fail(res) {
self.login_confirm_tips_modal();
}
});
} else {
});
},
fail(res) {
self.login_confirm_tips_modal();
}
});
} else {
self.login_confirm_tips_modal();
}
},
fail(res) {
self.login_confirm_tips_modal();
}
},
fail(res) {
self.login_confirm_tips_modal();
}
});
});
} else {
self.login_confirm_tips_modal();
}
},
//
@ -2019,7 +2047,7 @@
}
},
fail: (res) => {
app.globalData.showToast('请先获取授权');
self.showToast('请先获取授权');
if (typeof object === 'object' && (method || null) != null) {
object[method](0);
}
@ -2032,7 +2060,7 @@
}
// #endif
// #ifdef MP-KUAISHOU
app.globalData.showToast('不支持地理位置选择!');
self.showToast('不支持地理位置选择!');
if (typeof object === 'object' && (method || null) != null) {
object[method](0);
}

View File

@ -117,7 +117,7 @@
</view>
</view>
<!-- #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>
</view>
<!-- #endif -->

View File

@ -904,7 +904,7 @@
form_input_image_verify_value: '',
});
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({
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: () => {
uni.hideLoading();
app.globalData.showToast(this.$t('common.internet_error'));
app.globalData.showToast(this.$t('common.internet_error_tips'));
},
});
} else {
@ -1074,7 +1074,7 @@
this.setData({
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({
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({
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({
form_submit_loading: false,
});
app.globalData.showToast(this.$t('common.internet_error'));
app.globalData.showToast(this.$t('common.internet_error_tips'));
},
});
} else {
@ -1517,7 +1517,7 @@
},
fail: (res) => {
uni.hideLoading();
app.globalData.showToast(this.$t('common.internet_error'));
app.globalData.showToast(this.$t('common.internet_error_tips'));
},
});
},

View File

@ -225,9 +225,9 @@
self.setData({
data_list_loding_status: 2,
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'));
},
});
},

View File

@ -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;
}

View File

@ -0,0 +1,7 @@
{
"name": "getPhoneNumber",
"dependencies": {},
"extensions": {
"uni-cloud-verify": {}
}
}