From 7dc0594ecd9fb7f52f2aa62d6696d9bcfde12e1c Mon Sep 17 00:00:00 2001 From: "castle.zang" Date: Sun, 30 Oct 2022 10:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81form=20+=20ptl=5Fpcn=E4=BA=AE?= =?UTF-8?q?=E7=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/base/WhiteController.java | 152 ++++++++++++--------- 1 file changed, 85 insertions(+), 67 deletions(-) diff --git a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java index 726b1c1..dfa35ca 100644 --- a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java +++ b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java @@ -343,7 +343,8 @@ public class WhiteController extends CoreBaseController { SysUser user = null; List 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 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 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 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 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 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 = "根据用户名或登录名查询")