From 65558cd14f960d9513b46721693fd5bb68cfddf9 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 20 Jan 2021 14:50:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9sso=E7=99=BB=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E6=9B=B4=E7=81=B5=E6=B4=BB...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/service/impl/SsoServiceImpl.java | 20 ++++++++++--------- .../apiservice/AbstractApiService.java | 13 +++++++++++- .../thirdplat/bean/ThirdPlatUserInfo.java | 5 +++++ .../thirdplat/config/ThirdplatConfig.java | 9 ++++++++- .../constants/ApiServiceBeansConstants.java | 9 +++++++++ 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 482738566f..34f6ee588b 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -2,14 +2,13 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.epmet.commons.thirdplat.apiservice.AbstractApiService; import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +import com.epmet.commons.thirdplat.constants.ApiServiceBeansConstants; import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; -import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.utils.DateUtils; -import com.epmet.commons.tools.utils.HttpClientManager; -import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.*; import com.epmet.constant.SsoConstant; import com.epmet.dto.PaCustomerDTO; import com.epmet.dto.UserDTO; @@ -23,6 +22,8 @@ import com.epmet.redis.SsoRedis; import com.epmet.service.SsoService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -38,6 +39,8 @@ import java.util.Map; @Slf4j public class SsoServiceImpl implements SsoService { + Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired private SsoRedis ssoRedis; @@ -47,9 +50,6 @@ public class SsoServiceImpl implements SsoService { @Autowired private JwtTokenProperties jwtTokenProperties; - @Autowired - private JcetApiService jcetApiService; - @Autowired private EpmetUserOpenFeignClient epmetUserOpenFeignClient; @@ -65,8 +65,10 @@ public class SsoServiceImpl implements SsoService { if (formDTO.getAppId().equals(SsoConstant.WINE_CITY_E_OPEN_APP_ID)) { UserInfoResultDTO userInfo = null; try { - userInfo = jcetApiService.getUserInfoByTicket(formDTO.getTicket()); - } catch (UnsupportedEncodingException e) { + AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(ApiServiceBeansConstants.JCET_API_SERVICE); + userInfo = apiService.getUserInfoByTicket(formDTO.getTicket()); + } catch (Exception e) { + logger.error("调用第三方平台,根据用户ticket查询用户信息失败,错误信息"); e.printStackTrace(); } if (null == userInfo){ diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java index b0aa1e0d0b..3209a9ea44 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -3,15 +3,26 @@ package com.epmet.commons.thirdplat.apiservice; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.epmet.commons.thirdplat.dto.result.jcet.JcetResult; +import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; -public class AbstractApiService { +import java.io.UnsupportedEncodingException; + +public abstract class AbstractApiService { protected ThirdplatProps thirdplatProps; + /** + * 通过ticket查询用户信息 + * @param ticket + * @return + * @throws Exception + */ + public abstract UserInfoResultDTO getUserInfoByTicket(String ticket) throws Exception; + /** * @Description 解析请求结果 * @return diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java new file mode 100644 index 0000000000..365e142a0f --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java @@ -0,0 +1,5 @@ +package com.epmet.commons.thirdplat.bean; + +public class ThirdPlatUserInfo { + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java index 4e8f0dbf3d..11e941ab93 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java @@ -1,6 +1,7 @@ package com.epmet.commons.thirdplat.config; import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +import com.epmet.commons.thirdplat.constants.ApiServiceBeansConstants; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -13,7 +14,13 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(ThirdplatProps.class) public class ThirdplatConfig { - @Bean + /** + * @Description 酒城e通的apiService,这个name需要注册进数据库,使用的时候去数据库根据客户id找对应的apiService出来用 + * @return + * @author wxz + * @date 2021.01.20 13:50 + */ + @Bean(name = ApiServiceBeansConstants.JCET_API_SERVICE) public JcetApiService JcetApiService(ThirdplatProps props) { return new JcetApiService(props); } diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java new file mode 100644 index 0000000000..2d79aebcfa --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java @@ -0,0 +1,9 @@ +package com.epmet.commons.thirdplat.constants; + +/** + * ApiService常量 + */ +public interface ApiServiceBeansConstants { + // 酒城e通apiService + String JCET_API_SERVICE = "jcetApiService"; +}