From a81e687f67f98011483ce218ac6dcef20ad75ecc Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Fri, 4 Nov 2022 09:51:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=B1=B1=E4=B8=9C?= =?UTF-8?q?=E9=80=9A=E7=99=BB=E5=BD=95=E6=B5=81=E7=A8=8B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ThirdLoginServiceImpl.java | 40 ++-------------- .../com/epmet/feign/ThirdOpenFeignClient.java | 19 ++++++++ .../com/epmet/controller/SdtController.java | 25 ++++++++++ .../java/com/epmet/service/SdtService.java | 6 +++ .../epmet/service/impl/SdtServiceImpl.java | 48 +++++++++++++++++++ 5 files changed, 103 insertions(+), 35 deletions(-) diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java index 8b60fab849..fa502caf45 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java @@ -1173,47 +1173,17 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol @Override public UserTokenResultDTO sdtSSOLogin(String authCode, String customerId) { - String accessToken = getResultDataOrThrowsException(thirdOpenFeignClient.getSdtCachedAccessToken(customerId), ServiceConstant.EPMET_THIRD_SERVER, - EpmetErrorCode.SERVER_ERROR.getCode(), "获取山东通access_token失败", null); // 1.获取用户编码 - HashMap params = new HashMap<>(); - params.put("access_token", accessToken); - params.put("code", authCode); - Result sdtResult = HttpClientManager.getInstance().sendGet("/cgi-bin/user/getuserinfo", params); - if (!sdtResult.success()) { - // http状态判断 - log.error("【山东通登录】查询用户编码-http错误:{}", sdtResult.getMsg()); - throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户编码失败", null); - } - - SdtStaffInfoResult staffInfoResult = JSON.parseObject(sdtResult.getData(), SdtStaffInfoResult.class); - if (!staffInfoResult.success()) { - // 山东通业务返回状态判断 - log.error("【山东通登录】查询用户编码失败,错误信息:{}", staffInfoResult.getErrmsg()); - throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户编码失败", null); - } + SdtStaffInfoResult staffInfo = getResultDataOrThrowsException(thirdOpenFeignClient.getUserInfoByAuthCode(authCode, customerId), ServiceConstant.EPMET_THIRD_SERVER, + EpmetErrorCode.SERVER_ERROR.getCode(), "获取山东通用户基础信息失败", null); // 2.获取用户详细信息 - HashMap userDetailParams = new HashMap<>(); - userDetailParams.put("access_token", accessToken); - userDetailParams.put("userid", staffInfoResult.getUserId()); - Result userDetailResult = HttpClientManager.getInstance().sendGet("/cgi-bin/user/get", userDetailParams); - if (!userDetailResult.success()) { - // http状态判断 - log.error("【山东通登录】查询用户详细信息-http错误:{}", sdtResult.getMsg()); - throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户详细信息失败", null); - } - - SdtStaffDetailResult staffDetailResult = JSON.parseObject(userDetailResult.getData(), SdtStaffDetailResult.class); - if (!staffDetailResult.success()) { - // 山东通业务返回状态判断 - log.error("【山东通登录】查询用户详细信息失败,错误信息:{}", staffInfoResult.getErrmsg()); - throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户详细信息失败", null); - } + SdtStaffDetailResult staffDetail = getResultDataOrThrowsException(thirdOpenFeignClient.getUserDetailByUserId(authCode, customerId), ServiceConstant.EPMET_THIRD_SERVER, + EpmetErrorCode.SERVER_ERROR.getCode(), "获取山东通用户详细信息失败", null); // 3.有了手机号,可以做登录了 - String mobile = staffDetailResult.getMobile(); + String mobile = staffDetail.getMobile(); GovWebLoginFormDTO loginGovParam = new GovWebLoginFormDTO(); loginGovParam.setCustomerId(customerId); loginGovParam.setPhone(mobile); diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java index 003ae99e03..c130f8d27d 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java @@ -5,6 +5,8 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.*; import com.epmet.dto.result.ThirdplatformResultDTO; import com.epmet.feign.fallback.ThirdOpenFeignClientFallbackFactory; +import com.epmet.sdt.SdtStaffDetailResult; +import com.epmet.sdt.SdtStaffInfoResult; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -99,4 +101,21 @@ public interface ThirdOpenFeignClient { */ @GetMapping("/third/sdt/getCachedAccessToken") Result getSdtCachedAccessToken(@RequestParam("customerId") String customerId); + + /** + * 通过authCode查询用户基础信息 + * @param customerId + * @return + */ + @GetMapping("/third/sdt/getUserInfoByAuthCode") + Result getUserInfoByAuthCode(@RequestParam("authCode") String authCode, @RequestParam("customerId") String customerId); + + /** + * 使用用户id查询用户详情 + * @param userId + * @param customerId + * @return + */ + @GetMapping("/third/sdt/getUserDetailByUserId") + Result getUserDetailByUserId(@RequestParam("userId") String userId, @RequestParam("customerId") String customerId); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/SdtController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/SdtController.java index deb8e99fa4..1dfec76db3 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/SdtController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/SdtController.java @@ -2,6 +2,8 @@ package com.epmet.controller; import com.epmet.commons.tools.utils.EpmetRequestHolder; import com.epmet.commons.tools.utils.Result; +import com.epmet.sdt.SdtStaffDetailResult; +import com.epmet.sdt.SdtStaffInfoResult; import com.epmet.service.SdtService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -44,4 +46,27 @@ public class SdtController { return new Result().ok(cachedAccessToken); } + /** + * 通过authCode查询用户基础信息 + * @param customerId + * @return + */ + @GetMapping("getUserInfoByAuthCode") + public Result getUserInfoByAuthCode(@RequestParam("authCode") String authCode, @RequestParam("customerId") String customerId) { + SdtStaffInfoResult cachedAccessToken = sdtService.getUserInfoByCode(authCode, customerId); + return new Result().ok(cachedAccessToken); + } + + /** + * 使用用户id查询用户详情 + * @param userId + * @param customerId + * @return + */ + @GetMapping("getUserDetailByUserId") + public Result getUserDetailByUserId(@RequestParam("userId") String userId, @RequestParam("customerId") String customerId) { + SdtStaffDetailResult cachedAccessToken = sdtService.getUserDetailByUserId(userId, customerId); + return new Result().ok(cachedAccessToken); + } + } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/SdtService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/SdtService.java index ebc98e60ea..aab3480dd6 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/SdtService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/SdtService.java @@ -1,5 +1,7 @@ package com.epmet.service; +import com.epmet.sdt.SdtStaffDetailResult; +import com.epmet.sdt.SdtStaffInfoResult; import com.zaxxer.hikari.util.FastList; import lombok.Data; @@ -32,4 +34,8 @@ public interface SdtService { * * @return String */ String getCachedAccessToken(String customerId); + + SdtStaffInfoResult getUserInfoByCode(String authCode, String customerId); + + SdtStaffDetailResult getUserDetailByUserId(String userId, String customerId); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/SdtServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/SdtServiceImpl.java index 3ae9a03bb4..c5397776eb 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/SdtServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/SdtServiceImpl.java @@ -3,6 +3,8 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.HttpClientManager; @@ -10,6 +12,8 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dao.SdtAppInfoDao; import com.epmet.entity.SdtAppInfoEntity; import com.epmet.sdt.SdtGetAccessTokenResult; +import com.epmet.sdt.SdtStaffDetailResult; +import com.epmet.sdt.SdtStaffInfoResult; import com.epmet.service.SdtService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -153,4 +157,48 @@ public class SdtServiceImpl implements SdtService { return redisUtils.getString(key); } } + + @Override + public SdtStaffInfoResult getUserInfoByCode(String authCode, String customerId) { + HashMap params = new HashMap<>(); + params.put("access_token", getCachedAccessToken(customerId)); + params.put("code", authCode); + Result sdtResult = HttpClientManager.getInstance().sendGet("/cgi-bin/user/getuserinfo", params); + if (!sdtResult.success()) { + // http状态判断 + log.error("【山东通登录】查询用户编码-http错误:{}", sdtResult.getMsg()); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户编码失败", null); + } + + SdtStaffInfoResult staffInfoResult = JSON.parseObject(sdtResult.getData(), SdtStaffInfoResult.class); + if (!staffInfoResult.success()) { + // 山东通业务返回状态判断 + log.error("【山东通登录】查询用户编码失败,错误信息:{}", staffInfoResult.getErrmsg()); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户编码失败", null); + } + + return staffInfoResult; + } + + @Override + public SdtStaffDetailResult getUserDetailByUserId(String userId, String customerId) { + HashMap userDetailParams = new HashMap<>(); + userDetailParams.put("access_token", getCachedAccessToken(customerId)); + userDetailParams.put("userid", userId); + Result userDetailResult = HttpClientManager.getInstance().sendGet("/cgi-bin/user/get", userDetailParams); + if (!userDetailResult.success()) { + // http状态判断 + log.error("【山东通登录】查询用户详细信息-http错误:{}", userDetailResult.getMsg()); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户详细信息失败", null); + } + + SdtStaffDetailResult staffDetailResult = JSON.parseObject(userDetailResult.getData(), SdtStaffDetailResult.class); + if (!staffDetailResult.success()) { + // 山东通业务返回状态判断 + log.error("【山东通登录】查询用户详细信息失败,错误信息:{}", staffDetailResult.getErrmsg()); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用山东通查询用户详细信息失败", null); + } + + return staffDetailResult; + } }