From 3c04b02824da0a013d68808da567b9d1415c3878 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Thu, 22 Sep 2022 11:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4resiLoginDingTemp;resilogin-d?= =?UTF-8?q?ing-md=E6=8E=A5=E5=8F=A3=E5=B0=9D=E8=AF=95=E6=9C=AA=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ThirdLoginController.java | 6 ++ .../dto/form/ResiDingAppLoginMdFormDTO.java | 23 +++++ .../com/epmet/service/ThirdLoginService.java | 3 +- .../service/impl/ThirdLoginServiceImpl.java | 98 ++++++++++--------- 4 files changed, 83 insertions(+), 47 deletions(-) create mode 100644 epmet-auth/src/main/java/com/epmet/dto/form/ResiDingAppLoginMdFormDTO.java diff --git a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java index 47deddb33a..efcf97ef5b 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java @@ -135,4 +135,10 @@ public class ThirdLoginController { return new Result().ok(thirdLoginService.resiLoginDing(formDTO)); } + + @PostMapping("resilogin-ding-md") + public Result resiLoginDingMd(@RequestBody ResiDingAppLoginMdFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); + return new Result().ok(thirdLoginService.resiLoginDingMd(formDTO)); + } } diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/ResiDingAppLoginMdFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/ResiDingAppLoginMdFormDTO.java new file mode 100644 index 0000000000..0b3b9ae0f8 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/ResiDingAppLoginMdFormDTO.java @@ -0,0 +1,23 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Description + * @Author yzm + * @Date 2022/9/22 10:42 + */ +@Data +public class ResiDingAppLoginMdFormDTO { + @NotBlank(message = "authCode不能为空") + private String authCode; + /** + * 第三方企业应用传应用的SuiteKey + */ + @NotBlank(message = "miniAppId不能为空") + private String miniAppId; + +} + diff --git a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java index 731f350386..eeab9296a3 100644 --- a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java @@ -74,5 +74,6 @@ public interface ThirdLoginService { * @return */ ResiDingAppLoginResDTO resiLoginDing(ResiDingAppLoginFormDTO formDTO); - ResiDingAppLoginResDTO resiLoginDingTemp(ResiDingAppLoginFormDTO formDTO); + + ResiDingAppLoginResDTO resiLoginDingMd(ResiDingAppLoginMdFormDTO formDTO); } 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 3f14f4b3b4..38f1039c8c 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 @@ -11,7 +11,6 @@ import com.epmet.common.token.constant.LoginConstant; import com.epmet.commons.rocketmq.messages.LoginMQMsg; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.ServiceConstant; -import com.epmet.commons.tools.enums.DingMiniAppEnum; import com.epmet.commons.tools.enums.EnvEnum; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; @@ -800,56 +799,63 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol return token; } - @Override - public ResiDingAppLoginResDTO resiLoginDingTemp(ResiDingAppLoginFormDTO formDTO) { - //获取用户手机号 - log.info("钉钉居民端应用登录入参:"+ JSON.toJSONString(formDTO)); - ResiDingAppLoginResDTO resDTO= null; - try { - resDTO = new ResiDingAppLoginResDTO(); - EnvEnum currentEnv = EnvEnum.getCurrentEnv(); - if (EnvEnum.PROD.getCode().equals(currentEnv.getCode())) { - //烟台的客户id - resDTO.setCustomerId("1535072605621841922"); - }else if(EnvEnum.TEST.getCode().equals(currentEnv.getCode())){ - //最美琴岛 - resDTO.setCustomerId("0c41b272ee9ee95ac6f184ad548a30eb"); - resDTO.setGridId("f896b59f3cddf1f54280546d79803652"); - resDTO.setGridName("抚顺社区-抚顺第一网格"); - resDTO.setAgencyId("f6e183d8e6687020074e6d8061926bfa"); - resDTO.setEpmetUserId("f838614e67cf8ae0edaefe562b6660e5"); - resDTO.setRegFlag(true); - }else if(EnvEnum.LOCAL.getCode().equals(currentEnv.getCode())||EnvEnum.DEV.getCode().equals(currentEnv.getCode())){ - //其余统一走开发环境 - resDTO.setCustomerId("45687aa479955f9d06204d415238f7cc"); - resDTO.setGridId("763d6e09b9081d63195d53da84b3ae3a"); - resDTO.setGridName("抚顺社区-抚顺第二网格"); - resDTO.setAgencyId("f6e183d8e6687020074e6d8061926bfa"); - resDTO.setEpmetUserId("f838614e67cf8ae0edaefe562b6660e5"); - resDTO.setRegFlag(true); - } + public ResiDingAppLoginResDTO resiLoginDingMd(ResiDingAppLoginMdFormDTO formDTO) { + // 获取用户手机号 + log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); + ResiDingAppLoginResDTO resDTO = null; + resDTO = new ResiDingAppLoginResDTO(); + EnvEnum currentEnv = EnvEnum.getCurrentEnv(); + if (EnvEnum.PROD.getCode().equals(currentEnv.getCode())) { + // 烟台的客户id + resDTO.setCustomerId("1535072605621841922"); + } else if (EnvEnum.TEST.getCode().equals(currentEnv.getCode())) { + // 最美琴岛 + resDTO.setCustomerId("0c41b272ee9ee95ac6f184ad548a30eb"); + } else { + // 其余统一走开发环境 + resDTO.setCustomerId("45687aa479955f9d06204d415238f7cc"); + } - //1、获取用户手机号 todo 这里暂时没改为miniappId - String clientId = formDTO.getMiniAppId(); - DingTalkResult userAccessToken = dingTalkClientToken.getUserAccessToken(formDTO.getAuthCode(), clientId, DingMiniAppEnum.getEnum(clientId).getSuiteSecret()); - log.info("resiLoginDing userAccessToken:{}",JSON.toJSONString(userAccessToken)); - if (!userAccessToken.success() || null == userAccessToken.getData()) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "调用微信api异常:" + JSON.toJSONString(userAccessToken), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); - } - DingTalkResult me = dingTalkClientUser.getUserInfo("me", userAccessToken.getData().getAccessToken()); - log.info("resiLoginDing me:{}",JSON.toJSONString(me)); - resDTO.setExtInfo(JSON.toJSONString(me.getData())); + // 1、获取用户手机号 + DingLoginResiFormDTO dingLoginResiFormDTO = getDingLoginResiFormDTOMd(formDTO.getMiniAppId(), formDTO.getAuthCode()); + dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); + // 2、调用userfeign接口获取userId、注册网格相关信息 + Result loginResiResDTOResult = epmetUserOpenFeignClient.dingResiLogin(dingLoginResiFormDTO); + if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { + // 临时打个日志 + log.error(String.format("resiLoginDingMd获取epmetUserId异常,入参:%s,user服务返参:%s", JSON.toJSONString(formDTO), JSON.toJSONString(loginResiResDTOResult))); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取epmetUserId异常:" + JSON.toJSONString(loginResiResDTOResult), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); + } + DingLoginResiResDTO resiResDTO = loginResiResDTOResult.getData(); + resDTO.setGridId(resiResDTO.getGridId()); + resDTO.setGridName(resiResDTO.getGridName()); + resDTO.setAgencyId(resiResDTO.getAgencyId()); + resDTO.setEpmetUserId(resiResDTO.getEpmetUserId()); + resDTO.setRegFlag(resiResDTO.getRegFlag()); - // 2、调用userfeign接口获取userId、注册网格相关信息 todo + // 3.生成token,并且存放Redis + String token = this.saveTokenDtoDing(formDTO.getMiniAppId(), AppClientConstant.APP_RESI, AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); + resDTO.setAuthorization(token); - //3.生成token,并且存放Redis - String token=this.saveTokenDtoDing(clientId,AppClientConstant.APP_RESI,AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); - resDTO.setAuthorization(token); + return resDTO; + } - } catch (ApiException e) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), e.getErrMsg(), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); + private DingLoginResiFormDTO getDingLoginResiFormDTOMd(String miniAppId, String authCode) { + DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); + // 1、服务商获取第三方应用授权企业的access_token,文档地址:https://open.dingtalk.com/document/orgapp-server/obtains-the-enterprise-authorized-credential + // 烟台的CorpId: dingaae55cbc47a96845f5bf40eda33b7ba0 + DingTalkResult res = dingTalkClientToken.getThirdAuthCorpAccessToken(dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret(), "abc", "dingaae55cbc47a96845f5bf40eda33b7ba0"); + if (!res.success() || StringUtils.isBlank(res.getData())) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "服务商获取第三方应用授权企业的access_token", "服务商获取第三方应用授权企业的access_token"); } - return resDTO; + // 2、通过免登码获取用户信息,文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-userid-of-a-user-by-using-the-log-free + // dingTalkClientToken.getTodo(); + // 3、查询用户详情,文档地址:https://open.dingtalk.com/document/isvapp-server/query-user-details + // dingTalkClientToken.getTodo(); + DingLoginResiFormDTO dingLoginResiFormDTO = new DingLoginResiFormDTO(); + return dingLoginResiFormDTO; } + + }