第三方登录-google-google email与email注册的account绑定

This commit is contained in:
khalil
2025-07-10 11:46:10 +08:00
parent d0d6e4b5be
commit e5c66e89a1
4 changed files with 79 additions and 48 deletions

View File

@@ -142,6 +142,7 @@ public class AccountManageService {
throw new ServiceException(BusiStatus.REQUEST_FAST);
}
Account account = null;
String thirdAccountEmail = null;
if (LoginTypeEnum.GOOGLE.getValue() == type) {
@@ -150,53 +151,34 @@ public class AccountManageService {
openid = ref.getOpenId();
unionId = ref.getOpenId();
thirdAccountEmail = ref.getEmail();
if (ref.isRegister()){
Account emailAccount = accountService.getAccountByEmail(thirdAccountEmail);
if (null != emailAccount && null == emailAccount.getThirdLoginType()){
emailAccount.setThirdLoginType(type);
emailAccount.setUnionId(unionId);
emailAccount.setOpenId(openid);
accountMapper.updateById(emailAccount);
account = emailAccount;
}
}
}
}
Account account = accountService.getAccountByThird(type, unionId, null);
if (account == null) {
checkRegisterLimit(deviceInfo.getDeviceId(), ipAddress);
if (null == account){
account = accountService.getAccountByThird(type, unionId);
}
Date date = new Date();
account = new Account();
account.setNeteaseToken(UUIDUtil.get());
account.setLastLoginTime(date);
account.setLastLoginIp(ipAddress);
account.setUpdateTime(date);
account.setRegisterIp(ipAddress);
account.setSignTime(date);
account.setState("1");
account.setErbanNo(erBanNoService.getErBanNo());
account.setPhone(CommonUtil.genSpecialPhoneForInitAccount(account.getErbanNo().toString()));
// 三方登录信息
account.setThirdLoginType(type);
account.setUnionId(unionId);
account.setOpenId(openid);
account.setEmail(thirdAccountEmail);
account = fillDeviceInfo(account, deviceInfo);
accountMapper.insert(account);
//写缓存
accountService.writeAche(account);
String uidStr = String.valueOf(account.getUid());
TokenRet tokenRet = netEaseService.createNetEaseAcc(uidStr, account.getNeteaseToken(), "", "", null);
if (tokenRet.getCode() != 200) {
log.info("注册云信账号失败,openid=" + openid + "&uid=" + uidStr + ",异常原因code=" + tokenRet.getCode());
log.error("注册云信账号失败,openid=" + openid + "&uid=" + uidStr + ",异常原因code=" + tokenRet.getCode());
throw new Exception("第三方登录失败,openid=" + openid + ",异常原因code=" + tokenRet.getCode());
}
} else {
if (null != account){
// 已存在用户先判断account中的unionId是否为空或者不一致如果是的话则更新不是则跳过
String state = account.getState();
if ("2".equals(state)) {
if (Constant.AccountState.block.equals(state)) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.INVALID_USER,
"用户账号异常请联系官方客服uid=" + account.getUid());
}
Boolean bol =
(BlankUtil.isBlank(account.getUnionId())) || !account.getUnionId().equals(unionId);
if (bol) {
if (BlankUtil.isBlank(account.getUnionId()) || !account.getUnionId().equals(unionId)) {
account.setUnionId(unionId);
}
account.setLastLoginTime(new Date());
@@ -204,7 +186,43 @@ public class AccountManageService {
account.setUpdateTime(new Date());
accountMapper.updateById(account);
}
checkRegisterLimit(deviceInfo.getDeviceId(), ipAddress);
Date date = new Date();
account = new Account();
account.setLastLoginTime(date);
account.setLastLoginIp(ipAddress);
account.setUpdateTime(date);
account.setRegisterIp(ipAddress);
account.setSignTime(date);
account.setState(Constant.AccountState.normal);
account.setErbanNo(erBanNoService.getErBanNo());
account.setPhone(CommonUtil.genSpecialPhoneForInitAccount(account.getErbanNo().toString()));
// 三方登录信息
account.setThirdLoginType(type);
account.setUnionId(unionId);
account.setOpenId(openid);
account.setEmail(thirdAccountEmail);
account.setNeteaseToken(UUIDUtil.get());
account = fillDeviceInfo(account, deviceInfo);
accountMapper.insert(account);
//写缓存
accountService.writeAche(account);
String uidStr = String.valueOf(account.getUid());
TokenRet tokenRet = netEaseService.createNetEaseAcc(uidStr, account.getNeteaseToken(), "", "", null);
if (tokenRet.getCode() != 200) {
log.info("注册云信账号失败,openid=" + openid + "&uid=" + uidStr + ",异常原因code=" + tokenRet.getCode());
log.error("注册云信账号失败,openid=" + openid + "&uid=" + uidStr + ",异常原因code=" + tokenRet.getCode());
throw new Exception("第三方登录失败,openid=" + openid + ",异常原因code=" + tokenRet.getCode());
}
return account;
} finally {
jedisLockService.unlock(locKey, lockVal);
}