APP支持QQ和微信登录

master
gongfuxiang 2023-11-29 00:08:12 +08:00
parent d2ba36e030
commit f4b4548c27
4 changed files with 128 additions and 117 deletions

View File

@ -6,13 +6,13 @@
//
//
// request_url: 'https://new.shopxo.vip/',
// request_url: 'https://d1.shopxo.vip/',
request_url: 'http://shopxo.com/',
request_url: 'https://d1.shopxo.vip/',
// request_url: 'http://shopxo.com/',
// publicpublichttps://d1.shopxo.vip/public/
// static_url: 'https://new.shopxo.vip/',
// static_url: 'https://d1.shopxo.vip/',
static_url: 'http://shopxo.com/',
static_url: 'https://d1.shopxo.vip/',
// static_url: 'http://shopxo.com/',
// default
system_type: 'default',

View File

@ -29,6 +29,8 @@
"processing_in_text": "处理中...",
"loading_in_text": "加载中...",
"upload_in_text": "上传中...",
"auth_in_text": "授权中...",
"login_in_text": "登录中...",
"sending_in_text": "发送中...",
"sending": "发送中",
"warm_tips": "温馨提示",

View File

@ -64,8 +64,8 @@
},
"weixin" : {
"__platform__" : [ "ios", "android" ],
"appid" : "wx6ce676d70c00d5d1",
"UniversalLinks" : "https://www.ntfqw.com/.well-known/"
"appid" : "wx3bac19ff90c0a976",
"UniversalLinks" : "https://d1.shopxo.vip/.well-known/"
}
},
"push" : {},
@ -73,13 +73,13 @@
"oauth" : {
"apple" : {},
"weixin" : {
"appid" : "wx6ce676d70c00d5d1",
"appsecret" : "c549f30ba2404a7b1449323c9e55a614",
"UniversalLinks" : "https://www.ntfqw.com/.well-known/"
"appid" : "wx3bac19ff90c0a976",
"appsecret" : "91f132b39c5c575fe61b04993c57c734",
"UniversalLinks" : "https://d1.shopxo.vip/.well-known/"
},
"qq" : {
"appid" : "101944843",
"UniversalLinks" : "https://www.ntfqw.com/.well-known/"
"appid" : "102076195",
"UniversalLinks" : "https://d1.shopxo.vip/.well-known/"
}
},
"maps" : {
@ -96,12 +96,12 @@
},
"share" : {
"weixin" : {
"appid" : "wx6ce676d70c00d5d1",
"UniversalLinks" : "https://www.ntfqw.com/.well-known/"
"appid" : "wx3bac19ff90c0a976",
"UniversalLinks" : "https://d1.shopxo.vip/.well-known/"
},
"qq" : {
"appid" : "101944843",
"UniversalLinks" : "https://www.ntfqw.com/.well-known/"
"appid" : "102076195",
"UniversalLinks" : "https://d1.shopxo.vip/.well-known/"
}
}
},

View File

@ -4,7 +4,8 @@
<block v-if="(is_exist_base_data || 0) == 1">
<view class="flex-col jc-sb dom-content">
<view>
<view class="flex-row tr top-nav margin-bottom-xxxl">
<!-- 多语言切换 -->
<view class="flex-row tr top-nav margin-bottom-xl">
<view class="flex-1 cr-base text-size" @tap="open_language_event">
<view class="pr top-sm margin-right-sm dis-inline-block">
<iconfont name="icon-login-language" size="32rpx"></iconfont>
@ -80,11 +81,13 @@
</view>
<!-- 绑定账号提示 -->
<view v-if="(plugins_thirdpartylogin_user || null) != null && (plugins_thirdpartylogin_user.is_force_bind_user || 0) == 1" class="plugins-thirdpartylogin-bind tc padding-horizontal-main margin-top-xxxl">
<image :src="plugins_thirdpartylogin_user.avatar" mode="aspectFit" class="round br va-m"></image>
<text class="cr-blue margin-left-sm">{{ plugins_thirdpartylogin_user.nickname }}</text>
<text class="va-m margin-left-lg cr-grey">{{ $t('login.login.e77788') }}{{ plugins_thirdpartylogin_user.platform_name }}{{ $t('login.login.1i4o86') }}</text>
<button type="default" size="mini" class="br-red cr-red bg-white round va-m text-size-xs margin-left-lg padding-top-xs padding-bottom-xs" @tap="plugins_thirdpartylogin_cancel_event">{{ $t('common.cancel') }}</button>
<view v-if="(plugins_thirdpartylogin_user || null) != null && (plugins_thirdpartylogin_user.is_force_bind_user || 0) == 1" class="plugins-thirdpartylogin-bind tc padding-horizontal-main margin-top-xl">
<view class="margin-bottom-sm">
<image :src="plugins_thirdpartylogin_user.avatar" mode="aspectFit" class="round br va-m"></image>
<text class="cr-blue margin-left-sm">{{ plugins_thirdpartylogin_user.nickname }}</text>
<button type="default" size="mini" class="br-red cr-red bg-white round va-m text-size-xs margin-left-lg padding-top-xs padding-bottom-xs" @tap="plugins_thirdpartylogin_cancel_event">{{ $t('common.cancel') }}</button>
</view>
<view class="cr-grey text-size-xs">{{ $t('login.login.e77788') }}{{ plugins_thirdpartylogin_user.platform_name }}{{ $t('login.login.1i4o86') }}</view>
</view>
</block>
@ -519,7 +522,7 @@
this.init_config(true);
//
var user = app.globalData.get_user_cache_info();
var user = app.globalData.get_user_cache_info() || null;
//
var type = user == null ? 'auth' : 'bind';
@ -694,7 +697,7 @@
//
user_auth_back_event() {
var user = app.globalData.get_user_cache_info();
var user = app.globalData.get_user_cache_info() || null;
this.setData({
user: user,
});
@ -902,17 +905,24 @@
//
formBind(e) {
//
//
var client_type = app.globalData.application_client_type();
var user = this.user || this.plugins_thirdpartylogin_user || app.globalData.get_login_cache_info() || {};
e.detail.value['nickname'] = user.nickname;
e.detail.value['avatar'] = user.avatar;
e.detail.value['province'] = user.province;
e.detail.value['city'] = user.city;
e.detail.value['gender'] = user.gender;
//
// #ifdef MP
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = this.user[field_openid] || '';
e.detail.value[field_unionid] = this.user[field_unionid] || '';
e.detail.value['nickname'] = this.user.nickname;
e.detail.value['avatar'] = this.user.avatar;
e.detail.value['province'] = this.user.province;
e.detail.value['city'] = this.user.city;
e.detail.value['gender'] = this.user.gender;
e.detail.value[field_openid] = user[field_openid] || '';
e.detail.value[field_unionid] = user[field_unionid] || '';
// #endif
//
var validation = [
{ fields: 'mobile', msg: this.$t('login.login.4c5n8o') },
{ fields: 'verify', msg: this.$t('login.login.01xmab') },
@ -956,20 +966,21 @@
if ((encrypted_data != null && iv != null) || code != null) {
//
var client_type = app.globalData.application_client_type();
var user = this.user || this.plugins_thirdpartylogin_user || app.globalData.get_login_cache_info() || {};
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
var data = {
encrypted_data: encrypted_data,
iv: iv,
code: code,
openid: this.user[field_openid] || '',
nickname: this.user.nickname || '',
avatar: this.user.avatar || '',
province: this.user.province || '',
city: this.user.city || '',
gender: this.user.gender || 0,
openid: user[field_openid] || '',
nickname: user.nickname || '',
avatar: user.avatar || '',
province: user.province || '',
city: user.city || '',
gender: user.gender || 0,
};
data[field_unionid] = this.user[field_unionid] || '';
data[field_unionid] = user[field_unionid] || '';
uni.showLoading({
title: this.$t('common.processing_in_text'),
});
@ -1021,23 +1032,20 @@
//
e.detail.value['type'] = this.current_opt_type.replace('login_', '');
//
var client_type = app.globalData.application_client_type();
var user = this.user || this.plugins_thirdpartylogin_user || app.globalData.get_login_cache_info() || {};
e.detail.value['nickname'] = user.nickname;
e.detail.value['avatar'] = user.avatar;
e.detail.value['province'] = user.province;
e.detail.value['city'] = user.city;
e.detail.value['gender'] = user.gender;
// #ifdef MP
//
var client_type = app.globalData.application_client_type();
if ((this.user || null) != null) {
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = this.user[field_openid] || '';
e.detail.value[field_unionid] = this.user[field_unionid] || '';
} else {
var login_data = app.globalData.get_login_cache_info();
if (login_data != null) {
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = login_data['openid'] || '';
e.detail.value[field_unionid] = login_data['unionid'] || '';
}
}
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = user[field_openid] || '';
e.detail.value[field_unionid] = user[field_unionid] || '';
// #endif
//
@ -1092,28 +1100,21 @@
//
e.detail.value['type'] = this.current_opt_type.replace('reg_', '');
//
var client_type = app.globalData.application_client_type();
var user = this.user || this.plugins_thirdpartylogin_user || app.globalData.get_login_cache_info() || {};
e.detail.value['nickname'] = user.nickname;
e.detail.value['avatar'] = user.avatar;
e.detail.value['province'] = user.province;
e.detail.value['city'] = user.city;
e.detail.value['gender'] = user.gender;
// #ifdef MP
//
var client_type = app.globalData.application_client_type();
if ((this.user || null) != null) {
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = this.user[field_openid] || '';
e.detail.value[field_unionid] = this.user[field_unionid] || '';
e.detail.value['nickname'] = this.user.nickname;
e.detail.value['avatar'] = this.user.avatar;
e.detail.value['province'] = this.user.province;
e.detail.value['city'] = this.user.city;
e.detail.value['gender'] = this.user.gender;
} else {
var login_data = app.globalData.get_login_cache_info();
if (login_data != null) {
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = login_data['openid'] || '';
e.detail.value[field_unionid] = login_data['unionid'] || '';
}
}
var field_openid = client_type + '_openid';
var field_unionid = client_type + '_unionid';
e.detail.value[field_openid] = user[field_openid] || '';
e.detail.value[field_unionid] = user[field_unionid] || '';
// #endif
//
@ -1424,30 +1425,23 @@
// #endif
// #ifdef APP
let $this = this;
switch(type) {
// QQ
case 'weixin' :
case 'qq' :
let $this = this
//console.log("weixin")
uni.login({
provider: type,
success: function (loginRes) {
let {authResult} = loginRes
//console.log("",authResult)
let post_data = {
pluginsname:"thirdpartylogin",
pluginscontrol:"index",
pluginsaction:"bind",
platform:type,
openid:authResult['openid'],
access_token:authResult['access_token']
}
$this.loginByThirdAction(post_data,authResult)
success: function(res) {
let auth_result = res.authResult;
$this.app_login_bind_handle({
platform: type,
openid: auth_result['openid'],
access_token: auth_result['access_token']
}, auth_result);
},
fail: function (error) {
// {"errMsg":"login:fail ,https://ask.dcloud.net.cn/article/282","errCode":-7,"code":-7}
console.log(JSON.stringify(error));
app.globalData.showToast(error.errMsg || '调用登录SDK失败');
},
});
break;
@ -1480,7 +1474,7 @@
openid:openId
}
console.log("请求参数",post_data)
$this.loginByThirdAction(post_data,userInfo)
$this.app_login_bind_handle(post_data,userInfo)
}
})
@ -1492,33 +1486,48 @@
},
//
async loginByThirdAction(post_data,authResult){
console.log(post_data)
console.log(authResult)
return;
try{
let {data} = await this.loadingFn(apiResquest('plugins/index', "POST", post_data))
let {is_force_bind_user,...other} = data
if(is_force_bind_user && is_force_bind_user==1){
this.$store.dispatch('thirdLoginAction',{...authResult,...other,platform:post_data["platform"]})
setTimeout(function(){
uni.redirectTo({
url:`/pages/login/bind/bind`
})
},500)
}else{
this.$store.dispatch('loginKeyAction',other.token || other.user_name_view)
this.$store.dispatch('shopUserInfoAction',other)
this.$api.msg("登录成功!",2000,true,'success')
setTimeout(function(){
uni.navigateBack({delta: 1 });
},1500)
}
}catch(e){
console.log(e)
this.$api.msg(e,2000)
}
app_login_bind_handle(post_data, auth_result) {
uni.showLoading({
title: this.$t('common.loading_in_text'),
});
uni.request({
url: app.globalData.get_request_url('bind', 'index', 'thirdpartylogin'),
method: 'POST',
data: post_data,
dataType: 'json',
success: (res) => {
uni.hideLoading();
if (res.data.code == 0) {
var user = {...res.data.data, ...auth_result};
//
this.setData({
plugins_thirdpartylogin_user: user
});
//
if ((user.is_force_bind_user || 0) != 1) {
this.setData({
user: user
});
//
uni.setStorageSync(app.globalData.data.cache_user_info_key, user);
//
this.success_back_handle(res);
}
//
this.init();
} else {
app.globalData.showToast(res.data.msg);
}
},
fail: () => {
uni.hideLoading();
app.globalData.showToast(this.$t('common.internet_error'));
},
});
},
//