v1.0 : 调整三方登录时注册流程

This commit is contained in:
fbc
2022-09-28 12:12:11 +08:00
parent dbeead477d
commit 1d3cef3e21
6 changed files with 35 additions and 54 deletions

View File

@@ -39,12 +39,13 @@ public class Account {
private String registerIp;
@Deprecated
private String weixinOpenid;
@Deprecated
private String weixinUnionid;
@Deprecated
private String qqOpenid;
@Deprecated
private String qqUnionid;
private String appleUid;
@@ -93,4 +94,11 @@ public class Account {
@TableField(value = "device_info")
private String deviceInfo;
@TableField(value = "third_login_type")
private Byte thirdLoginType;
@TableField(value = "open_id")
private String openId;
@TableField(value = "union_id")
private String unionId;
}

View File

@@ -1,7 +1,6 @@
package com.accompany.core.service.account;
import com.accompany.common.constant.ApplicationConstant;
import com.accompany.common.constant.Constant;
import com.accompany.common.netease.neteaseacc.result.TokenRet;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.BlankUtil;
@@ -45,17 +44,12 @@ public class AccountService extends ServiceImpl<AccountMapper, Account> {
/**
* 获取第三方登录账号
*
* @param openId
* @param unionId
* @return
*/
public Account getAccountByThird(Integer type, String openId, String unionId) {
public Account getAccountByThird(Byte type, String unionId) {
QueryWrapper<Account> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(Constant.AccountType.wx_account.intValue() == type, Account::getWeixinUnionid, unionId)
.eq(Constant.AccountType.apple_account.intValue() == type, Account::getAppleUid, unionId)
.and(Constant.AccountType.qq_account.intValue() == type,
queryWrapper -> queryWrapper.eq(Account::getQqOpenid, openId).or().
eq(Account::getQqUnionid, unionId));
wrapper.lambda().eq(Account::getThirdLoginType, type).eq(Account::getUnionId, unionId);
List<Account> accounts = list(wrapper);
if (CollectionUtils.isEmpty(accounts)) {
return null;

View File

@@ -13,7 +13,7 @@ public interface MyUserDetailsService extends UserDetailsService {
UserDetails loadUserByPhone(String phone, String smsCode, DeviceInfo deviceInfo, String ipAddress) throws Exception;
UserDetails loadUserByOpenId(String openid, int type, DeviceInfo deviceInfo, String ipAddress, String unionId,
UserDetails loadUserByOpenId(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId,
YiDunDto yiDunDto, ShuMeiDto shuMeiDto, String appleFullName) throws Exception;
void login(String reqUserName, UserDetails userDetails, LoginTypeEnum loginTypeEnum, DeviceInfo deviceInfo, String ip, String openId, String unionId, String yiDunToken, String shuMeiDeviceId, String smsCode) throws Exception;

View File

@@ -2,7 +2,6 @@ package com.accompany.oauth2.service;
import com.accompany.common.constant.AppEnum;
import com.accompany.common.constant.Constant;
import com.accompany.common.constant.SmsTypeEnum;
import com.accompany.common.device.DeviceInfo;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.status.BusiStatus;
@@ -125,7 +124,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
}
@Override
public UserDetails loadUserByOpenId(String openid, int type, DeviceInfo deviceInfo, String ipAddress, String unionId,
public UserDetails loadUserByOpenId(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId,
YiDunDto yiDunDto, ShuMeiDto shuMeiDto, String appleFullName) throws Exception {
Account account = accountManageService.getOrGenAccountByOpenid(openid, type, deviceInfo, ipAddress, unionId,
yiDunDto, shuMeiDto, appleFullName);

View File

@@ -135,8 +135,8 @@ public class AccountManageService {
}
public Account getOrGenAccountByOpenid(String openid, int type, DeviceInfo deviceInfo, String ipAddress, String unionId,
YiDunDto yiDunDto, ShuMeiDto shuMeiDto, String appleFullName) throws Exception {
public Account getOrGenAccountByOpenid(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId,
YiDunDto yiDunDto, ShuMeiDto shuMeiDto, String appleFullName) 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));
@@ -145,7 +145,7 @@ public class AccountManageService {
if (BlankUtil.isBlank(lockVal)){
throw new ServiceException(BusiStatus.REQUEST_FAST);
}
Account account = accountService.getAccountByThird(type, openid, unionId);
Account account = accountService.getAccountByThird(type, unionId);
if (account == null) {
int count = accountService.getRegisterIpCountByOneDay(ipAddress);
if (count > maxRegisterCount) {
@@ -159,22 +159,13 @@ public class AccountManageService {
account.setRegisterIp(ipAddress);
account.setSignTime(date);
account.setState("1");
if (type == Constant.AccountType.wx_account.byteValue()) {
account.setWeixinOpenid(openid);
if (!BlankUtil.isBlank(unionId)) {
account.setWeixinUnionid(unionId);
}
} else if (type == Constant.AccountType.qq_account.byteValue()) {
account.setQqOpenid(openid);
if (!BlankUtil.isBlank(unionId)) {
account.setQqUnionid(unionId);
}
} else if (type == Constant.AccountType.apple_account.byteValue()) {
account.setAppleUid(unionId);
account.setAppleFullName(appleFullName);
}
account.setErbanNo(erBanNoService.getErBanNo());
account.setPhone(account.getErbanNo().toString());
// 三方登录信息
account.setThirdLoginType(type);
account.setUnionId(unionId);
account.setOpenId(openid);
account = fillDeviceInfo(account, deviceInfo);
if (deviceInfo != null) {
@@ -195,21 +186,17 @@ public class AccountManageService {
log.info("TRIGGER USER REGISTER SUCCESS EVENT");
applicationContext.publishEvent(new UserRegisterSuccessEvent(account));
} else {
//account = fillDeviceInfo(account, deviceInfo);
// 已存在用户先判断account中的微信unionId是否为空或者不一致如果是的话则更新不是则跳过
Boolean bol = (BlankUtil.isBlank(account.getWeixinUnionid())) || !account.getWeixinUnionid().equals(unionId);
if (type == Constant.AccountType.wx_account.byteValue() && bol) {
log.info("account params uid={},old weixinUnionId={},new weixinUnionId={}", account.getUid(), account.getWeixinUnionid(), unionId);
account.setWeixinUnionid(unionId);
} else if (type == 2 && !BlankUtil.isBlank(unionId)) {
//更新存储qq的unionId
account.setQqUnionid(unionId);
}
// 已存在用户先判断account中的unionId是否为空或者不一致如果是的话则更新不是则跳过
String state = account.getState();
if ("2".equals(state)) {
throw new CustomOAuth2Exception(CustomOAuth2Exception.INVALID_USER,
"用户账号异常请联系官方客服uid=" + account.getUid());
}
Boolean bol =
(BlankUtil.isBlank(account.getUnionId())) || !account.getUnionId().equals(unionId);
if (bol) {
account.setUnionId(unionId);
}
account.setLastLoginTime(new Date());
account.setUpdateTime(new Date());
accountMapper.updateById(account);

View File

@@ -395,18 +395,12 @@ public class AccountController extends BaseController {
}
@RequestMapping("third/login")
public ResponseEntity<OAuth2AccessToken> login(String openid, int type, DeviceInfo deviceInfo, HttpServletRequest request,
public ResponseEntity<OAuth2AccessToken> login(String openid, Integer type, DeviceInfo deviceInfo, HttpServletRequest request,
String shuMeiDeviceId, String yiDunToken, AppEnum app) throws Exception {
logger.info("/acc/third/login?openid:{},type:{},shuMeiDeviceId:{},yiDunToken:{},app:{}" ,openid,type,shuMeiDeviceId,yiDunToken,app);
String unionId = request.getParameter("unionid");
String appleFullName = request.getParameter("appleFullName");
logger.info("/acc/third/login? app {} , type {}, unionId {}", app, type, unionId);
checkAppVersion(deviceInfo);
if (type == Constant.AccountType.wx_account.byteValue()) {
logger.info("============thirdLogin weixin unionId={}", request.getParameter("unionid"));
} else if (type == Constant.AccountType.qq_account.byteValue()) {
logger.info("============thirdLogin qq unionId={}", request.getParameter("unionid"));
} else if (type == Constant.AccountType.apple_account.byteValue()) {
logger.info("============thirdLogin apple appleUid={}", request.getParameter("unionid"));
openid = request.getParameter("unionid");
}
if (StringUtils.isEmpty(openid) || type == 0) {
throw new RuntimeException("参数异常");
}
@@ -414,9 +408,8 @@ public class AccountController extends BaseController {
YiDunDto yiDunDto = accountManageService.buildYiDunDto(oAuthConfig, ipAddress, yiDunToken, null,null, deviceInfo);
ShuMeiDto shuMeiDto = accountManageService.buildShuMeiDto(oAuthConfig, deviceInfo, openid, ipAddress, openid, shuMeiDeviceId,"register");
String unionId = request.getParameter("unionid");
String appleFullName = request.getParameter("appleFullName");
UserDetails userDetails = myUserDetailsService.loadUserByOpenId(openid, type, deviceInfo, ipAddress, unionId, yiDunDto, shuMeiDto, appleFullName);
UserDetails userDetails = myUserDetailsService.loadUserByOpenId(openid, type.byteValue(), deviceInfo, ipAddress, unionId, yiDunDto, shuMeiDto, appleFullName);
myUserDetailsService.login(null, userDetails, LoginTypeEnum.get(type), deviceInfo, ipAddress, openid, unionId, yiDunToken, shuMeiDeviceId,null);
OAuth2AccessToken token = createAccessToken(userDetails);