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 f7ea86b..ce5886e 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 @@ -57,14 +57,58 @@ public class TrxServiceImpl implements TrxService { Map paramsMap = new HashMap<>(); paramsMap.put("isToken", false); paramsMap.put("ngx_cookie", ngxCookie); - JSONObject result = JSONObject.parseObject(HttpUtil.get(url, paramsMap)); - if ("-1".equals(result.getString("result"))) { - return new GeneralResult(false, "获取随机数失败" + result.getString("errmsg")); - } - return new GeneralResult(true, result.getString("result"), "获取随机数成功"); + JSONObject result; +// 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", "获取随机数成功"); } // 获取天融信用户信息 +// @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) { String url = trxUrl + "/userAuthen"; @@ -72,20 +116,35 @@ public class TrxServiceImpl implements TrxService { paramsMap.put("cookie", trxAuthModel.getClientHello()); paramsMap.put("certMd5", trxAuthModel.getServerHello()); paramsMap.put("client_ip", trxAuthModel.getClientIp()); - JSONObject result = JSONObject.parseObject(HttpUtil.post(url, paramsMap)); - if (!"0".equals(result.getString("result"))) { - return new GeneralResult(false, "用户登录失败" + result.getString("errmsg")); + JSONObject result = null; + GeneralResult> login; + 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"); + 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()); } - String trxToken = result.getString("token"); - String userId = result.getString("userId"); - // 处理ukey登录用户 - saveUserByTrx(userId); - // 登录 - User user = userRepository.getByUserId(userId); - Encryptor encryptor = new AESEncryptor(); - String password = encryptor.encrypt(userId + "CMP", null); - GeneralResult> login = userServiceImpl.login(user.getAccount(), password, null, null, true); - login.getData().put("trxToken", trxToken); return new GeneralResult(true, login, "用户登录成功"); } @@ -95,7 +154,12 @@ 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 = 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"); if (ObjectUtils.isEmpty(user)) { log.info("开始新增天融信登录用户,userId: " + userId); // 新增 以userId作为account 并添加注释 @@ -146,6 +210,63 @@ 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";