|
@@ -1,8 +1,10 @@
|
|
|
package cn.iocoder.yudao.module.system.service.auth;
|
|
package cn.iocoder.yudao.module.system.service.auth;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
|
|
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
|
|
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
|
|
@@ -53,6 +55,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Validator;
|
|
import javax.validation.Validator;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -100,6 +103,12 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
@Value("${oa.secret}")
|
|
@Value("${oa.secret}")
|
|
|
private String oaSecret;
|
|
private String oaSecret;
|
|
|
|
|
|
|
|
|
|
+ @Value("${zentao.code}")
|
|
|
|
|
+ private String zentaoCode;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${zentao.secret}")
|
|
|
|
|
+ private String zentaoSecret;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 验证码的开关,默认为 true
|
|
* 验证码的开关,默认为 true
|
|
|
*/
|
|
*/
|
|
@@ -443,4 +452,52 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public AuthZentaoLoginRespVO zentaoSsoToken(AuthSocialLoginReqVO reqVO) {
|
|
|
|
|
+ AuthZentaoLoginRespVO respVO = new AuthZentaoLoginRespVO();
|
|
|
|
|
+ respVO.setCode(zentaoCode);
|
|
|
|
|
+ LocalDateTime currentDate = LocalDateTime.now();
|
|
|
|
|
+ Long currentDateMilli = LocalDateTimeUtil.toEpochMilli(currentDate);
|
|
|
|
|
+ respVO.setTimestamp(currentDateMilli);
|
|
|
|
|
+ // 跳转链接 http://project.deepoil.cc/zentao/api.php?m=user&f=apilogin&account=0033777&code=Deep0ilPortal&time=1775199774917&token=43f484e18659a1898cded87e6fd8e40c
|
|
|
|
|
+ // md5 加密 code+应用密钥+时间戳 得到 token
|
|
|
|
|
+ String token = SecureUtil.md5(zentaoCode + zentaoSecret + currentDateMilli);
|
|
|
|
|
+ respVO.setToken(token);
|
|
|
|
|
+ // h5页面获取免登录授权码code 后台通过code查询用户信息
|
|
|
|
|
+ String validCode = StrUtils.xssEncode(reqVO.getCode());
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 钉钉用户id
|
|
|
|
|
+ String userId = DingtalkUtil.getUserIdByAuthCode(validCode);
|
|
|
|
|
+ if (StrUtil.isBlank(userId)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 根据钉钉用户id 查询用户详情
|
|
|
|
|
+ OapiV2UserGetResponse.UserGetResponse userDetail = DingtalkUtil.getUserDetail(userId);
|
|
|
|
|
+ if (ObjUtil.isEmpty(userDetail)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 工号
|
|
|
|
|
+ String jobNumber = userDetail.getJobNumber();
|
|
|
|
|
+ respVO.setJobNumber(jobNumber);
|
|
|
|
|
+ // 手机号
|
|
|
|
|
+ String mobile = userDetail.getMobile();
|
|
|
|
|
+ if (StrUtil.isBlank(mobile)) {
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 查询当前用户表中 此手机号 是否存在
|
|
|
|
|
+ AdminUserDO user = userService.getUserByMobile(mobile);
|
|
|
|
|
+ if (ObjUtil.isEmpty(user)) {
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ return respVO;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 调用钉钉接口报错 提示 登录失败
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|