From d65c28d7f7e7db4a8c14538ba3cd30d3111bf6d3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Dec 2023 09:59:58 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Member=EF=BC=9A=E7=A4=BE=E4=BA=A4?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=99=BB=E5=BD=95=E6=97=B6=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=EF=BC=8C=E5=88=99=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=94=A8=E6=88=B7=EF=BC=8C=E4=BF=9D=E6=8C=81=E5=92=8C=E5=90=84?= =?UTF-8?q?=20App=20=E7=BB=9F=E4=B8=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/enums/TerminalEnum.java | 1 + .../common/util/servlet/ServletUtils.java | 2 -- .../web/core/util/WebFrameworkUtils.java | 19 +++++++++++++++++++ .../app/order/AppTradeOrderController.java | 5 ++--- .../convert/order/TradeOrderConvert.java | 3 +-- .../order/TradeOrderUpdateService.java | 4 +--- .../order/TradeOrderUpdateServiceImpl.java | 14 ++++++++------ .../app/auth/AppAuthController.java | 5 ++--- .../service/auth/MemberAuthService.java | 4 +--- .../service/auth/MemberAuthServiceImpl.java | 10 +++++++--- .../service/user/MemberUserService.java | 12 ++++++++++++ .../service/user/MemberUserServiceImpl.java | 15 +++++++++++---- .../api/logger/dto/LoginLogCreateReqDTO.java | 4 ++-- .../api/social/dto/SocialUserRespDTO.java | 10 +++++++++- .../service/auth/AdminAuthServiceImpl.java | 2 +- .../service/social/SocialUserServiceImpl.java | 8 +++----- 16 files changed, 80 insertions(+), 38 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java index 632675203..f256712b3 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum TerminalEnum implements IntArrayValuable { + UNKNOWN(0, "未知"), // 目的:在无法解析到 terminal 时,使用它 WECHAT_MINI_PROGRAM(10, "微信小程序"), WECHAT_WAP(11, "微信公众号"), H5(20, "H5 网页"), diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java index 672c1fa19..bc592d890 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java @@ -88,8 +88,6 @@ public class ServletUtils { return JakartaServletUtil.getClientIP(request); } - // TODO @疯狂:terminal 还是从 ServletUtils 里拿,更容易全局治理; - public static boolean isJsonRequest(ServletRequest request) { return StrUtil.startWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE); } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java index 70c59cb4e..ae18634c2 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.framework.web.core.util; import cn.hutool.core.util.NumberUtil; +import cn.hutool.extra.servlet.ServletUtil; +import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.web.config.WebProperties; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; @@ -25,6 +28,13 @@ public class WebFrameworkUtils { public static final String HEADER_TENANT_ID = "tenant-id"; + /** + * 终端的 Header + * + * @see cn.iocoder.yudao.framework.common.enums.TerminalEnum + */ + public static final String HEADER_TERMINAL = "terminal"; + private static WebProperties properties; public WebFrameworkUtils(WebProperties webProperties) { @@ -107,6 +117,15 @@ public class WebFrameworkUtils { return getLoginUserId(request); } + public static Integer getTerminal() { + HttpServletRequest request = getRequest(); + if (request == null) { + return TerminalEnum.UNKNOWN.getTerminal(); + } + String terminalValue = request.getHeader(HEADER_TERMINAL); + return NumberUtil.parseInt(terminalValue, TerminalEnum.UNKNOWN.getTerminal()); + } + public static void setCommonResult(ServletRequest request, CommonResult result) { request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 545f0adde..8bae3e35d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -61,9 +61,8 @@ public class AppTradeOrderController { @PostMapping("/create") @Operation(summary = "创建订单") @PreAuthenticated - public CommonResult createOrder(@Valid @RequestBody AppTradeOrderCreateReqVO createReqVO, - @RequestHeader Integer terminal) { - TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), getClientIP(), createReqVO, terminal); + public CommonResult createOrder(@Valid @RequestBody AppTradeOrderCreateReqVO createReqVO) { + TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), createReqVO); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 773bb9e91..e368d0355 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -69,8 +69,7 @@ public interface TradeOrderConvert { @Mapping(source = "calculateRespBO.price.vipPrice", target = "vipPrice"), @Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice") }) - TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, - TradePriceCalculateRespBO calculateRespBO); + TradeOrderDO convert(Long userId, AppTradeOrderCreateReqVO createReqVO, TradePriceCalculateRespBO calculateRespBO); TradeOrderRespDTO convert(TradeOrderDO orderDO); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index b26d84c65..e16a08bd7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -36,12 +36,10 @@ public interface TradeOrderUpdateService { * 【会员】创建交易订单 * * @param userId 登录用户 - * @param userIp 用户 IP 地址 * @param createReqVO 创建交易订单请求模型 - * @param terminal 终端 {@link TerminalEnum} * @return 交易订单的 */ - TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, Integer terminal); + TradeOrderDO createOrder(Long userId, AppTradeOrderCreateReqVO createReqVO); /** * 更新交易订单已支付 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 40e26a2b7..e0b57d923 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -64,6 +64,8 @@ import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.minusTime; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** @@ -158,11 +160,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CREATE) - public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, Integer terminal) { + public TradeOrderDO createOrder(Long userId, AppTradeOrderCreateReqVO createReqVO) { // 1.1 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); // 1.2 构建订单 - TradeOrderDO order = buildTradeOrder(userId, userIp, createReqVO, calculateRespBO, terminal); + TradeOrderDO order = buildTradeOrder(userId, createReqVO, calculateRespBO); List orderItems = buildTradeOrderItems(order, calculateRespBO); // 2. 订单创建前的逻辑 @@ -178,15 +180,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return order; } - private TradeOrderDO buildTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO, - TradePriceCalculateRespBO calculateRespBO, Integer terminal) { - TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO); + private TradeOrderDO buildTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, + TradePriceCalculateRespBO calculateRespBO) { + TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, createReqVO, calculateRespBO); order.setType(calculateRespBO.getType()); order.setNo(tradeNoRedisDAO.generate(TradeNoRedisDAO.TRADE_ORDER_NO_PREFIX)); order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); - order.setTerminal(terminal); + order.setUserIp(getClientIP()).setTerminal(getTerminal()); // 支付 + 退款信息 order.setAdjustPrice(0).setPayStatus(false); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java index 503ff13bd..16c7db207 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java @@ -73,9 +73,8 @@ public class AppAuthController { @PostMapping("/sms-login") @Operation(summary = "使用手机 + 验证码登录") - public CommonResult smsLogin(@RequestBody @Valid AppAuthSmsLoginReqVO reqVO, - @RequestHeader Integer terminal) { - return success(authService.smsLogin(reqVO, terminal)); + public CommonResult smsLogin(@RequestBody @Valid AppAuthSmsLoginReqVO reqVO) { + return success(authService.smsLogin(reqVO)); } @PostMapping("/send-sms-code") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java index 46bc048dc..3fad6e232 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.member.service.auth; -import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; import jakarta.validation.Valid; @@ -33,10 +32,9 @@ public interface MemberAuthService { * 手机 + 验证码登陆 * * @param reqVO 登陆信息 - * @param terminal 终端 {@link TerminalEnum} * @return 登录结果 */ - AppAuthLoginRespVO smsLogin(@Valid AppAuthSmsLoginReqVO reqVO, Integer terminal); + AppAuthLoginRespVO smsLogin(@Valid AppAuthSmsLoginReqVO reqVO); /** * 社交登录,使用 code 授权码 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java index cb246bd0f..3111034d5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java @@ -36,6 +36,7 @@ import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; /** @@ -78,13 +79,13 @@ public class MemberAuthServiceImpl implements MemberAuthService { @Override @Transactional - public AppAuthLoginRespVO smsLogin(AppAuthSmsLoginReqVO reqVO, Integer terminal) { + public AppAuthLoginRespVO smsLogin(AppAuthSmsLoginReqVO reqVO) { // 校验验证码 String userIp = getClientIP(); smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.MEMBER_LOGIN.getScene(), userIp)); // 获得获得注册用户 - MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp, terminal); + MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp, getTerminal()); Assert.notNull(user, "获取用户失败,结果为空"); // 如果 socialType 非空,说明需要绑定社交用户 @@ -107,10 +108,13 @@ public class MemberAuthServiceImpl implements MemberAuthService { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } - // 自动登录 + // 情况一:已绑定,自动登录 MemberUserDO user = userService.getUser(socialUser.getUserId()); if (user == null) { throw exception(USER_NOT_EXISTS); + // 情况二:未绑定,注册登录 + } else { + user = userService.createUser(user.getNickname(), user.getAvatar(), getClientIP(), getTerminal()); } // 创建 Token 令牌,记录登录日志 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 1305c5ae3..dcd71ea21 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -49,6 +49,18 @@ public interface MemberUserService { */ MemberUserDO createUserIfAbsent(@Mobile String mobile, String registerIp, Integer terminal); + /** + * 创建用户 + * 目的:三方登录时,如果未绑定用户时,自动创建对应用户 + * + * @param nickname 昵称 + * @param avtar 头像 + * @param registerIp 注册 IP + * @param terminal 终端 {@link TerminalEnum} + * @return 用户对象 + */ + MemberUserDO createUser(String nickname, String avtar, String registerIp, Integer terminal); + /** * 更新用户的最后登陆信息 * diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 37b56f001..b704166b4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -81,10 +81,17 @@ public class MemberUserServiceImpl implements MemberUserService { return user; } // 用户不存在,则进行创建 - return createUser(mobile, registerIp, terminal); + return createUser(mobile, null, null, registerIp, terminal); } - private MemberUserDO createUser(String mobile, String registerIp, Integer terminal) { + @Override + @Transactional(rollbackFor = Exception.class) + public MemberUserDO createUser(String nickname, String avtar, String registerIp, Integer terminal) { + return createUser(null, nickname, avtar, registerIp, terminal); + } + + private MemberUserDO createUser(String mobile, String nickname, String avtar, + String registerIp, Integer terminal) { // 生成密码 String password = IdUtil.fastSimpleUUID(); // 插入用户 @@ -92,8 +99,8 @@ public class MemberUserServiceImpl implements MemberUserService { user.setMobile(mobile); user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 user.setPassword(encodePassword(password)); // 加密密码 - user.setRegisterIp(registerIp); - user.setRegisterTerminal(terminal); + user.setRegisterIp(registerIp).setRegisterTerminal(terminal); + user.setNickname(nickname).setAvatar(avtar); // 基础信息 memberUserMapper.insert(user); // 发送 MQ 消息:用户创建 diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java index 2e7a14210..539c8ee27 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java @@ -36,9 +36,9 @@ public class LoginLogCreateReqDTO { private Integer userType; /** * 用户账号 + * + * 不再强制校验 username 非空,因为 Member 社交登录时,此时暂时没有 username(mobile)! */ - @NotBlank(message = "用户账号不能为空") - @Size(max = 30, message = "用户账号长度不能超过30个字符") private String username; /** diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java index ac25b148e..29fef0107 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java @@ -15,9 +15,17 @@ import lombok.NoArgsConstructor; public class SocialUserRespDTO { /** - * 社交用户 openid + * 社交用户的 openid */ private String openid; + /** + * 社交用户的昵称 + */ + private String nickname; + /** + * 社交用户的头像 + */ + private String avatar; /** * 关联的用户编号 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index aae67de0d..6ff184544 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -158,7 +158,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); - if (socialUser == null) { + if (socialUser == null || socialUser.getUserId() == null) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java index 1deecba78..5b7dd5f72 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java @@ -99,13 +99,11 @@ public class SocialUserServiceImpl implements SocialUserService { SocialUserDO socialUser = authSocialUser(socialType, userType, code, state); Assert.notNull(socialUser, "社交用户不能为空"); - // 如果未绑定的社交用户,则无法自动登录,进行报错 + // 获得绑定用户 SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserTypeAndSocialUserId(userType, socialUser.getId()); - if (socialUserBind == null) { - throw exception(AUTH_THIRD_LOGIN_NOT_BIND); - } - return new SocialUserRespDTO(socialUser.getOpenid(), socialUserBind.getUserId()); + return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(), + socialUserBind != null ? socialUserBind.getUserId() : null); } /**