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
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
// #2861c5ios normalColor: theme_color,
highlightColor: theme_color_light, // #2861c5ios
// #73aaf5ios highlightColor: theme_color_light,
disabledColor: 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: { success(res) {
// 2urltitle. // access_tokenopenidcallfunction
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_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) {
// //
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);
} }

View File

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

View File

@ -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'));
}, },
}); });
}, },

View File

@ -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'));
}, },
}); });
}, },

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": {}
}
}