Compare commits

..

No commits in common. "d938d659a461e2a450080a0beb32de32135da8d4" and "6bacdb06bc02156bc8770f7717b465779e865b5b" have entirely different histories.

4 changed files with 137 additions and 49 deletions

View File

@ -80,7 +80,6 @@ public class ManagerServiceImpl implements ManagerService {
User user = userRepository.query(context.getTarget()); User user = userRepository.query(context.getTarget());
List<Long> qxAppModuleIds = new ArrayList<>(); List<Long> qxAppModuleIds = new ArrayList<>();
if (null != user.getUserId()) { if (null != user.getUserId()) {
try {
// 天融信用户获取权限系统菜单权限 // 天融信用户获取权限系统菜单权限
log.info("开始获取天融信登录用户所拥有权限系统列表"); log.info("开始获取天融信登录用户所拥有权限系统列表");
List<AppModule> appModules = trxServiceImpl.queryQxCategoryList(trxToken, user.getUserId()); List<AppModule> appModules = trxServiceImpl.queryQxCategoryList(trxToken, user.getUserId());
@ -92,9 +91,6 @@ public class ManagerServiceImpl implements ManagerService {
long id = Long.parseLong(appModule.getId()); long id = Long.parseLong(appModule.getId());
qxAppModuleIds.add(id); qxAppModuleIds.add(id);
} }
} catch (Exception e) {
log.error("获取天融信登录用户所拥有权限系统列表失败:", e);
}
} }
// 查询所拥有权限(菜单按钮api) // 查询所拥有权限(菜单按钮api)

View File

@ -58,19 +58,56 @@ public class TrxServiceImpl implements TrxService {
paramsMap.put("isToken", false); paramsMap.put("isToken", false);
paramsMap.put("ngx_cookie", ngxCookie); paramsMap.put("ngx_cookie", ngxCookie);
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
try { // try {
log.info("调用天融信获取随机字符串接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap)); // log.info("调用天融信获取随机字符串接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap));
result = JSONObject.parseObject(HttpUtil.get(url, paramsMap, 10000)); // result = JSONObject.parseObject(HttpUtil.get(url, paramsMap, 10000));
if ("-1".equals(result.getString("result"))) { // if ("-1".equals(result.getString("result"))) {
return new GeneralResult(false, "获取随机数失败" + result.getString("errmsg")); // return new GeneralResult(false, "获取随机数失败" + result.getString("errmsg"));
} // }
} catch (Exception e) { // } catch (Exception e) {
log.error("调用天融信获取随机字符串失败", e); // log.error("调用天融信获取随机字符串失败", e);
return new GeneralResult(false, "获取随机数失败" + e.getMessage()); // return new GeneralResult(false, "获取随机数失败" + e.getMessage());
} // }
return new GeneralResult(true, result.getString("result"), "获取随机数成功"); // return new GeneralResult(true, result.getString("result"), "获取随机数成功");
return new GeneralResult(true, "randomstr", "获取随机数成功");
} }
// 获取天融信用户信息
// @Override
// public GeneralResult getAuthToken(TrxAuthModel trxAuthModel) {
// String url = trxUrl + "/userAuthen";
// Map<String, Object> paramsMap = new HashMap<>();
// paramsMap.put("cookie", trxAuthModel.getClientHello());
// paramsMap.put("certMd5", trxAuthModel.getServerHello());
// paramsMap.put("client_ip", trxAuthModel.getClientIp());
// JSONObject result;
// GeneralResult<Map<String, Object>> 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 @Override
public GeneralResult getAuthToken(TrxAuthModel trxAuthModel) { public GeneralResult getAuthToken(TrxAuthModel trxAuthModel) {
@ -83,7 +120,10 @@ public class TrxServiceImpl implements TrxService {
GeneralResult<Map<String, Object>> login = new GeneralResult<>(); GeneralResult<Map<String, Object>> login = new GeneralResult<>();
try { try {
log.info("调用天融信登录接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap)); log.info("调用天融信登录接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap));
result = JSONObject.parseObject(HttpUtil.post(url, paramsMap, 10000)); // 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"))) { if (!"0".equals(result.getString("result"))) {
return new GeneralResult(false, "用户登录天融信失败" + result.getString("errmsg")); return new GeneralResult(false, "用户登录天融信失败" + result.getString("errmsg"));
} }
@ -115,7 +155,12 @@ public class TrxServiceImpl implements TrxService {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("userId", userId); 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)) { if (ObjectUtils.isEmpty(user)) {
log.info("开始新增天融信登录用户userId: " + userId); log.info("开始新增天融信登录用户userId: " + userId);
// 新增 以userId作为account 并添加注释 // 新增 以userId作为account 并添加注释
@ -166,18 +211,70 @@ 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<Long> 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是否有效 //确认天融信token是否有效
public GeneralResult getTokenOnline(String trxToken) { public GeneralResult getTokenOnline(String trxToken) {
try {
String url = trxUrl + "/tokenOnline"; String url = trxUrl + "/tokenOnline";
JSONObject result = JSONObject.parseObject(HttpUtil.post(url, trxToken, 10000)); JSONObject result = JSONObject.parseObject(HttpUtil.post(url, trxToken));
if (!"0".equals(result.getString("result"))) { if (!"0".equals(result.getString("result"))) {
return new GeneralResult(false, "当前token无效" + result.getString("errmsg")); 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有效"); return new GeneralResult(true, "当前token有效");
} }

View File

@ -3,7 +3,6 @@ package com.bocloud.sms.service.utils;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.bocloud.sms.model.QxReqVo; import com.bocloud.sms.model.QxReqVo;
import com.megatron.common.model.GeneralResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -28,17 +27,13 @@ public class QxUtils {
} }
public String call(String url, QxReqVo qxReqVo){ public String call(String url, QxReqVo qxReqVo){
try {
String str = JSONObject.toJSONString(qxReqVo); String str = JSONObject.toJSONString(qxReqVo);
logger.info("call method[{}] req params[{}]",url,str); logger.info("call method[{}] req params[{}]",url,str);
JSONObject result = JSONObject.parseObject(HttpUtil.post(url,str, 10000)); JSONObject result = JSONObject.parseObject(HttpUtil.post(url,str));
if (!"200".equals(result.getString("status"))) { if (!"200".equals(result.getString("status"))) {
throw new IllegalArgumentException("调用权限系统接口异常" + result.getString("msg")); throw new IllegalArgumentException("调用权限系统接口异常" + result.getString("msg"));
} }
return result.getString("data"); return result.getString("data");
} catch (Exception e) {
logger.error("获取天融信token状态失败", e);
}
return null;
} }
} }

View File

@ -28,7 +28,7 @@ public class YkUtils {
String str = JSONObject.toJSONString(reqVo); String str = JSONObject.toJSONString(reqVo);
logger.info("call yk url [{}]" , url); logger.info("call yk url [{}]" , url);
logger.info("call yk method[{}] req params[{}]",reqVo.getMethod(),str); logger.info("call yk method[{}] req params[{}]",reqVo.getMethod(),str);
String resultStr = HttpUtil.post(url, str, 10000); String resultStr = HttpUtil.post(url, str);
//logger.info("call method[{}] resp params[{}]",reqVo.getMethod(),resultStr); //logger.info("call method[{}] resp params[{}]",reqVo.getMethod(),resultStr);
JSONObject result = JSONObject.parseObject(resultStr); JSONObject result = JSONObject.parseObject(resultStr);
logger.info("call yk result [{}]" , result.toString()); logger.info("call yk result [{}]" , result.toString());