google客户端新sdk兼容登录

google客户端新sdk兼容登录
This commit is contained in:
2025-06-20 14:47:24 +08:00
committed by khalil
parent d393ede84d
commit 8a52bffaeb
9 changed files with 233 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ public interface MyUserDetailsService extends UserDetailsService {
UserDetails loadUserByPhone(String phone, String phoneAreaCode, String smsCode, DeviceInfo deviceInfo, String ipAddress) throws Exception;
UserDetails loadUserByOpenId(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId) throws Exception;
UserDetails loadUserByOpenId(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId, String idToken) throws Exception;
void login(String reqUserName, UserDetails userDetails, LoginTypeEnum loginTypeEnum, DeviceInfo deviceInfo, String smsCode) throws Exception;

View File

@@ -21,7 +21,6 @@ import com.accompany.core.service.account.LoginRecordService;
import com.accompany.core.service.account.UserAppService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.region.RegionNetworkService;
import com.accompany.core.service.user.PhoneBlackService;
import com.accompany.core.service.user.UsersBaseService;
import com.accompany.core.util.I18NMessageSourceUtil;
import com.accompany.email.service.EmailService;
@@ -155,8 +154,8 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
}
@Override
public UserDetails loadUserByOpenId(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId) throws Exception {
Account account = accountManageService.getOrGenAccountByOpenid(openid, type, deviceInfo, ipAddress, unionId);
public UserDetails loadUserByOpenId(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId, String idToken) throws Exception {
Account account = accountManageService.getOrGenAccountByOpenid(openid, type, deviceInfo, ipAddress, unionId, idToken);
if (account == null) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.USER_NOT_EXISTED,
BusiStatus.USER_NOT_EXISTED.getReasonPhrase());

View File

@@ -21,6 +21,7 @@ import com.accompany.core.service.account.ErBanNoService;
import com.accompany.core.service.account.NetEaseService;
import com.accompany.core.service.common.JedisLockService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.user.GoogleOpenidRefService;
import com.accompany.core.service.user.UserCancelRecordService;
import com.accompany.core.service.user.UsersBaseService;
import com.accompany.core.util.MD5;
@@ -74,6 +75,8 @@ public class AccountManageService {
private SmsService smsService;
@Autowired
private EmailService emailService;
@Autowired
private GoogleOpenidRefService googleOpenidRefService;
protected Gson gson = new Gson();
@@ -133,7 +136,7 @@ public class AccountManageService {
}
}
public Account getOrGenAccountByOpenid(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId) throws Exception {
public Account getOrGenAccountByOpenid(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId, String idToken) throws Exception {
log.info("getOrGenAccountByOpenid openId:{},type:{},unionId:{}", openid, type, unionId);
final String locKey = RedisKey.lock_register_by_openid.getKey(openid, unionId, String.valueOf(type));
final String lockVal = jedisLockService.lock(locKey, 10 * 1000);
@@ -141,8 +144,16 @@ public class AccountManageService {
if (BlankUtil.isBlank(lockVal)) {
throw new ServiceException(BusiStatus.REQUEST_FAST);
}
Account account = accountService.getAccountByThird(type, unionId,
LoginTypeEnum.GOOGLE.getValue() == type ? deviceInfo.getApp() : null);
boolean googleLogin = LoginTypeEnum.GOOGLE.getValue() == type;
if (googleLogin) {
String sub = googleOpenidRefService.getUnionIdByEmail(openid, idToken);
if (sub != null) {
openid = sub;
unionId = sub;
}
}
Account account = accountService.getAccountByThird(type, unionId, null);
if (account == null) {
checkRegisterLimit(deviceInfo.getDeviceId(), ipAddress);

View File

@@ -51,10 +51,10 @@ public class AccountController extends BaseController {
@RequestMapping("/third/login")
public OAuth2AccessToken login(HttpServletRequest request,
@RequestParam String openid, @RequestParam Integer type,
String unionid, DeviceInfo deviceInfo, AppEnum app) throws Exception {
String unionid, DeviceInfo deviceInfo, AppEnum app, String idToken) throws Exception {
log.info("/acc/third/login? app {} , type {}, unionId {}", app, type, unionid);
String ipAddress = IPUtils.getRealIpAddress(request);
UserDetails userDetails = myUserDetailsService.loadUserByOpenId(openid, type.byteValue(), deviceInfo, ipAddress, unionid);
UserDetails userDetails = myUserDetailsService.loadUserByOpenId(openid, type.byteValue(), deviceInfo, ipAddress, unionid, idToken);
myUserDetailsService.login(null, userDetails, LoginTypeEnum.get(type), deviceInfo, ipAddress, openid, unionid,null);
return createAccessToken(userDetails);