|
|
|
@ -343,7 +343,8 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
SysUser user = null;
|
|
|
|
|
List<SysMenu> menuList;
|
|
|
|
|
try {
|
|
|
|
|
OapiV2UserGetResponse dingTalkUserInfo = getDingTalkUserInfo(authCode);
|
|
|
|
|
// OapiV2UserGetResponse dingTalkUserInfo = getDingTalkUserInfo(authCode);
|
|
|
|
|
OapiV2UserGetResponse dingTalkUserInfo = null;
|
|
|
|
|
|
|
|
|
|
String mobile = dingTalkUserInfo.getResult().getMobile();
|
|
|
|
|
if (StringUtils.isEmpty(mobile)) {
|
|
|
|
@ -362,54 +363,53 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
return ResultBean.success("查询成功").setResultList(menuList);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/auth/dingtalk/login")
|
|
|
|
|
@ApiOperation(value = "登录", notes = "登录")
|
|
|
|
|
public ResultBean loginByPhoneNumber(HttpServletRequest request, String dingTalkTmpAuthCode,
|
|
|
|
|
@RequestParam(required = false) String languageCode,
|
|
|
|
|
@RequestParam(required = false) String deviceId) {
|
|
|
|
|
SysLoginModel loginModel = SysLoginModel.builder()
|
|
|
|
|
.dingTalkTmpAuthCode(dingTalkTmpAuthCode)
|
|
|
|
|
.languageCode(languageCode)
|
|
|
|
|
.deviceId(deviceId)
|
|
|
|
|
.loginStrategy(ImppEnumUtil.AUTH_LOGIN_STRATEGY.NAME.getCode()).build();
|
|
|
|
|
|
|
|
|
|
String dingTalkUrl = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_URL);
|
|
|
|
|
String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
String dingTalkWhiteList = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_WHITE_LIST);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(dingTalkUrl) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkAppKey) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkAppSecret) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkWhiteList)) {
|
|
|
|
|
return ResultBean.fail("访问钉钉的系统参数缺失,请在平台的系统参数中进行配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<OapiV2UserGetResponse> userInfo =
|
|
|
|
|
dingTalkService.getUserInfo(dingTalkUrl, dingTalkAppKey, dingTalkAppSecret, loginModel.getDingTalkTmpAuthCode());
|
|
|
|
|
if (userInfo.isPresent()) {
|
|
|
|
|
String mobile = userInfo.get().getResult().getMobile();
|
|
|
|
|
if (StringUtils.isEmpty(mobile)) {
|
|
|
|
|
return ResultBean.fail("用户并未在钉钉中设置手机号 或 钉钉接口权限不足无法获取到手机号");
|
|
|
|
|
}
|
|
|
|
|
if (!Arrays.asList(dingTalkWhiteList.split(",")).contains(mobile)) {
|
|
|
|
|
return ResultBean.fail("对指定手机号允许,权限不足,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
SysUser sysUserByPhone = userService.getSysUserByPhone(mobile);
|
|
|
|
|
if (sysUserByPhone == null) {
|
|
|
|
|
return ResultBean.fail("未根据用户手机在平台中找到相应记录 钉钉获取的手机号为" + mobile);
|
|
|
|
|
}
|
|
|
|
|
loginModel.setLoginName(sysUserByPhone.getUserLoginName());
|
|
|
|
|
loginModel.setPhoneNumber(mobile);
|
|
|
|
|
} else {
|
|
|
|
|
return ResultBean.fail("获取钉钉用户信息失败");
|
|
|
|
|
}
|
|
|
|
|
String beanName = ImppEnumUtil.AUTH_LOGIN_STRATEGY.codeOfStrategyName(loginModel.getLoginStrategy());
|
|
|
|
|
ISystemLoginStrategyService loginStrategyService = (ISystemLoginStrategyService) SpringContextsUtil.getBean(beanName);
|
|
|
|
|
|
|
|
|
|
return loginByStrategy(request, loginModel, loginStrategyService.login());
|
|
|
|
|
}
|
|
|
|
|
// @GetMapping(value = "/auth/dingtalk/login")
|
|
|
|
|
// @ApiOperation(value = "登录", notes = "登录")
|
|
|
|
|
// public ResultBean loginByPhoneNumber(HttpServletRequest request, String dingTalkTmpAuthCode,
|
|
|
|
|
// @RequestParam(required = false) String languageCode,
|
|
|
|
|
// @RequestParam(required = false) String deviceId) {
|
|
|
|
|
// SysLoginModel loginModel = SysLoginModel.builder()
|
|
|
|
|
// .dingTalkTmpAuthCode(dingTalkTmpAuthCode)
|
|
|
|
|
// .languageCode(languageCode)
|
|
|
|
|
// .deviceId(deviceId)
|
|
|
|
|
// .loginStrategy(ImppEnumUtil.AUTH_LOGIN_STRATEGY.NAME.getCode()).build();
|
|
|
|
|
//
|
|
|
|
|
// String dingTalkUrl = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_URL);
|
|
|
|
|
// String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
// String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
// String dingTalkWhiteList = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_WHITE_LIST);
|
|
|
|
|
//
|
|
|
|
|
// if (StringUtils.isEmpty(dingTalkUrl) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkAppKey) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkAppSecret) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkWhiteList)) {
|
|
|
|
|
// return ResultBean.fail("访问钉钉的系统参数缺失,请在平台的系统参数中进行配置");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Optional<OapiV2UserGetResponse> userInfo =
|
|
|
|
|
// dingTalkService.getUserInfo(dingTalkUrl, dingTalkAppKey, dingTalkAppSecret, loginModel.getDingTalkTmpAuthCode());
|
|
|
|
|
// if (userInfo.isPresent()) {
|
|
|
|
|
// String mobile = userInfo.get().getResult().getMobile();
|
|
|
|
|
// if (StringUtils.isEmpty(mobile)) {
|
|
|
|
|
// return ResultBean.fail("用户并未在钉钉中设置手机号 或 钉钉接口权限不足无法获取到手机号");
|
|
|
|
|
// }
|
|
|
|
|
// if (!Arrays.asList(dingTalkWhiteList.split(",")).contains(mobile)) {
|
|
|
|
|
// return ResultBean.fail("对指定手机号允许,权限不足,请联系管理员");
|
|
|
|
|
// }
|
|
|
|
|
// SysUser sysUserByPhone = userService.getSysUserByPhone(mobile);
|
|
|
|
|
// if (sysUserByPhone == null) {
|
|
|
|
|
// return ResultBean.fail("未根据用户手机在平台中找到相应记录 钉钉获取的手机号为" + mobile);
|
|
|
|
|
// }
|
|
|
|
|
// loginModel.setLoginName(sysUserByPhone.getUserLoginName());
|
|
|
|
|
// loginModel.setPhoneNumber(mobile);
|
|
|
|
|
// } else {
|
|
|
|
|
// return ResultBean.fail("获取钉钉用户信息失败");
|
|
|
|
|
// }
|
|
|
|
|
// String beanName = ImppEnumUtil.AUTH_LOGIN_STRATEGY.codeOfStrategyName(loginModel.getLoginStrategy());
|
|
|
|
|
// ISystemLoginStrategyService loginStrategyService = (ISystemLoginStrategyService) SpringContextsUtil.getBean(beanName);
|
|
|
|
|
//
|
|
|
|
|
// return loginByStrategy(request, loginModel, loginStrategyService.login());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/auth/login")
|
|
|
|
|
@ApiOperation(value = "登录", notes = "登录")
|
|
|
|
@ -1169,6 +1169,24 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// private OapiV2UserGetResponse getDingTalkUserInfo(String dingTalkTmpAuthCode) {
|
|
|
|
|
// String dingTalkUrl = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_URL);
|
|
|
|
|
// String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
// String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
// String dingTalkWhiteList = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_WHITE_LIST);
|
|
|
|
|
// if (StringUtils.isEmpty(dingTalkUrl) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkAppKey) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkAppSecret) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkWhiteList)) {
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance().setErrorDetail("访问钉钉的系统参数缺失,请在平台的系统参数中进行配置").build();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Optional<OapiV2UserGetResponse> userInfo = dingTalkService.getUserInfo(dingTalkUrl, dingTalkAppKey, dingTalkAppSecret, dingTalkTmpAuthCode);
|
|
|
|
|
// if (!userInfo.isPresent()) {
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance().setErrorDetail("访问钉钉的系统员工信息不存在").build();
|
|
|
|
|
// }
|
|
|
|
|
// return userInfo.get();
|
|
|
|
|
// }
|
|
|
|
|
private static final Long ACCESS_TOKEN_EXPIRE_TIME = 7080L;
|
|
|
|
|
private static final String ACCESS_TOKEN_KEY = "ding_talk:access_token";
|
|
|
|
|
private static final String ACCESS_EMS_TOKEN_KEY = "ding_talk_ems:access_token";
|
|
|
|
@ -1408,24 +1426,24 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private OapiV2UserGetResponse getDingTalkUserInfo(String dingTalkTmpAuthCode) {
|
|
|
|
|
String dingTalkUrl = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_URL);
|
|
|
|
|
String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
String dingTalkWhiteList = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_WHITE_LIST);
|
|
|
|
|
if (StringUtils.isEmpty(dingTalkUrl) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkAppKey) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkAppSecret) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkWhiteList)) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance().setErrorDetail("访问钉钉的系统参数缺失,请在平台的系统参数中进行配置").build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<OapiV2UserGetResponse> userInfo = dingTalkService.getUserInfo(dingTalkUrl, dingTalkAppKey, dingTalkAppSecret, dingTalkTmpAuthCode);
|
|
|
|
|
if (!userInfo.isPresent()) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance().setErrorDetail("访问钉钉的系统员工信息不存在").build();
|
|
|
|
|
}
|
|
|
|
|
return userInfo.get();
|
|
|
|
|
}
|
|
|
|
|
// private OapiV2UserGetResponse getDingTalkUserInfo(String dingTalkTmpAuthCode) {
|
|
|
|
|
// String dingTalkUrl = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_URL);
|
|
|
|
|
// String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
// String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
// String dingTalkWhiteList = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_WHITE_LIST);
|
|
|
|
|
// if (StringUtils.isEmpty(dingTalkUrl) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkAppKey) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkAppSecret) ||
|
|
|
|
|
// StringUtils.isEmpty(dingTalkWhiteList)) {
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance().setErrorDetail("访问钉钉的系统参数缺失,请在平台的系统参数中进行配置").build();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Optional<OapiV2UserGetResponse> userInfo = dingTalkService.getUserInfo(dingTalkUrl, dingTalkAppKey, dingTalkAppSecret, dingTalkTmpAuthCode);
|
|
|
|
|
// if (!userInfo.isPresent()) {
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance().setErrorDetail("访问钉钉的系统员工信息不存在").build();
|
|
|
|
|
// }
|
|
|
|
|
// return userInfo.get();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/query-user-by-name")
|
|
|
|
|
@ApiOperation(value = "根据用户名或登录名查询")
|
|
|
|
|