Browse Source

删除resiLoginDingTemp;resilogin-ding-md接口尝试未完

master
yinzuomei 3 years ago
parent
commit
3c04b02824
  1. 6
      epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java
  2. 23
      epmet-auth/src/main/java/com/epmet/dto/form/ResiDingAppLoginMdFormDTO.java
  3. 3
      epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java
  4. 68
      epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java

6
epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java

@ -135,4 +135,10 @@ public class ThirdLoginController {
return new Result<ResiDingAppLoginResDTO>().ok(thirdLoginService.resiLoginDing(formDTO));
}
@PostMapping("resilogin-ding-md")
public Result<ResiDingAppLoginResDTO> resiLoginDingMd(@RequestBody ResiDingAppLoginMdFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<ResiDingAppLoginResDTO>().ok(thirdLoginService.resiLoginDingMd(formDTO));
}
}

23
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;
}

3
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);
}

68
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,13 +799,11 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol
return token;
}
@Override
public ResiDingAppLoginResDTO resiLoginDingTemp(ResiDingAppLoginFormDTO formDTO) {
public ResiDingAppLoginResDTO resiLoginDingMd(ResiDingAppLoginMdFormDTO formDTO) {
// 获取用户手机号
log.info("钉钉居民端应用登录入参:"+ JSON.toJSONString(formDTO));
log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO));
ResiDingAppLoginResDTO resDTO = null;
try {
resDTO = new ResiDingAppLoginResDTO();
EnvEnum currentEnv = EnvEnum.getCurrentEnv();
if (EnvEnum.PROD.getCode().equals(currentEnv.getCode())) {
@ -815,41 +812,50 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol
} 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())){
} else {
// 其余统一走开发环境
resDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
resDTO.setGridId("763d6e09b9081d63195d53da84b3ae3a");
resDTO.setGridName("抚顺社区-抚顺第二网格");
resDTO.setAgencyId("f6e183d8e6687020074e6d8061926bfa");
resDTO.setEpmetUserId("f838614e67cf8ae0edaefe562b6660e5");
resDTO.setRegFlag(true);
}
//1、获取用户手机号 todo 这里暂时没改为miniappId
String clientId = formDTO.getMiniAppId();
DingTalkResult<AccessTokenResult> 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());
// 1、获取用户手机号
DingLoginResiFormDTO dingLoginResiFormDTO = getDingLoginResiFormDTOMd(formDTO.getMiniAppId(), formDTO.getAuthCode());
dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId());
// 2、调用userfeign接口获取userId、注册网格相关信息
Result<DingLoginResiResDTO> 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());
}
DingTalkResult<UserBaseInfo> me = dingTalkClientUser.getUserInfo("me", userAccessToken.getData().getAccessToken());
log.info("resiLoginDing me:{}",JSON.toJSONString(me));
resDTO.setExtInfo(JSON.toJSONString(me.getData()));
// 2、调用userfeign接口获取userId、注册网格相关信息 todo
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(clientId,AppClientConstant.APP_RESI,AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId());
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 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<String> 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");
}
// 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;
}
}

Loading…
Cancel
Save