From 16f0a0967073b39180786ea667d1ec5a0c9bfcd3 Mon Sep 17 00:00:00 2001 From: bayuzhen Date: Mon, 26 Aug 2024 16:52:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0uKey=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/service/ManagerServiceImpl.java | 24 +-- .../bocloud/sms/service/TrxServiceImpl.java | 141 +++--------------- .../bocloud/sms/service/utils/QxUtils.java | 19 ++- .../bocloud/sms/service/utils/YkUtils.java | 2 +- 4 files changed, 49 insertions(+), 137 deletions(-) diff --git a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/ManagerServiceImpl.java b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/ManagerServiceImpl.java index 577bec6..45ed6e9 100644 --- a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/ManagerServiceImpl.java +++ b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/ManagerServiceImpl.java @@ -80,16 +80,20 @@ public class ManagerServiceImpl implements ManagerService { User user = userRepository.query(context.getTarget()); List qxAppModuleIds = new ArrayList<>(); if (null != user.getUserId()) { - // 天融信用户获取权限系统菜单权限 - log.info("开始获取天融信登录用户所拥有权限系统列表"); - List appModules = trxServiceImpl.queryQxCategoryList(trxToken, user.getUserId()); - if (CollectionUtils.isEmpty(appModules)) { - log.error("获取天融信登录用户所拥有权限系统列表失败"); - return new GeneralResult<>(false, "获取权限系统菜单信息失败"); - } - for (AppModule appModule : appModules) { - long id = Long.parseLong(appModule.getId()); - qxAppModuleIds.add(id); + try { + // 天融信用户获取权限系统菜单权限 + log.info("开始获取天融信登录用户所拥有权限系统列表"); + List appModules = trxServiceImpl.queryQxCategoryList(trxToken, user.getUserId()); + if (CollectionUtils.isEmpty(appModules)) { + log.error("获取天融信登录用户所拥有权限系统列表失败"); + return new GeneralResult<>(false, "获取权限系统菜单信息失败"); + } + for (AppModule appModule : appModules) { + long id = Long.parseLong(appModule.getId()); + qxAppModuleIds.add(id); + } + } catch (Exception e) { + log.error("获取天融信登录用户所拥有权限系统列表失败:", e); } } diff --git a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/TrxServiceImpl.java b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/TrxServiceImpl.java index 3e22587..4088ba7 100644 --- a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/TrxServiceImpl.java +++ b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/TrxServiceImpl.java @@ -58,56 +58,19 @@ public class TrxServiceImpl implements TrxService { paramsMap.put("isToken", false); paramsMap.put("ngx_cookie", ngxCookie); JSONObject result = new JSONObject(); -// try { -// log.info("调用天融信获取随机字符串接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap)); -// result = JSONObject.parseObject(HttpUtil.get(url, paramsMap, 10000)); -// if ("-1".equals(result.getString("result"))) { -// return new GeneralResult(false, "获取随机数失败" + result.getString("errmsg")); -// } -// } catch (Exception e) { -// log.error("调用天融信获取随机字符串失败", e); -// return new GeneralResult(false, "获取随机数失败" + e.getMessage()); -// } -// return new GeneralResult(true, result.getString("result"), "获取随机数成功"); - return new GeneralResult(true, "randomstr", "获取随机数成功"); + try { + log.info("调用天融信获取随机字符串接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap)); + result = JSONObject.parseObject(HttpUtil.get(url, paramsMap, 10000)); + if ("-1".equals(result.getString("result"))) { + return new GeneralResult(false, "获取随机数失败" + result.getString("errmsg")); + } + } catch (Exception e) { + log.error("调用天融信获取随机字符串失败", e); + return new GeneralResult(false, "获取随机数失败" + e.getMessage()); + } + return new GeneralResult(true, result.getString("result"), "获取随机数成功"); } - // 获取天融信用户信息 -// @Override -// public GeneralResult getAuthToken(TrxAuthModel trxAuthModel) { -// String url = trxUrl + "/userAuthen"; -// Map paramsMap = new HashMap<>(); -// paramsMap.put("cookie", trxAuthModel.getClientHello()); -// paramsMap.put("certMd5", trxAuthModel.getServerHello()); -// paramsMap.put("client_ip", trxAuthModel.getClientIp()); -// JSONObject result; -// GeneralResult> login; -// try { -// log.info("调用天融信登录接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap)); -// result = JSONObject.parseObject(HttpUtil.post(url, paramsMap, 10000)); -// if (!"0".equals(result.getString("result"))) { -// return new GeneralResult(false, "用户登录天融信失败" + result.getString("errmsg")); -// } -// String trxToken = result.getString("token"); -// String userId = result.getString("userId"); -// // 处理ukey登录用户 -// log.info("开始uKey登录用户入库"); -// saveUserByTrx(userId); -// log.info("uKey登录用户入库结束"); -// // 登录 -// log.info("开始uKey登录用户登录云管平台"); -// User user = userRepository.getByUserId(userId); -// Encryptor encryptor = new AESEncryptor(); -// String password = encryptor.encrypt(userId + "CMP", null); -// login = userServiceImpl.login(user.getAccount(), password, null, null, true); -// login.getData().put("trxToken", trxToken); -// log.info("uKey登录用户登录云管平台结束"); -// } catch (Exception e) { -// log.error("用户登录失败:", e); -// return new GeneralResult(false, "用户登录失败" + e.getMessage()); -// } -// return new GeneralResult(true, login, "用户登录成功"); -// } @Override public GeneralResult getAuthToken(TrxAuthModel trxAuthModel) { @@ -120,10 +83,7 @@ public class TrxServiceImpl implements TrxService { GeneralResult> login = new GeneralResult<>(); try { log.info("调用天融信登录接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap)); -// result = JSONObject.parseObject(HttpUtil.post(url, paramsMap, 10000)); - result.put("result", 0); - result.put("token", "trxTokenStr"); - result.put("userId", "100001"); + result = JSONObject.parseObject(HttpUtil.post(url, paramsMap, 10000)); if (!"0".equals(result.getString("result"))) { return new GeneralResult(false, "用户登录天融信失败" + result.getString("errmsg")); } @@ -155,12 +115,7 @@ public class TrxServiceImpl implements TrxService { JSONObject params = new JSONObject(); params.put("userId", userId); //请求运控系统获取用户信息 -// YkUserModel ykUser = JSONArray.parseArray(ykUtils.call(YkInf.queryAllUser, params, String.class), YkUserModel.class).get(0); - YkUserModel ykUser = new YkUserModel(); - ykUser.setLoginName("trx01"); - ykUser.setUserName("trx01"); - ykUser.setMobile("15238853513"); - ykUser.setEmail("188834343@qq.com"); + YkUserModel ykUser = JSONArray.parseArray(ykUtils.call(YkInf.queryAllUser, params, String.class), YkUserModel.class).get(0); if (ObjectUtils.isEmpty(user)) { log.info("开始新增天融信登录用户,userId: " + userId); // 新增 以userId作为account 并添加注释 @@ -211,69 +166,17 @@ public class TrxServiceImpl implements TrxService { } } -// private void saveUserByTrx(String userId) { -// User user = userRepository.getByUserId(userId); -// // 根据userId获取运控系统用户信息 -// JSONObject params = new JSONObject(); -// params.put("userId", userId); -// //请求运控系统获取用户信息 -// YkUserModel ykUser = JSONArray.parseArray(ykUtils.call(YkInf.queryAllUser, params, String.class), YkUserModel.class).get(0); -// if (ObjectUtils.isEmpty(user)) { -// log.info("开始新增天融信登录用户,userId: " + userId); -// // 新增 以userId作为account 并添加注释 -// UserBean userBean = new UserBean(); -// userBean.setPassword(userId + "CMP"); -// userBean.setSex(true); -// userBean.setIsManager(true); -// userBean.setUserId(userId); -// userBean.setRemark("天融信登录添加用户"); -// // 设置运控用户信息 -// userBean.setAccount(ykUser.getLoginName()); -// userBean.setName(ykUser.getUserName()); -// userBean.setMobile(ykUser.getMobile()); -// userBean.setEmail(ykUser.getEmail()); -// userBean.setUserId(userId); -// RequestContext context = new RequestContext(); -// context.setTarget(1L); -// context.setCatalog(RequestContext.Catalog.Manager); -// userServiceImpl.create(userBean, context); -// /** -// * 云管授权当前用户全部角色 -// * 1,获取云管角色列表 -// * 2,授权 -// * */ -// User userByUserId = userRepository.getByUserId(userId); -// List roleIds = roleRepository.list().stream().map(Role::getId).collect(Collectors.toList()); -// userServiceImpl.accredit(userByUserId.getId(), roleIds, context); -// log.info("完成新增天融信登录用户,userId: " + userId); -// } else { -// // 修改 -// log.info("开始修改天融信登录用户,userId: " + userId); -// UserBean userBean = new UserBean(); -// userBean.setId(user.getId()); -// userBean.setSex(true); -// userBean.setIsManager(true); -// userBean.setUserId(userId); -// userBean.setRemark("天融信登录添加用户"); -// // 设置运控用户信息 -// userBean.setAccount(ykUser.getLoginName()); -// userBean.setName(ykUser.getUserName()); -// userBean.setMobile(ykUser.getMobile()); -// userBean.setEmail(ykUser.getEmail()); -// RequestContext context = new RequestContext(); -// context.setTarget(1L); -// context.setCatalog(RequestContext.Catalog.Manager); -// userServiceImpl.modify(user.getId(), userBean, context); -// log.info("完成修改天融信登录用户,userId: " + userId); -// } -// } - //确认天融信token是否有效 public GeneralResult getTokenOnline(String trxToken) { - String url = trxUrl + "/tokenOnline"; - JSONObject result = JSONObject.parseObject(HttpUtil.post(url, trxToken)); - if (!"0".equals(result.getString("result"))) { - return new GeneralResult(false, "当前token无效" + result.getString("errmsg")); + try { + String url = trxUrl + "/tokenOnline"; + JSONObject result = JSONObject.parseObject(HttpUtil.post(url, trxToken, 10000)); + if (!"0".equals(result.getString("result"))) { + return new GeneralResult(false, "当前token无效" + result.getString("errmsg")); + } + } catch (Exception e) { + log.error("获取天融信token状态失败:", e); + return new GeneralResult(false, "获取天融信token状态失败" + e.getMessage()); } return new GeneralResult(true, "当前token有效"); } diff --git a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/QxUtils.java b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/QxUtils.java index 37f1162..16a85ad 100644 --- a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/QxUtils.java +++ b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/QxUtils.java @@ -3,6 +3,7 @@ package com.bocloud.sms.service.utils; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; import com.bocloud.sms.model.QxReqVo; +import com.megatron.common.model.GeneralResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -27,13 +28,17 @@ public class QxUtils { } public String call(String url, QxReqVo qxReqVo){ - String str = JSONObject.toJSONString(qxReqVo); - logger.info("call method[{}] req params[{}]",url,str); - JSONObject result = JSONObject.parseObject(HttpUtil.post(url,str)); - if (!"200".equals(result.getString("status"))) { - throw new IllegalArgumentException("调用权限系统接口异常" + result.getString("msg")); + try { + String str = JSONObject.toJSONString(qxReqVo); + logger.info("call method[{}] req params[{}]",url,str); + JSONObject result = JSONObject.parseObject(HttpUtil.post(url,str, 10000)); + if (!"200".equals(result.getString("status"))) { + throw new IllegalArgumentException("调用权限系统接口异常" + result.getString("msg")); + } + return result.getString("data"); + } catch (Exception e) { + logger.error("获取天融信token状态失败:", e); } - - return result.getString("data"); + return null; } } diff --git a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/YkUtils.java b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/YkUtils.java index 4560232..db79a02 100644 --- a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/YkUtils.java +++ b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/utils/YkUtils.java @@ -28,7 +28,7 @@ public class YkUtils { String str = JSONObject.toJSONString(reqVo); logger.info("call yk url [{}]" , url); logger.info("call yk method[{}] req params[{}]",reqVo.getMethod(),str); - String resultStr = HttpUtil.post(url, str); + String resultStr = HttpUtil.post(url, str, 10000); //logger.info("call method[{}] resp params[{}]",reqVo.getMethod(),resultStr); JSONObject result = JSONObject.parseObject(resultStr); logger.info("call yk result [{}]" , result.toString());