|
|
@ -23,30 +23,35 @@ public class WaterRequestUtil { |
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(WaterRequestUtil.class); |
|
|
|
|
|
|
|
@Value("${water.paasToken:}") |
|
|
|
public String paasToken; |
|
|
|
@Value("${water.paasId:}") |
|
|
|
public String paasId; |
|
|
|
//网关
|
|
|
|
@Value("${water.gateway.paasToken:}") |
|
|
|
public String gatewayPaasToken; |
|
|
|
@Value("${water.gateway.paasId:}") |
|
|
|
public String gatewayPaasId; |
|
|
|
|
|
|
|
//应用中台
|
|
|
|
@Value("${water.center.paasToken:}") |
|
|
|
public String centerPaasToken; |
|
|
|
@Value("${water.center.paasId:}") |
|
|
|
public String centerPaasId; |
|
|
|
|
|
|
|
//网关
|
|
|
|
@Value("${water.url:}") |
|
|
|
public String url; |
|
|
|
|
|
|
|
//单点登录id
|
|
|
|
@Value("${water.singOnServiceId:}") |
|
|
|
public String singOnServiceId; |
|
|
|
//单点登录密钥
|
|
|
|
@Value("${water.singOnAppsecret:}") |
|
|
|
public String singOnAppsecret; |
|
|
|
@Value("${water.singOnUrl:}") |
|
|
|
public String singOnUrl; |
|
|
|
@Value("${water.logoutUrl:}") |
|
|
|
public String logoutUrl; |
|
|
|
|
|
|
|
@Value("${water.accessTokenUrl:}") |
|
|
|
public String accessTokenUrl; |
|
|
|
|
|
|
|
|
|
|
|
//验证用户登录
|
|
|
|
@Value("${water.userUrl:}") |
|
|
|
public String userUrl; |
|
|
|
@Value("${water.authUserServiceId:}") |
|
|
|
public String authUserServiceId; |
|
|
|
@Value("${water.authUserAppsecret:}") |
|
|
|
public String authUserAppsecret; |
|
|
|
|
|
|
|
@Value("${water.systemCode:}") |
|
|
|
public String systemCode; |
|
|
|
@Value("${water.systemName:}") |
|
|
@ -55,79 +60,61 @@ public class WaterRequestUtil { |
|
|
|
//获取部门信息
|
|
|
|
@Value("${water.orgUrl:}") |
|
|
|
public String orgUrl; |
|
|
|
@Value("${water.orgServiceId:}") |
|
|
|
public String orgServiceId; |
|
|
|
@Value("${water.orgAppsecret:}") |
|
|
|
public String orgAppsecret; |
|
|
|
|
|
|
|
|
|
|
|
//业务角色
|
|
|
|
@Value("${water.roleUrl:}") |
|
|
|
public String roleUrl; |
|
|
|
@Value("${water.roleServiceId:}") |
|
|
|
public String roleServiceId; |
|
|
|
@Value("${water.roleAppsecret:}") |
|
|
|
public String roleAppsecret; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${water.systemUrl:}") |
|
|
|
public String systemUrl; |
|
|
|
@Value("${water.systemServiceId:}") |
|
|
|
public String systemServiceId; |
|
|
|
@Value("${water.systemAppsecret:}") |
|
|
|
public String systemAppsecret; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${water.usersUrl:}") |
|
|
|
public String usersUrl; |
|
|
|
@Value("${water.usersServiceId:}") |
|
|
|
public String usersServiceId; |
|
|
|
@Value("${water.usersAppsecret:}") |
|
|
|
public String usersAppsecret; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${water.resourceUrl:}") |
|
|
|
public String resourceUrl; |
|
|
|
@Value("${water.resourceServiceId:}") |
|
|
|
public String resourceServiceId; |
|
|
|
@Value("${water.resourceAppsecret:}") |
|
|
|
public String resourceAppsecret; |
|
|
|
|
|
|
|
/** |
|
|
|
* 设置 |
|
|
|
* |
|
|
|
* @param httpRequest |
|
|
|
* @param serviceId |
|
|
|
* @param appsecret |
|
|
|
*/ |
|
|
|
private void setHead(HttpRequest httpRequest, String serviceId, String appsecret) { |
|
|
|
private void setHead(HttpRequest httpRequest) { |
|
|
|
String timestamp = String.valueOf(new Date().getTime()); |
|
|
|
String nonce = IdUtil.fastSimpleUUID(); |
|
|
|
String signature = timestamp + paasToken + nonce + timestamp; |
|
|
|
String gatewaySignature = timestamp + gatewayPaasToken + nonce + timestamp; |
|
|
|
String centerSignature = timestamp + centerPaasToken + nonce + timestamp; |
|
|
|
try { |
|
|
|
signature = SHACoder.encodeSHA256Hex(signature).toUpperCase(); |
|
|
|
gatewaySignature = SHACoder.encodeSHA256Hex(gatewaySignature).toUpperCase(); |
|
|
|
centerSignature = SHACoder.encodeSHA256Hex(centerSignature).toUpperCase(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
httpRequest |
|
|
|
.header("x-tsp-paasid", paasId) |
|
|
|
.header("x-tsp-signature", signature) |
|
|
|
.header("x-tif-paasid", gatewayPaasId) |
|
|
|
.header("x-tif-signature", gatewaySignature) |
|
|
|
.header("x-tif-timestamp", timestamp) |
|
|
|
.header("x-tif-nonce", nonce) |
|
|
|
.header("x-tsp-paasid", centerPaasId) |
|
|
|
.header("x-tsp-signature", centerSignature) |
|
|
|
.header("x-tsp-timestamp", timestamp) |
|
|
|
.header("x-tsp-nonce", nonce) |
|
|
|
.header("x-tsp-serviceid", serviceId) |
|
|
|
.header("x-tsp-appsecret", appsecret); |
|
|
|
.header("x-tsp-nonce", nonce); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public HttpRequest createGet(String url, String serviceId, String appsecret) { |
|
|
|
public HttpRequest createGet(String url) { |
|
|
|
HttpRequest httpRequest = HttpRequest.get(url); |
|
|
|
setHead(httpRequest, serviceId, appsecret); |
|
|
|
setHead(httpRequest); |
|
|
|
return httpRequest; |
|
|
|
} |
|
|
|
|
|
|
|
public HttpRequest createPost(String url, String serviceId, String appsecret) { |
|
|
|
public HttpRequest createPost(String url) { |
|
|
|
HttpRequest httpRequest = HttpRequest.post(url); |
|
|
|
setHead(httpRequest, serviceId, appsecret); |
|
|
|
setHead(httpRequest); |
|
|
|
return httpRequest; |
|
|
|
} |
|
|
|
|
|
|
@ -138,7 +125,7 @@ public class WaterRequestUtil { |
|
|
|
*/ |
|
|
|
public WaterResult systemPage() { |
|
|
|
log.info("查询业务系统-----------------"); |
|
|
|
HttpRequest post = createPost(systemUrl, systemServiceId, systemAppsecret); |
|
|
|
HttpRequest post = createPost(systemUrl); |
|
|
|
HashMap<String, String> query = new HashMap<>(); |
|
|
|
query.put("code", systemCode); |
|
|
|
query.put("name", systemName); |
|
|
@ -183,9 +170,9 @@ public class WaterRequestUtil { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public WaterResult signOn(String userId) { |
|
|
|
HttpRequest get = createGet(userUrl, singOnServiceId, singOnAppsecret); |
|
|
|
HttpRequest get = createGet(userUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.header("x-tsp-target", paasId) |
|
|
|
try (HttpResponse response = get.header("x-tsp-target", gatewayPaasId) |
|
|
|
.header("x-tsp-uid-type", "id") |
|
|
|
.header("x-tsp-uid", userId) |
|
|
|
.execute()) { |
|
|
@ -194,6 +181,23 @@ public class WaterRequestUtil { |
|
|
|
return JSONObject.parseObject(body, WaterResult.class); |
|
|
|
} |
|
|
|
|
|
|
|
public WaterResultV2<String> logout(String authorization) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求统一门户用户注销登陆,请求地址为:{}", logoutUrl); |
|
|
|
HttpRequest get = createGet(logoutUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.header("Authorization", authorization) |
|
|
|
.execute()) { |
|
|
|
body = response.body(); |
|
|
|
} |
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求统一门户用户注销登陆,耗时{}毫秒,返回结果为:{}", endTime - startTime, body); |
|
|
|
WaterResultV2<String> waterResult = JSON.parseObject(body, new TypeReference<WaterResultV2<String>>() { |
|
|
|
}); |
|
|
|
isSuccess(waterResult); |
|
|
|
return waterResult; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 验证用户登录 |
|
|
|
* |
|
|
@ -203,20 +207,45 @@ public class WaterRequestUtil { |
|
|
|
public WaterResultV2<WaterUser> authUser(String authorization) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求统一门户用户验证,请求地址为:{}", userUrl); |
|
|
|
HttpRequest get = createGet(userUrl, authUserServiceId, authUserAppsecret); |
|
|
|
HttpRequest get = createGet(userUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.header("Authorization", authorization) |
|
|
|
.execute()) { |
|
|
|
body = response.body(); |
|
|
|
} |
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求统一门户用户验证,耗时{}毫秒,返回结果为:{}", endTime - startTime, body); |
|
|
|
log.info("--------请求统一门户用户验证,耗时{}毫秒", endTime - startTime); |
|
|
|
WaterResultV2<WaterUser> waterResult = JSON.parseObject(body, new TypeReference<WaterResultV2<WaterUser>>() { |
|
|
|
}); |
|
|
|
isSuccess(waterResult); |
|
|
|
return waterResult; |
|
|
|
} |
|
|
|
|
|
|
|
public String getToken(String code) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求统一门户获取token,请求地址为:{}", accessTokenUrl); |
|
|
|
HttpRequest get = createGet(accessTokenUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.header("Authorization", code) |
|
|
|
.execute()) { |
|
|
|
body = response.body(); |
|
|
|
} |
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
log.info("-------请求统一门户获取token,耗时{}毫秒,token:[{}]", endTime - startTime, body); |
|
|
|
WaterResultV2<WaterToken> waterResult = JSON.parseObject(body, new TypeReference<WaterResultV2<WaterToken>>() { |
|
|
|
}); |
|
|
|
isSuccess(waterResult); |
|
|
|
return waterResult.getData().getAccessToken(); |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class WaterToken { |
|
|
|
private String accessToken; |
|
|
|
private String tokenType; |
|
|
|
private String refreshToken; |
|
|
|
private String expiresIn; |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class WaterUser { |
|
|
|
private WaterUserInfo user; |
|
|
@ -236,7 +265,7 @@ public class WaterRequestUtil { |
|
|
|
hashMap.put("page", 1); |
|
|
|
hashMap.put("size", 100); |
|
|
|
hashMap.put("systemCode", systemCode); |
|
|
|
HttpRequest get = createPost(orgUrl, orgServiceId, orgAppsecret); |
|
|
|
HttpRequest get = createPost(orgUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.body(JSONObject.toJSONString(hashMap)) |
|
|
|
.execute()) { |
|
|
@ -263,14 +292,15 @@ public class WaterRequestUtil { |
|
|
|
//计算请求消耗的时间
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求获取门户用户资源信息,请求地址为:{}", resourceUrl); |
|
|
|
HttpRequest get = createPost(resourceUrl + "?systemCode=" + systemCode, resourceServiceId, resourceAppsecret); |
|
|
|
HttpRequest get = createPost(resourceUrl + "?systemCode=" + systemCode); |
|
|
|
get.header("Authorization", authorization); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.execute()) { |
|
|
|
body = response.body(); |
|
|
|
} |
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
log.info("--------请求获取门户用户资源信息,耗时{}毫秒,返回结果为:{}", endTime - startTime, body); |
|
|
|
log.info("--------请求获取门户用户资源信息,耗时{}毫秒", endTime - startTime); |
|
|
|
log.debug("--------请求获取门户用户资源信息,返回结果:{}", body); |
|
|
|
WaterResultV2<List<SingleMenu>> waterResult = JSON.parseObject(body, new TypeReference<WaterResultV2<List<SingleMenu>>>() { |
|
|
|
}); |
|
|
|
isSuccess(waterResult); |
|
|
@ -285,13 +315,13 @@ public class WaterRequestUtil { |
|
|
|
hashMap.put("page", 1); |
|
|
|
hashMap.put("size", 1000); |
|
|
|
hashMap.put("systemCode", systemCode); |
|
|
|
HttpRequest get = createPost(roleUrl, roleServiceId, roleAppsecret); |
|
|
|
HttpRequest get = createPost(roleUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.body(JSONObject.toJSONString(hashMap)) |
|
|
|
.execute()) { |
|
|
|
body = response.body(); |
|
|
|
} |
|
|
|
log.info("--------请求获取门户角色信息,返回结果为:{}", body); |
|
|
|
log.info("--------请求获取门户角色信息"); |
|
|
|
WaterResult waterResult = JSONObject.parseObject(body, WaterResult.class); |
|
|
|
isSuccess(waterResult); |
|
|
|
//{\"total\":1,\"size\":100,\"records\":[{\"area\":\"440000\",\"systemList\":[{\"area\":\"440000\",\"code\":\"sgc-jg\",\"name\":\"水工程应用-水利工程建设管理模块\",\"id\":\"1732648267643097090\"}],\"code\":\"YW00013\",\"level\":\"1d\",\"dataConfig\":\"none\",\"type\":\"BUSINESS\",\"posts\":[],\"users\":[{\"id\":\"20231225000006\"},{\"id\":\"20240119000002\"}],\"name\":\"水利工程应用-水利工程建设管理模块角色\",\"id\":\"20231213000001\",\"category\":\"BUSINESS\",\"businesses\":[{\"parent\":\"1762458920822599682\",\"businessCode\":\"YWSLGCJSGL0008\",\"parentName\":\"水利工程建设管理\",\"businessName\":\"水利工程建设管理\",\"description\":\"\",\"id\":\"1705128209926942721\",\"delFlag\":0}],\"status\":\"1\"}],\"page\":1}
|
|
|
@ -305,13 +335,13 @@ public class WaterRequestUtil { |
|
|
|
hashMap.put("page", 1); |
|
|
|
hashMap.put("size", 100); |
|
|
|
hashMap.put("systemCode", systemCode); |
|
|
|
HttpRequest get = createPost(usersUrl, usersServiceId, usersAppsecret); |
|
|
|
HttpRequest get = createPost(usersUrl); |
|
|
|
String body; |
|
|
|
try (HttpResponse response = get.body(JSONObject.toJSONString(hashMap)) |
|
|
|
.execute()) { |
|
|
|
body = response.body(); |
|
|
|
} |
|
|
|
log.info("--------请求获取门户用户信息,返回结果为:{}", body); |
|
|
|
log.info("--------请求获取门户用户信息"); |
|
|
|
WaterResult waterResult = JSONObject.parseObject(body, WaterResult.class); |
|
|
|
isSuccess(waterResult); |
|
|
|
return waterResult; |
|
|
|