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 bfea4bbbb8..f2aec2828e 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java @@ -3,7 +3,6 @@ package com.epmet.controller; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.*; -import com.epmet.dto.result.ResiDingAppLoginResDTO; import com.epmet.dto.result.StaffOrgsResultDTO; import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.service.ThirdLoginService; @@ -159,11 +158,11 @@ public class ThirdLoginController { * @param formDTO * @return */ - @PostMapping("resilogin-ding") - public Result resiLoginDing(@RequestBody ResiDingAppLoginFormDTO formDTO) { - ValidatorUtils.validateEntity(formDTO,ResiDingAppLoginFormDTO.InnerMiniApp.class); - return new Result().ok(thirdLoginService.resiLoginDing(formDTO)); - } +// @PostMapping("resilogin-ding") +// public Result resiLoginDing(@RequestBody ResiDingAppLoginFormDTO formDTO) { +// ValidatorUtils.validateEntity(formDTO,ResiDingAppLoginFormDTO.InnerMiniApp.class); +// return new Result().ok(thirdLoginService.resiLoginDing(formDTO)); +// } /** * 烟台建立应用,授权给我们,走企业免登 @@ -173,11 +172,11 @@ public class ThirdLoginController { * @param formDTO * @return */ - @PostMapping("resilogin-ding-md") - public Result resiLoginDingMd(@RequestBody DingAppLoginMdFormDTO formDTO) { - ValidatorUtils.validateEntity(formDTO); - return new Result().ok(thirdLoginService.resiLoginDingMd(formDTO)); - } +// @PostMapping("resilogin-ding-md") +// public Result resiLoginDingMd(@RequestBody DingAppLoginMdFormDTO formDTO) { +// ValidatorUtils.validateEntity(formDTO); +// return new Result().ok(thirdLoginService.resiLoginDingMd(formDTO)); +// } /** * 企业内部应用开发,不授权了 文档地址:https://open.dingtalk.com/document/orgapp-server/enterprise-internal-application-logon-free @@ -200,11 +199,11 @@ public class ThirdLoginController { * @return * 目前烟台用的这个!!!!!! */ - @PostMapping("resilogin-internalding") - public Result resiLoginInternalDing(@RequestBody DingAppLoginMdFormDTO formDTO) { - ValidatorUtils.validateEntity(formDTO); - return new Result().ok(thirdLoginService.resiLoginInternalDing(formDTO)); - } +// @PostMapping("resilogin-internalding") +// public Result resiLoginInternalDing(@RequestBody DingAppLoginMdFormDTO formDTO) { +// ValidatorUtils.validateEntity(formDTO); +// return new Result().ok(thirdLoginService.resiLoginInternalDing(formDTO)); +// } /** * 根据免登授权码, 获取登录用户身份 @@ -212,11 +211,11 @@ public class ThirdLoginController { * @param formDTO 免登授权码 * @return */ - @PostMapping("govlogin-internalding") - public Result login(@RequestBody DingAppLoginMdFormDTO formDTO) { - ValidatorUtils.validateEntity(formDTO); - return new Result().ok(thirdLoginService.govLoginInternalDing(formDTO)); - } +// @PostMapping("govlogin-internalding") +// public Result login(@RequestBody DingAppLoginMdFormDTO formDTO) { +// ValidatorUtils.validateEntity(formDTO); +// return new Result().ok(thirdLoginService.govLoginInternalDing(formDTO)); +// } /** * 根据免登授权码, 获取登录用户身份 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 6003df29b1..97653d51d0 100644 --- a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java @@ -1,7 +1,6 @@ package com.epmet.service; import com.epmet.dto.form.*; -import com.epmet.dto.result.ResiDingAppLoginResDTO; import com.epmet.dto.result.StaffOrgsResultDTO; import com.epmet.dto.result.UserTokenResultDTO; @@ -93,7 +92,7 @@ public interface ThirdLoginService { * @param formDTO * @return */ - ResiDingAppLoginResDTO resiLoginDing(ResiDingAppLoginFormDTO formDTO); +// ResiDingAppLoginResDTO resiLoginDing(ResiDingAppLoginFormDTO formDTO); /** * 企业简历内部应用授权给第三方 @@ -102,21 +101,21 @@ public interface ThirdLoginService { * @param formDTO * @return */ - ResiDingAppLoginResDTO resiLoginDingMd(DingAppLoginMdFormDTO formDTO); +// ResiDingAppLoginResDTO resiLoginDingMd(DingAppLoginMdFormDTO formDTO); /** * 企业内部应用免登 文档地址:https://open.dingtalk.com/document/orgapp-server/enterprise-internal-application-logon-free * @param formDTO * @return */ - ResiDingAppLoginResDTO resiLoginInternalDing(DingAppLoginMdFormDTO formDTO); +// ResiDingAppLoginResDTO resiLoginInternalDing(DingAppLoginMdFormDTO formDTO); /** * desc:企业内部应用 工作端登录 * @param formDTO * @return */ - UserTokenResultDTO govLoginInternalDing(DingAppLoginMdFormDTO formDTO); +// UserTokenResultDTO govLoginInternalDing(DingAppLoginMdFormDTO formDTO); /** * desc:烟台sso根据authCode 获取本系统token 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 ce1635c8cc..16944c4e7b 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 @@ -5,22 +5,18 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.aliyun.dingtalk.module.DingTalkResult; import com.epmet.auth.constants.AuthOperationConstants; 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.NumConstant; import com.epmet.commons.tools.constant.ServiceConstant; -import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.enums.EnvEnum; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.feign.ResultDataResolver; -import com.epmet.commons.tools.redis.common.CustomerDingDingRedis; -import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.password.PasswordUtils; @@ -31,8 +27,6 @@ import com.epmet.commons.tools.validator.PhoneValidatorUtils; import com.epmet.constant.AuthHttpUrlConstant; import com.epmet.constant.SmsTemplateConstant; import com.epmet.dto.*; -import com.epmet.dto.dingres.DingUserDetailDTO; -import com.epmet.dto.dingres.V2UserGetuserinfoResDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.feign.EpmetMessageOpenFeignClient; @@ -43,11 +37,6 @@ import com.epmet.jwt.JwtTokenUtils; import com.epmet.redis.CaptchaRedis; import com.epmet.service.GovWebService; import com.epmet.service.ThirdLoginService; -import com.taobao.api.ApiException; -import com.taobao.dingtalk.client.DingTalkClientToken; -import com.taobao.dingtalk.client.DingTalkClientUser; -import com.taobao.dingtalk.vo.result.AccessTokenResult; -import com.taobao.dingtalk.vo.result.UserBaseInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -87,10 +76,10 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; @Autowired private EpmetMessageOpenFeignClient messageOpenFeignClient; - @Autowired - private DingTalkClientToken dingTalkClientToken; - @Autowired - private DingTalkClientUser dingTalkClientUser; +// @Autowired +// private DingTalkClientToken dingTalkClientToken; +// @Autowired +// private DingTalkClientUser dingTalkClientUser; @Autowired private GovWebService govWebService; @@ -870,54 +859,54 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol * @param formDTO * @return */ - @Override - public ResiDingAppLoginResDTO resiLoginDing(ResiDingAppLoginFormDTO formDTO) { - //获取用户手机号 - log.info("1、钉钉居民端应用登录入参:"+ JSON.toJSONString(formDTO)); - ResiDingAppLoginResDTO resDTO= null; - try { - resDTO = new ResiDingAppLoginResDTO(); - resDTO.setCustomerId(getCurrentCustomerId()); - //1、获取用户手机号 - String miniAppId = formDTO.getMiniAppId(); - DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); - DingTalkResult userAccessToken = dingTalkClientToken.getUserAccessToken(formDTO.getAuthCode(), dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret()); - log.info("2、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("3、resiLoginDing me:{}",JSON.toJSONString(me)); - resDTO.setExtInfo(JSON.toJSONString(me.getData())); - if (!me.success() || StringUtils.isBlank(me.getData().getMobile())) { - log.error("resilogin-ding登录接口报错,入参:" + JSON.toJSONString(formDTO) + ";获取手机号为空, userAccessToken.getData().getAccessToken()=" + userAccessToken.getData().getAccessToken()); - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); - } - // 2、调用userfeign接口获取userId、注册网格相关信息 todo - DingLoginResiFormDTO dingLoginResiFormDTO=ConvertUtils.sourceToTarget(me.getData(),DingLoginResiFormDTO.class); - dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); - Result loginResiResDTOResult = epmetUserOpenFeignClient.dingResiLogin(dingLoginResiFormDTO); - if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { - //临时打个日志 - log.error(String.format("resilogin-ding获取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()); - - //3.生成token,并且存放Redis - String token=this.saveTokenDtoDing(formDTO.getMiniAppId(),AppClientConstant.APP_RESI,AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); - resDTO.setAuthorization(token); - - } catch (ApiException e) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), e.getErrMsg(), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); - } - return resDTO; - } +// @Override +// public ResiDingAppLoginResDTO resiLoginDing(ResiDingAppLoginFormDTO formDTO) { +// //获取用户手机号 +// log.info("1、钉钉居民端应用登录入参:"+ JSON.toJSONString(formDTO)); +// ResiDingAppLoginResDTO resDTO= null; +// try { +// resDTO = new ResiDingAppLoginResDTO(); +// resDTO.setCustomerId(getCurrentCustomerId()); +// //1、获取用户手机号 +// String miniAppId = formDTO.getMiniAppId(); +// DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); +// DingTalkResult userAccessToken = dingTalkClientToken.getUserAccessToken(formDTO.getAuthCode(), dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret()); +// log.info("2、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("3、resiLoginDing me:{}",JSON.toJSONString(me)); +// resDTO.setExtInfo(JSON.toJSONString(me.getData())); +// if (!me.success() || StringUtils.isBlank(me.getData().getMobile())) { +// log.error("resilogin-ding登录接口报错,入参:" + JSON.toJSONString(formDTO) + ";获取手机号为空, userAccessToken.getData().getAccessToken()=" + userAccessToken.getData().getAccessToken()); +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); +// } +// // 2、调用userfeign接口获取userId、注册网格相关信息 todo +// DingLoginResiFormDTO dingLoginResiFormDTO=ConvertUtils.sourceToTarget(me.getData(),DingLoginResiFormDTO.class); +// dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); +// Result loginResiResDTOResult = epmetUserOpenFeignClient.dingResiLogin(dingLoginResiFormDTO); +// if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { +// //临时打个日志 +// log.error(String.format("resilogin-ding获取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()); +// +// //3.生成token,并且存放Redis +// String token=this.saveTokenDtoDing(formDTO.getMiniAppId(),AppClientConstant.APP_RESI,AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); +// resDTO.setAuthorization(token); +// +// } catch (ApiException e) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), e.getErrMsg(), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); +// } +// return resDTO; +// } private String saveTokenDtoDing(String miniAppId,String app,String client, String userId,String customerId) { //生成token串 @@ -943,84 +932,84 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol return token; } - @Override - public ResiDingAppLoginResDTO resiLoginDingMd(DingAppLoginMdFormDTO formDTO) { - // 获取用户手机号 - log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); - ResiDingAppLoginResDTO resDTO = null; - resDTO = new ResiDingAppLoginResDTO(); - resDTO.setCustomerId(getCurrentCustomerId()); - // 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()); - - // 3.生成token,并且存放Redis - String token = this.saveTokenDtoDing(formDTO.getMiniAppId(), AppClientConstant.APP_RESI, AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); - resDTO.setAuthorization(token); - - return resDTO; - } - - 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 - String yantaiCorpId = "dingaae55cbc47a96845f5bf40eda33b7ba0"; - DingTalkResult res = dingTalkClientToken.getThirdAuthCorpAccessToken(dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret(), "abc", yantaiCorpId); - if (!res.success() || StringUtils.isBlank(res.getData())) { - log.error(String.format("企业内部应用免登服务商获取第三方应用授权企业的access_token失败,customKey:%s,customSecret:%s,corpId:%s", dingMiniInfo.getSuiteSecret(), dingMiniInfo.getSuiteSecret(), yantaiCorpId)); - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "服务商获取第三方应用授权企业的access_token", "服务商获取第三方应用授权企业的access_token"); - } - String accessToken = res.getData(); - log.info(String.format("1、服务商获取第三方应用授权企业的access_token返参:%s", accessToken)); - - // 2、通过免登码获取用户信息,文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-userid-of-a-user-by-using-the-log-free - DingTalkResult v2UserGetuserinfoRes = dingTalkClientToken.getUserInfo(accessToken, authCode); - if (!v2UserGetuserinfoRes.success() || StringUtils.isBlank(v2UserGetuserinfoRes.getData())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "通过免登码获取用户信息异常", "通过免登码获取用户信息异常"); - } - log.info(String.format("2、通过免登码获取用户信息返参:%s", v2UserGetuserinfoRes.getData())); - V2UserGetuserinfoResDTO v2UserGetuserinfoResDTO = JSON.parseObject(v2UserGetuserinfoRes.getData(), V2UserGetuserinfoResDTO.class); - if (null == v2UserGetuserinfoResDTO || StringUtils.isBlank(v2UserGetuserinfoResDTO.getUserid())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉用户userid为空", "获取钉钉用户userid为空"); - } - - - // 3、查询用户详情,文档地址:https://open.dingtalk.com/document/isvapp-server/query-user-details - DingTalkResult v2UserGetRes = dingTalkClientToken.getUserDetail(v2UserGetuserinfoResDTO.getUserid(), accessToken); - if (!v2UserGetRes.success() || StringUtils.isBlank(v2UserGetRes.getData())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "根据userId查询用户详情失败", "根据userId查询用户详情失败"); - } - log.info(String.format("3、查询用户详情:%s", v2UserGetRes.getData())); - DingUserDetailDTO dingUserDetailDTO = JSON.parseObject(v2UserGetRes.getData(), DingUserDetailDTO.class); - if (null == dingUserDetailDTO || StringUtils.isBlank(dingUserDetailDTO.getMobile())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); - } - - DingLoginResiFormDTO dingLoginResiFormDTO = new DingLoginResiFormDTO(); - dingLoginResiFormDTO.setAvatarUrl(dingUserDetailDTO.getAvatar()); - dingLoginResiFormDTO.setEmail(dingUserDetailDTO.getOrg_email()); - dingLoginResiFormDTO.setMobile(dingUserDetailDTO.getMobile()); - dingLoginResiFormDTO.setNick(dingUserDetailDTO.getName()); - dingLoginResiFormDTO.setOpenId(StrConstant.EPMETY_STR); - dingLoginResiFormDTO.setStateCode(dingUserDetailDTO.getState_code()); - dingLoginResiFormDTO.setUnionId(dingUserDetailDTO.getUnionid()); - return dingLoginResiFormDTO; - } +// @Override +// public ResiDingAppLoginResDTO resiLoginDingMd(DingAppLoginMdFormDTO formDTO) { +// // 获取用户手机号 +// log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); +// ResiDingAppLoginResDTO resDTO = null; +// resDTO = new ResiDingAppLoginResDTO(); +// resDTO.setCustomerId(getCurrentCustomerId()); +// // 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()); +// +// // 3.生成token,并且存放Redis +// String token = this.saveTokenDtoDing(formDTO.getMiniAppId(), AppClientConstant.APP_RESI, AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); +// resDTO.setAuthorization(token); +// +// return resDTO; +// } + +// 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 +// String yantaiCorpId = "dingaae55cbc47a96845f5bf40eda33b7ba0"; +// DingTalkResult res = dingTalkClientToken.getThirdAuthCorpAccessToken(dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret(), "abc", yantaiCorpId); +// if (!res.success() || StringUtils.isBlank(res.getData())) { +// log.error(String.format("企业内部应用免登服务商获取第三方应用授权企业的access_token失败,customKey:%s,customSecret:%s,corpId:%s", dingMiniInfo.getSuiteSecret(), dingMiniInfo.getSuiteSecret(), yantaiCorpId)); +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "服务商获取第三方应用授权企业的access_token", "服务商获取第三方应用授权企业的access_token"); +// } +// String accessToken = res.getData(); +// log.info(String.format("1、服务商获取第三方应用授权企业的access_token返参:%s", accessToken)); +// +// // 2、通过免登码获取用户信息,文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-userid-of-a-user-by-using-the-log-free +// DingTalkResult v2UserGetuserinfoRes = dingTalkClientToken.getUserInfo(accessToken, authCode); +// if (!v2UserGetuserinfoRes.success() || StringUtils.isBlank(v2UserGetuserinfoRes.getData())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "通过免登码获取用户信息异常", "通过免登码获取用户信息异常"); +// } +// log.info(String.format("2、通过免登码获取用户信息返参:%s", v2UserGetuserinfoRes.getData())); +// V2UserGetuserinfoResDTO v2UserGetuserinfoResDTO = JSON.parseObject(v2UserGetuserinfoRes.getData(), V2UserGetuserinfoResDTO.class); +// if (null == v2UserGetuserinfoResDTO || StringUtils.isBlank(v2UserGetuserinfoResDTO.getUserid())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉用户userid为空", "获取钉钉用户userid为空"); +// } +// +// +// // 3、查询用户详情,文档地址:https://open.dingtalk.com/document/isvapp-server/query-user-details +// DingTalkResult v2UserGetRes = dingTalkClientToken.getUserDetail(v2UserGetuserinfoResDTO.getUserid(), accessToken); +// if (!v2UserGetRes.success() || StringUtils.isBlank(v2UserGetRes.getData())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "根据userId查询用户详情失败", "根据userId查询用户详情失败"); +// } +// log.info(String.format("3、查询用户详情:%s", v2UserGetRes.getData())); +// DingUserDetailDTO dingUserDetailDTO = JSON.parseObject(v2UserGetRes.getData(), DingUserDetailDTO.class); +// if (null == dingUserDetailDTO || StringUtils.isBlank(dingUserDetailDTO.getMobile())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); +// } +// +// DingLoginResiFormDTO dingLoginResiFormDTO = new DingLoginResiFormDTO(); +// dingLoginResiFormDTO.setAvatarUrl(dingUserDetailDTO.getAvatar()); +// dingLoginResiFormDTO.setEmail(dingUserDetailDTO.getOrg_email()); +// dingLoginResiFormDTO.setMobile(dingUserDetailDTO.getMobile()); +// dingLoginResiFormDTO.setNick(dingUserDetailDTO.getName()); +// dingLoginResiFormDTO.setOpenId(StrConstant.EPMETY_STR); +// dingLoginResiFormDTO.setStateCode(dingUserDetailDTO.getState_code()); +// dingLoginResiFormDTO.setUnionId(dingUserDetailDTO.getUnionid()); +// return dingLoginResiFormDTO; +// } /** @@ -1043,57 +1032,57 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol * @param formDTO * @return */ - @Override - public ResiDingAppLoginResDTO resiLoginInternalDing(DingAppLoginMdFormDTO formDTO) { - // 获取用户手机号 - log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); - ResiDingAppLoginResDTO resDTO = new ResiDingAppLoginResDTO(); - resDTO.setCustomerId(getCurrentCustomerId()); - - // 1、获取用户手机号 - DingLoginResiFormDTO dingLoginResiFormDTO = getDingLoginResiFormDTOInternal(formDTO.getMiniAppId(), formDTO.getAuthCode()); - dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); - resDTO.setRealName(dingLoginResiFormDTO.getNick()); - // 2、调用userfeign接口获取userId、注册网格相关信息 - Result loginResiResDTOResult = epmetUserOpenFeignClient.dingResiLogin(dingLoginResiFormDTO); - if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { - // 临时打个日志 - log.error(String.format("resiLoginInternalDing获取epmetUserId异常,入参:%s", JSON.toJSONString(dingLoginResiFormDTO))); - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取epmetUserId异常:"+ JSON.toJSONString(loginResiResDTOResult), "获取epmetUserId异常"); - } - DingLoginResiResDTO resiResDTO = loginResiResDTOResult.getData(); - resDTO.setGridId(resiResDTO.getGridId()); - resDTO.setGridName(resiResDTO.getGridName()); - resDTO.setAgencyId(resiResDTO.getAgencyId()); - resDTO.setEpmetUserId(resiResDTO.getEpmetUserId()); - resDTO.setRegFlag(resiResDTO.getRegFlag()); - - // 3.生成token,并且存放Redis - String token = this.saveTokenDtoDing(formDTO.getMiniAppId(), AppClientConstant.APP_RESI, AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); - resDTO.setAuthorization(token); - - return resDTO; - } - - @Override - public UserTokenResultDTO govLoginInternalDing(DingAppLoginMdFormDTO formDTO) { - // 获取用户手机号 - log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); - ResiDingAppLoginResDTO resDTO = null; - resDTO = new ResiDingAppLoginResDTO(); - resDTO.setCustomerId(getCurrentCustomerId()); - - // 1、获取用户手机号 - DingLoginResiFormDTO dingLoginResiFormDTO = getDingLoginResiFormDTOInternal(formDTO.getMiniAppId(), formDTO.getAuthCode()); - dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); - - - GovWebLoginFormDTO loginGovParam = new GovWebLoginFormDTO(); - loginGovParam.setCustomerId(dingLoginResiFormDTO.getCustomerId()); - loginGovParam.setPhone(dingLoginResiFormDTO.getMobile()); - - return govWebService.loginByThirdPlatform(loginGovParam); - } +// @Override +// public ResiDingAppLoginResDTO resiLoginInternalDing(DingAppLoginMdFormDTO formDTO) { +// // 获取用户手机号 +// log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); +// ResiDingAppLoginResDTO resDTO = new ResiDingAppLoginResDTO(); +// resDTO.setCustomerId(getCurrentCustomerId()); +// +// // 1、获取用户手机号 +// DingLoginResiFormDTO dingLoginResiFormDTO = getDingLoginResiFormDTOInternal(formDTO.getMiniAppId(), formDTO.getAuthCode()); +// dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); +// resDTO.setRealName(dingLoginResiFormDTO.getNick()); +// // 2、调用userfeign接口获取userId、注册网格相关信息 +// Result loginResiResDTOResult = epmetUserOpenFeignClient.dingResiLogin(dingLoginResiFormDTO); +// if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { +// // 临时打个日志 +// log.error(String.format("resiLoginInternalDing获取epmetUserId异常,入参:%s", JSON.toJSONString(dingLoginResiFormDTO))); +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取epmetUserId异常:"+ JSON.toJSONString(loginResiResDTOResult), "获取epmetUserId异常"); +// } +// DingLoginResiResDTO resiResDTO = loginResiResDTOResult.getData(); +// resDTO.setGridId(resiResDTO.getGridId()); +// resDTO.setGridName(resiResDTO.getGridName()); +// resDTO.setAgencyId(resiResDTO.getAgencyId()); +// resDTO.setEpmetUserId(resiResDTO.getEpmetUserId()); +// resDTO.setRegFlag(resiResDTO.getRegFlag()); +// +// // 3.生成token,并且存放Redis +// String token = this.saveTokenDtoDing(formDTO.getMiniAppId(), AppClientConstant.APP_RESI, AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); +// resDTO.setAuthorization(token); +// +// return resDTO; +// } + +// @Override +// public UserTokenResultDTO govLoginInternalDing(DingAppLoginMdFormDTO formDTO) { +// // 获取用户手机号 +// log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); +// ResiDingAppLoginResDTO resDTO = null; +// resDTO = new ResiDingAppLoginResDTO(); +// resDTO.setCustomerId(getCurrentCustomerId()); +// +// // 1、获取用户手机号 +// DingLoginResiFormDTO dingLoginResiFormDTO = getDingLoginResiFormDTOInternal(formDTO.getMiniAppId(), formDTO.getAuthCode()); +// dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); +// +// +// GovWebLoginFormDTO loginGovParam = new GovWebLoginFormDTO(); +// loginGovParam.setCustomerId(dingLoginResiFormDTO.getCustomerId()); +// loginGovParam.setPhone(dingLoginResiFormDTO.getMobile()); +// +// return govWebService.loginByThirdPlatform(loginGovParam); +// } @Override public UserTokenResultDTO yanTaiSSOLogin(String authCode) { @@ -1115,55 +1104,55 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol * @param authCode * @return */ - private DingLoginResiFormDTO getDingLoginResiFormDTOInternal(String miniAppId, String authCode) { - DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); - if (dingMiniInfo == null){ - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉应用配置异常", "获取钉钉应用配置异常"); - } - // 1、获取企业内部应用的accessToken文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-access_token-of-an-internal-app - String accessToken = ""; - DingTalkResult dingTalkResult = dingTalkClientToken.getAppAccessTokenToken(dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret()); - if (!dingTalkResult.success() || StringUtils.isBlank(dingTalkResult.getData())) { - log.error(String.format("获取企业内部应用的accessToken失败,customKey:%s,customSecret:%s", dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret())); - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取企业内部应用的accessToken异常", "获取企业内部应用的accessToken"); - } - accessToken = dingTalkResult.getData(); - log.info(String.format("1、获取企业内部应用的accessToken返参:%s", accessToken)); - - - // 2、通过免登码获取用户信息,文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-userid-of-a-user-by-using-the-log-free - DingTalkResult v2UserGetuserinfoRes = dingTalkClientToken.getUserInfo(accessToken, authCode); - if (!v2UserGetuserinfoRes.success() || StringUtils.isBlank(v2UserGetuserinfoRes.getData())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "通过免登码获取用户信息异常", "通过免登码获取用户信息异常"); - } - log.info(String.format("2、通过免登码获取用户信息返参:%s", v2UserGetuserinfoRes.getData())); - V2UserGetuserinfoResDTO v2UserGetuserinfoResDTO = JSON.parseObject(v2UserGetuserinfoRes.getData(), V2UserGetuserinfoResDTO.class); - if (null == v2UserGetuserinfoResDTO || StringUtils.isBlank(v2UserGetuserinfoResDTO.getUserid())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉用户userid为空", "获取钉钉用户userid为空"); - } - - - // 3、查询用户详情,文档地址:https://open.dingtalk.com/document/isvapp-server/query-user-details - DingTalkResult v2UserGetRes = dingTalkClientToken.getUserDetail(v2UserGetuserinfoResDTO.getUserid(), accessToken); - if (!v2UserGetRes.success() || StringUtils.isBlank(v2UserGetRes.getData())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "根据userId查询用户详情失败", "根据userId查询用户详情失败"); - } - log.info(String.format("3、查询用户详情:%s", v2UserGetRes.getData())); - DingUserDetailDTO dingUserDetailDTO = JSON.parseObject(v2UserGetRes.getData(), DingUserDetailDTO.class); - if (null == dingUserDetailDTO || StringUtils.isBlank(dingUserDetailDTO.getMobile())) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); - } - - DingLoginResiFormDTO dingLoginResiFormDTO = new DingLoginResiFormDTO(); - dingLoginResiFormDTO.setAvatarUrl(dingUserDetailDTO.getAvatar()); - dingLoginResiFormDTO.setEmail(dingUserDetailDTO.getOrg_email()); - dingLoginResiFormDTO.setMobile(dingUserDetailDTO.getMobile()); - dingLoginResiFormDTO.setNick(dingUserDetailDTO.getName()); - dingLoginResiFormDTO.setOpenId(StrConstant.EPMETY_STR); - dingLoginResiFormDTO.setStateCode(dingUserDetailDTO.getState_code()); - dingLoginResiFormDTO.setUnionId(dingUserDetailDTO.getUnionid()); - return dingLoginResiFormDTO; - } +// private DingLoginResiFormDTO getDingLoginResiFormDTOInternal(String miniAppId, String authCode) { +// DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); +// if (dingMiniInfo == null){ +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉应用配置异常", "获取钉钉应用配置异常"); +// } +// // 1、获取企业内部应用的accessToken文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-access_token-of-an-internal-app +// String accessToken = ""; +// DingTalkResult dingTalkResult = dingTalkClientToken.getAppAccessTokenToken(dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret()); +// if (!dingTalkResult.success() || StringUtils.isBlank(dingTalkResult.getData())) { +// log.error(String.format("获取企业内部应用的accessToken失败,customKey:%s,customSecret:%s", dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret())); +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取企业内部应用的accessToken异常", "获取企业内部应用的accessToken"); +// } +// accessToken = dingTalkResult.getData(); +// log.info(String.format("1、获取企业内部应用的accessToken返参:%s", accessToken)); +// +// +// // 2、通过免登码获取用户信息,文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-userid-of-a-user-by-using-the-log-free +// DingTalkResult v2UserGetuserinfoRes = dingTalkClientToken.getUserInfo(accessToken, authCode); +// if (!v2UserGetuserinfoRes.success() || StringUtils.isBlank(v2UserGetuserinfoRes.getData())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "通过免登码获取用户信息异常", "通过免登码获取用户信息异常"); +// } +// log.info(String.format("2、通过免登码获取用户信息返参:%s", v2UserGetuserinfoRes.getData())); +// V2UserGetuserinfoResDTO v2UserGetuserinfoResDTO = JSON.parseObject(v2UserGetuserinfoRes.getData(), V2UserGetuserinfoResDTO.class); +// if (null == v2UserGetuserinfoResDTO || StringUtils.isBlank(v2UserGetuserinfoResDTO.getUserid())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉用户userid为空", "获取钉钉用户userid为空"); +// } +// +// +// // 3、查询用户详情,文档地址:https://open.dingtalk.com/document/isvapp-server/query-user-details +// DingTalkResult v2UserGetRes = dingTalkClientToken.getUserDetail(v2UserGetuserinfoResDTO.getUserid(), accessToken); +// if (!v2UserGetRes.success() || StringUtils.isBlank(v2UserGetRes.getData())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "根据userId查询用户详情失败", "根据userId查询用户详情失败"); +// } +// log.info(String.format("3、查询用户详情:%s", v2UserGetRes.getData())); +// DingUserDetailDTO dingUserDetailDTO = JSON.parseObject(v2UserGetRes.getData(), DingUserDetailDTO.class); +// if (null == dingUserDetailDTO || StringUtils.isBlank(dingUserDetailDTO.getMobile())) { +// throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); +// } +// +// DingLoginResiFormDTO dingLoginResiFormDTO = new DingLoginResiFormDTO(); +// dingLoginResiFormDTO.setAvatarUrl(dingUserDetailDTO.getAvatar()); +// dingLoginResiFormDTO.setEmail(dingUserDetailDTO.getOrg_email()); +// dingLoginResiFormDTO.setMobile(dingUserDetailDTO.getMobile()); +// dingLoginResiFormDTO.setNick(dingUserDetailDTO.getName()); +// dingLoginResiFormDTO.setOpenId(StrConstant.EPMETY_STR); +// dingLoginResiFormDTO.setStateCode(dingUserDetailDTO.getState_code()); +// dingLoginResiFormDTO.setUnionId(dingUserDetailDTO.getUnionid()); +// return dingLoginResiFormDTO; +// } /** * 客户写死吧 diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/EpmetThirdApplication.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/EpmetThirdApplication.java index 21c518e033..3efd642c87 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/EpmetThirdApplication.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/EpmetThirdApplication.java @@ -1,7 +1,6 @@ package com.epmet; import com.epmet.mq.properties.RocketMQProperties; -import com.taobao.dingtalk.spring.annotations.EnableDingTalk; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -9,7 +8,6 @@ import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; -@EnableDingTalk @EnableConfigurationProperties(RocketMQProperties.class) @SpringBootApplication @EnableDiscoveryClient diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java index 8164c4cdbe..a978ece6eb 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java @@ -1,29 +1,14 @@ package com.epmet.controller.dingtalk; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.aliyun.dingtalk.util.DingCallbackCrypto; -import com.epmet.commons.tools.constant.NumConstant; -import com.epmet.commons.tools.dto.form.DingMiniInfoFormDTO; -import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; -import com.epmet.commons.tools.utils.Result; -import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dao.OpenSyncBizDataDao; -import com.epmet.dto.DingMiniInfoDTO; -import com.epmet.dto.form.ExemptLoginUserDetailFormDTO; -import com.epmet.entity.OpenSyncBizDataEntity; import com.epmet.redis.DingDingCallbackRedis; import com.epmet.service.DingTalkService; import com.epmet.service.OpenSyncBizDataService; -import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * ISV 小程序回调信息处理 @@ -65,81 +50,81 @@ public class CallbackController { @Autowired private DingTalkService dingTalkService; - @PostMapping(value = "dingCallback") - public Object dingCallback( - @RequestParam(value = "signature") String signature, - @RequestParam(value = "timestamp") Long timestamp, - @RequestParam(value = "nonce") String nonce, - @RequestParam(value = "suiteKey") String suiteKey, - @RequestBody(required = false) JSONObject body - ) { - String params = "signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " body:" + body + "suiteKey::"+suiteKey; - try { - log.info("begin callback:" + params); - DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfo(suiteKey); - DingCallbackCrypto dingTalkEncryptor = new DingCallbackCrypto(dingMiniInfo.getToken(), dingMiniInfo.getAesKey(), suiteKey); - - // 从post请求的body中获取回调信息的加密数据进行解密处理 - String encrypt = body.getString("encrypt"); - String plainText = dingTalkEncryptor.getDecryptMsg(signature, timestamp.toString(), nonce, encrypt); - JSONObject callBackContent = JSON.parseObject(plainText); - - log.info("推来的消息体:"+plainText); - - // 根据回调事件类型做不同的业务处理 - String eventType = callBackContent.getString("EventType"); - if (EVENT_CHECK_CREATE_SUITE_URL.equals(eventType)) { - log.info("验证新创建的回调URL有效性: " + plainText); - } else if (EVENT_CHECK_UPADTE_SUITE_URL.equals(eventType)) { - log.info("验证更新回调URL有效性: " + plainText); - } else if (EVENT_SUITE_TICKET.equals(eventType)) { - // suite_ticket用于用签名形式生成accessToken(访问钉钉服务端的凭证),需要保存到应用的db。 - // 钉钉会定期向本callback url推送suite_ticket新值用以提升安全性。 - // 应用在获取到新的时值时,保存db成功后,返回给钉钉success加密串(如本demo的return) - log.info("应用suite_ticket数据推送: " + plainText); - } else if (EVENT_TMP_AUTH_CODE.equals(eventType)) { - // 本事件应用应该异步进行授权开通企业的初始化,目的是尽最大努力快速返回给钉钉服务端。用以提升企业管理员开通应用体验 - // 即使本接口没有收到数据或者收到事件后处理初始化失败都可以后续再用户试用应用时从前端获取到corpId并拉取授权企业信息,进而初始化开通及企业。 - log.info("企业授权开通应用事件: " + plainText); - } else if (EVENT_SYNC_HTTP_PUSH_HIGH.equals(eventType)){ - List> bizData = (List>) callBackContent.get("bizData"); - if (CollectionUtils.isNotEmpty(bizData)){ - List list = new ArrayList<>(); - bizData.forEach(b -> { - OpenSyncBizDataEntity e = new OpenSyncBizDataEntity(); - e.setSuiteKey(suiteKey); - e.setSubscribeId(b.get("subscribe_id").toString()); - e.setCorpId(b.get("corp_id").toString()); - e.setBizId(b.get("biz_id").toString()); - e.setBizData(b.get("biz_data").toString()); - e.setBizType(b.get("biz_type").toString()); - list.add(e); - openSyncBizDataService.delete(e); - if (e.getBizType().equals(NumConstant.TWO_STR)){ - Map ticketMap = JSON.parseObject(e.getBizData(), Map.class); - dingCallbackRedis.set(suiteKey,ticketMap.get("suiteTicket")); - } - }); - openSyncBizDataService.insertBatch(list); - } - } else{ - // 其他类型事件处理 - } - - // 返回success的加密信息表示回调处理成功 - return dingTalkEncryptor.getEncryptedMap("success", timestamp, nonce); - } catch (Exception e) { - //失败的情况,应用的开发者应该通过告警感知,并干预修复 - log.error("process callback fail." + params, e); - return "fail"; - } - } - - @PostMapping("getExemptLoginUserDetail") - public Result getExemptLoginUserDetail(@RequestBody ExemptLoginUserDetailFormDTO formDTO){ - ValidatorUtils.validateEntity(formDTO, ExemptLoginUserDetailFormDTO.ExemptLoginUserDetailForm.class); - return new Result().ok(dingTalkService.getExemptLoginUserDetail(formDTO)); - } +// @PostMapping(value = "dingCallback") +// public Object dingCallback( +// @RequestParam(value = "signature") String signature, +// @RequestParam(value = "timestamp") Long timestamp, +// @RequestParam(value = "nonce") String nonce, +// @RequestParam(value = "suiteKey") String suiteKey, +// @RequestBody(required = false) JSONObject body +// ) { +// String params = "signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " body:" + body + "suiteKey::"+suiteKey; +// try { +// log.info("begin callback:" + params); +// DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfo(suiteKey); +// DingCallbackCrypto dingTalkEncryptor = new DingCallbackCrypto(dingMiniInfo.getToken(), dingMiniInfo.getAesKey(), suiteKey); +// +// // 从post请求的body中获取回调信息的加密数据进行解密处理 +// String encrypt = body.getString("encrypt"); +// String plainText = dingTalkEncryptor.getDecryptMsg(signature, timestamp.toString(), nonce, encrypt); +// JSONObject callBackContent = JSON.parseObject(plainText); +// +// log.info("推来的消息体:"+plainText); +// +// // 根据回调事件类型做不同的业务处理 +// String eventType = callBackContent.getString("EventType"); +// if (EVENT_CHECK_CREATE_SUITE_URL.equals(eventType)) { +// log.info("验证新创建的回调URL有效性: " + plainText); +// } else if (EVENT_CHECK_UPADTE_SUITE_URL.equals(eventType)) { +// log.info("验证更新回调URL有效性: " + plainText); +// } else if (EVENT_SUITE_TICKET.equals(eventType)) { +// // suite_ticket用于用签名形式生成accessToken(访问钉钉服务端的凭证),需要保存到应用的db。 +// // 钉钉会定期向本callback url推送suite_ticket新值用以提升安全性。 +// // 应用在获取到新的时值时,保存db成功后,返回给钉钉success加密串(如本demo的return) +// log.info("应用suite_ticket数据推送: " + plainText); +// } else if (EVENT_TMP_AUTH_CODE.equals(eventType)) { +// // 本事件应用应该异步进行授权开通企业的初始化,目的是尽最大努力快速返回给钉钉服务端。用以提升企业管理员开通应用体验 +// // 即使本接口没有收到数据或者收到事件后处理初始化失败都可以后续再用户试用应用时从前端获取到corpId并拉取授权企业信息,进而初始化开通及企业。 +// log.info("企业授权开通应用事件: " + plainText); +// } else if (EVENT_SYNC_HTTP_PUSH_HIGH.equals(eventType)){ +// List> bizData = (List>) callBackContent.get("bizData"); +// if (CollectionUtils.isNotEmpty(bizData)){ +// List list = new ArrayList<>(); +// bizData.forEach(b -> { +// OpenSyncBizDataEntity e = new OpenSyncBizDataEntity(); +// e.setSuiteKey(suiteKey); +// e.setSubscribeId(b.get("subscribe_id").toString()); +// e.setCorpId(b.get("corp_id").toString()); +// e.setBizId(b.get("biz_id").toString()); +// e.setBizData(b.get("biz_data").toString()); +// e.setBizType(b.get("biz_type").toString()); +// list.add(e); +// openSyncBizDataService.delete(e); +// if (e.getBizType().equals(NumConstant.TWO_STR)){ +// Map ticketMap = JSON.parseObject(e.getBizData(), Map.class); +// dingCallbackRedis.set(suiteKey,ticketMap.get("suiteTicket")); +// } +// }); +// openSyncBizDataService.insertBatch(list); +// } +// } else{ +// // 其他类型事件处理 +// } +// +// // 返回success的加密信息表示回调处理成功 +// return dingTalkEncryptor.getEncryptedMap("success", timestamp, nonce); +// } catch (Exception e) { +// //失败的情况,应用的开发者应该通过告警感知,并干预修复 +// log.error("process callback fail." + params, e); +// return "fail"; +// } +// } + +// @PostMapping("getExemptLoginUserDetail") +// public Result getExemptLoginUserDetail(@RequestBody ExemptLoginUserDetailFormDTO formDTO){ +// ValidatorUtils.validateEntity(formDTO, ExemptLoginUserDetailFormDTO.ExemptLoginUserDetailForm.class); +// return new Result().ok(dingTalkService.getExemptLoginUserDetail(formDTO)); +// } /** * Desc: 获取钉钉小程序信息 @@ -147,9 +132,9 @@ public class CallbackController { * @author zxc * @date 2022/9/15 10:46 */ - @PostMapping("getDingMiniInfo") - public Result getDingMiniInfo(@RequestBody DingMiniInfoFormDTO formDTO){ - ValidatorUtils.validateEntity(formDTO, DingMiniInfoFormDTO.DingMiniInfoForm.class); - return new Result().ok(dingTalkService.getDingMiniInfo(formDTO)); - } +// @PostMapping("getDingMiniInfo") +// public Result getDingMiniInfo(@RequestBody DingMiniInfoFormDTO formDTO){ +// ValidatorUtils.validateEntity(formDTO, DingMiniInfoFormDTO.DingMiniInfoForm.class); +// return new Result().ok(dingTalkService.getDingMiniInfo(formDTO)); +// } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/tccc/TCCCAuthController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/tccc/TCCCAuthController.java index dd852c7eca..086f325d11 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/tccc/TCCCAuthController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/tccc/TCCCAuthController.java @@ -1,6 +1,8 @@ package com.epmet.controller.tccc; import com.epmet.commons.tools.utils.net.TCCCClientUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -8,8 +10,10 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("tccc") +@Api(tags = "获取腾讯呼叫中心URL") public class TCCCAuthController { + @ApiOperation(value = "tccc") @RequestMapping("getTcccAuth") public String getTcccAuth() { try { diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DingTalkService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DingTalkService.java index ca0ba390f8..1d282c1749 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DingTalkService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DingTalkService.java @@ -1,9 +1,5 @@ package com.epmet.service; -import com.epmet.commons.tools.dto.form.DingMiniInfoFormDTO; -import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; -import com.epmet.dto.form.ExemptLoginUserDetailFormDTO; - /** * @Author zxc * @DateTime 2022/9/14 14:56 @@ -11,7 +7,7 @@ import com.epmet.dto.form.ExemptLoginUserDetailFormDTO; */ public interface DingTalkService { - Object getExemptLoginUserDetail(ExemptLoginUserDetailFormDTO formDTO); +// Object getExemptLoginUserDetail(ExemptLoginUserDetailFormDTO formDTO); /** * Desc: 获取钉钉小程序信息 @@ -19,6 +15,6 @@ public interface DingTalkService { * @author zxc * @date 2022/9/15 10:46 */ - DingMiniInfoCache getDingMiniInfo(DingMiniInfoFormDTO formDTO); +// DingMiniInfoCache getDingMiniInfo(DingMiniInfoFormDTO formDTO); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DingTalkServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DingTalkServiceImpl.java index ec239a3ee9..ab2357d109 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DingTalkServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DingTalkServiceImpl.java @@ -1,24 +1,11 @@ package com.epmet.service.impl; -import cn.hutool.core.bean.BeanUtil; -import com.aliyun.dingtalk.module.DingTalkResult; -import com.epmet.commons.tools.dto.form.DingMiniInfoFormDTO; -import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; -import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; -import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.dao.OpenSyncBizDataDao; -import com.epmet.dto.DingMiniInfoDTO; -import com.epmet.dto.form.ExemptLoginUserDetailFormDTO; import com.epmet.redis.DingDingCallbackRedis; import com.epmet.service.DingTalkService; -import com.taobao.dingtalk.client.DingTalkClientToken; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import java.util.Map; /** * @Author zxc @@ -29,21 +16,21 @@ import java.util.Map; @Slf4j public class DingTalkServiceImpl implements DingTalkService { - @Autowired - private DingTalkClientToken dingTalkClientToken; - @Autowired - private OpenSyncBizDataDao openSyncBizDataDao; +// @Autowired +// private DingTalkClientToken dingTalkClientToken; +// @Autowired +// private OpenSyncBizDataDao openSyncBizDataDao; @Autowired private DingDingCallbackRedis dingCallbackRedis; @Autowired private RedisUtils redisUtils; - @Override - public Object getExemptLoginUserDetail(ExemptLoginUserDetailFormDTO formDTO) { - DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfoByAppId(formDTO.getMiniAppId()); - DingTalkResult exemptLoginUserDetail = dingTalkClientToken.getExemptLoginUserDetail(formDTO.getCorpId(), dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret(), dingCallbackRedis.get(dingMiniInfo.getSuiteKey()), formDTO.getCode()); - return exemptLoginUserDetail.getData(); - } +// @Override +// public Object getExemptLoginUserDetail(ExemptLoginUserDetailFormDTO formDTO) { +// DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfoByAppId(formDTO.getMiniAppId()); +// DingTalkResult exemptLoginUserDetail = dingTalkClientToken.getExemptLoginUserDetail(formDTO.getCorpId(), dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret(), dingCallbackRedis.get(dingMiniInfo.getSuiteKey()), formDTO.getCode()); +// return exemptLoginUserDetail.getData(); +// } /** * Desc: 获取钉钉小程序信息 @@ -51,18 +38,18 @@ public class DingTalkServiceImpl implements DingTalkService { * @author zxc * @date 2022/9/15 10:46 */ - @Override - public DingMiniInfoCache getDingMiniInfo(DingMiniInfoFormDTO formDTO) { - String key = RedisKeys.getDingMiniInfoKey(formDTO.getMiniAppId()); - Map dingMiniInfoMap = redisUtils.hGetAll(key); - if (!CollectionUtils.isEmpty(dingMiniInfoMap)) { - return ConvertUtils.mapToEntity(dingMiniInfoMap,DingMiniInfoCache.class); - } - DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfoByAppId(formDTO.getMiniAppId()); - if (null != dingMiniInfo){ - redisUtils.hMSet(key, BeanUtil.beanToMap(dingMiniInfo)); - return ConvertUtils.sourceToTarget(dingMiniInfo,DingMiniInfoCache.class); - } - return null; - } +// @Override +// public DingMiniInfoCache getDingMiniInfo(DingMiniInfoFormDTO formDTO) { +// String key = RedisKeys.getDingMiniInfoKey(formDTO.getMiniAppId()); +// Map dingMiniInfoMap = redisUtils.hGetAll(key); +// if (!CollectionUtils.isEmpty(dingMiniInfoMap)) { +// return ConvertUtils.mapToEntity(dingMiniInfoMap,DingMiniInfoCache.class); +// } +// DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfoByAppId(formDTO.getMiniAppId()); +// if (null != dingMiniInfo){ +// redisUtils.hMSet(key, BeanUtil.beanToMap(dingMiniInfo)); +// return ConvertUtils.sourceToTarget(dingMiniInfo,DingMiniInfoCache.class); +// } +// return null; +// } } diff --git a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/dao/CustomerProjectParameterDao.java b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/dao/CustomerProjectParameterDao.java index 1aebe7b1d7..8d1f5b826e 100644 --- a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/dao/CustomerProjectParameterDao.java +++ b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/dao/CustomerProjectParameterDao.java @@ -87,5 +87,5 @@ public interface CustomerProjectParameterDao extends BaseDao