|
@@ -27,6 +27,7 @@ import cn.newfeifan.mall.module.system.enums.logger.LoginResultEnum;
|
|
import cn.newfeifan.mall.module.system.enums.oauth2.OAuth2ClientConstants;
|
|
import cn.newfeifan.mall.module.system.enums.oauth2.OAuth2ClientConstants;
|
|
import cn.newfeifan.mall.module.system.enums.sms.SmsSceneEnum;
|
|
import cn.newfeifan.mall.module.system.enums.sms.SmsSceneEnum;
|
|
import cn.newfeifan.mall.module.system.enums.social.SocialTypeEnum;
|
|
import cn.newfeifan.mall.module.system.enums.social.SocialTypeEnum;
|
|
|
|
+import jodd.util.StringUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -101,9 +102,9 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO) {
|
|
|
|
|
|
+ public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO, String phone) {
|
|
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
|
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
|
- SocialUserRespDTO socialUser = socialUserApi.getSocialUserByCode(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
|
|
|
|
|
+ SocialUserRespDTO socialUser = socialUserApi.getFirstSocialUserByCode(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
|
reqVO.getCode(), reqVO.getState());
|
|
reqVO.getCode(), reqVO.getState());
|
|
if (socialUser == null) {
|
|
if (socialUser == null) {
|
|
throw exception(AUTH_SOCIAL_USER_NOT_FOUND);
|
|
throw exception(AUTH_SOCIAL_USER_NOT_FOUND);
|
|
@@ -113,9 +114,20 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
|
MemberUserDO user;
|
|
MemberUserDO user;
|
|
if (socialUser.getUserId() != null) {
|
|
if (socialUser.getUserId() != null) {
|
|
user = userService.getUser(socialUser.getUserId());
|
|
user = userService.getUser(socialUser.getUserId());
|
|
- // 情况二:未绑定,注册用户 + 绑定用户
|
|
|
|
|
|
+ // 情况二:未绑定,注册用户 + 绑定用户
|
|
} else {
|
|
} else {
|
|
- user = userService.createUser(socialUser.getNickname(), socialUser.getAvatar(), getClientIP(), getTerminal());
|
|
|
|
|
|
+
|
|
|
|
+ //通过微信 + 手机号首次登录
|
|
|
|
+ if (!StringUtil.isEmpty(phone)) {
|
|
|
|
+ //如果会员表中有记录
|
|
|
|
+ user = userService.getUserByMobile(phone);
|
|
|
|
+ if (user == null) {
|
|
|
|
+ user = userService.createUser(socialUser.getNickname(), socialUser.getAvatar(), getClientIP(), getTerminal());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ user = userService.createUser(socialUser.getNickname(), socialUser.getAvatar(), getClientIP(), getTerminal());
|
|
|
|
+ }
|
|
|
|
+
|
|
socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
|
socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
|
reqVO.getType(), reqVO.getCode(), reqVO.getState()));
|
|
reqVO.getType(), reqVO.getCode(), reqVO.getState()));
|
|
}
|
|
}
|
|
@@ -127,6 +139,17 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
|
return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, socialUser.getOpenid());
|
|
return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, socialUser.getOpenid());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public AppAuthLoginRespVO firstSocialLogin(AppAuthSocialLoginReqVO reqVO, String phone) {
|
|
|
|
+ SocialUserRespDTO socialUser = socialUserApi.getFirstSocialUserByCode(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
|
|
|
+ reqVO.getCode(), reqVO.getState());
|
|
|
|
+ if (socialUser == null) {
|
|
|
|
+ throw exception(AUTH_SOCIAL_USER_NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ return socialLogin(reqVO, phone);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public AppAuthLoginRespVO weixinMiniAppLogin(AppAuthWeixinMiniAppLoginReqVO reqVO) {
|
|
public AppAuthLoginRespVO weixinMiniAppLogin(AppAuthWeixinMiniAppLoginReqVO reqVO) {
|
|
// 获得对应的手机号信息
|
|
// 获得对应的手机号信息
|