|
|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.server.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
import cn.iocoder.yudao.module.system.oa.E9ApiTokenUtil;
|
|
|
@@ -43,74 +44,79 @@ public class PortalOaFlow {
|
|
|
@Value("${oa.gettoken}")
|
|
|
private String tokenUrl;
|
|
|
|
|
|
- private static String spk = "";
|
|
|
- private static String secret = "";
|
|
|
+ private static final Map<String,String> SYSTEM_CACHE = new HashMap <>();
|
|
|
+
|
|
|
@Autowired
|
|
|
private OaNoticeMapper oaNoticeMapper;
|
|
|
|
|
|
|
|
|
+ // ==================== 新增:每次使用【全新的、无Cookie】的RestTemplate ====================
|
|
|
+ private RestTemplate getNewRestTemplateWithoutCookie() {
|
|
|
+// return new RestTemplate(new HttpComponentsClientHttpRequestFactory(
|
|
|
+// HttpClients.custom()
|
|
|
+// .disableCookieManagement() // 彻底禁用Cookie,不保存、不携带
|
|
|
+// .setRedirectStrategy(new LaxRedirectStrategy())
|
|
|
+// .build()
|
|
|
+// ));
|
|
|
+ RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(
|
|
|
+ HttpClients.custom()
|
|
|
+ .disableCookieManagement() // 彻底禁用Cookie
|
|
|
+ .setRedirectStrategy(new LaxRedirectStrategy())
|
|
|
+ .build()
|
|
|
+ ));
|
|
|
+ // 关键:强制响应编码为 UTF-8
|
|
|
+ restTemplate.getMessageConverters().stream()
|
|
|
+ .filter(converter -> converter instanceof org.springframework.http.converter.StringHttpMessageConverter)
|
|
|
+ .forEach(converter -> ((org.springframework.http.converter.StringHttpMessageConverter) converter)
|
|
|
+ .setDefaultCharset(java.nio.charset.StandardCharsets.UTF_8));
|
|
|
+ return restTemplate;
|
|
|
+ }
|
|
|
+
|
|
|
public void register() throws Exception{
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.add("appid", appid);
|
|
|
headers.add("cpk", cpk);
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
- RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
-
|
|
|
- String result = restTemplate.postForObject(registerUrl, requestEntity, String.class);
|
|
|
+ RestTemplate noCookieRestTemplate = getNewRestTemplateWithoutCookie();
|
|
|
+ String result = noCookieRestTemplate.postForObject(registerUrl, requestEntity, String.class);
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
- spk = String.valueOf(jsonObject.get("spk"));
|
|
|
- secret = String.valueOf(jsonObject.get("secret"));
|
|
|
+ //ECOLOGY返回的系统公钥
|
|
|
+ SYSTEM_CACHE.put("SERVER_PUBLIC_KEY", String.valueOf(jsonObject.get("spk")));
|
|
|
+ //ECOLOGY返回的系统密钥
|
|
|
+ SYSTEM_CACHE.put("SERVER_SECRET",String.valueOf(jsonObject.get("secret")));
|
|
|
System.out.println("result register:" + result);
|
|
|
|
|
|
}
|
|
|
|
|
|
public String getToken() throws Exception{
|
|
|
-// if (StringUtils.isBlank(spk) || StringUtils.isBlank(secret)) {
|
|
|
+ String secret = SYSTEM_CACHE.get("SERVER_SECRET");
|
|
|
+ String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
|
|
|
+ // 如果为空,说明还未进行注册,调用注册接口进行注册认证与数据更新
|
|
|
+ if (Objects.isNull(secret)||Objects.isNull(spk)){
|
|
|
register();
|
|
|
-// }
|
|
|
+ // 重新获取最新ECOLOGY系统公钥和Secret信息
|
|
|
+ secret = SYSTEM_CACHE.get("SERVER_SECRET");
|
|
|
+ spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
|
|
|
+ }
|
|
|
String secretEn = E9ApiTokenUtil.encryptString(spk, secret);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.add("appid", appid);
|
|
|
headers.add("secret", secretEn);
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
- RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+ RestTemplate noCookieRestTemplate = getNewRestTemplateWithoutCookie();
|
|
|
|
|
|
- String result = restTemplate.postForObject(tokenUrl, requestEntity, String.class);
|
|
|
+ String result = noCookieRestTemplate.postForObject(tokenUrl, requestEntity, String.class);
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
String token = String.valueOf(jsonObject.get("token"));
|
|
|
System.out.println("result token:" + result);
|
|
|
return token;
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
-
|
|
|
- // ==================== 新增:每次使用【全新的、无Cookie】的RestTemplate ====================
|
|
|
- private RestTemplate getNewRestTemplateWithoutCookie() {
|
|
|
-// return new RestTemplate(new HttpComponentsClientHttpRequestFactory(
|
|
|
-// HttpClients.custom()
|
|
|
-// .disableCookieManagement() // 彻底禁用Cookie,不保存、不携带
|
|
|
-// .setRedirectStrategy(new LaxRedirectStrategy())
|
|
|
-// .build()
|
|
|
-// ));
|
|
|
- RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(
|
|
|
- HttpClients.custom()
|
|
|
- .disableCookieManagement() // 彻底禁用Cookie
|
|
|
- .setRedirectStrategy(new LaxRedirectStrategy())
|
|
|
- .build()
|
|
|
- ));
|
|
|
- // 关键:强制响应编码为 UTF-8
|
|
|
- restTemplate.getMessageConverters().stream()
|
|
|
- .filter(converter -> converter instanceof org.springframework.http.converter.StringHttpMessageConverter)
|
|
|
- .forEach(converter -> ((org.springframework.http.converter.StringHttpMessageConverter) converter)
|
|
|
- .setDefaultCharset(java.nio.charset.StandardCharsets.UTF_8));
|
|
|
- return restTemplate;
|
|
|
- }
|
|
|
-
|
|
|
public ImmutableMap<String, Object> getOaTodo(String oaId, Integer pageNo ,Integer pageSize) throws Exception {
|
|
|
String token = getToken();
|
|
|
+ String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
|
|
|
|
|
|
HttpHeaders headersOut = new HttpHeaders();
|
|
|
headersOut.add("token", token);
|
|
|
@@ -139,7 +145,7 @@ public class PortalOaFlow {
|
|
|
//已办数量
|
|
|
String done = noCookieRestTemplate.postForObject("https://yfoa.keruioil.com/api/workflow/paService/getHandledWorkflowRequestCount", requestEntityOut, String.class);
|
|
|
|
|
|
- map.put("root", ImmutableMap.of("craterid", oaId));
|
|
|
+ map.put("root", ImmutableMap.of("craterid", oaId,"isdebug", "true"));
|
|
|
params.put("conditions", map);
|
|
|
// params.put("pageSize", pageSize);
|
|
|
// params.put("pageNo", pageNo);
|
|
|
@@ -165,7 +171,7 @@ public class PortalOaFlow {
|
|
|
|
|
|
public List getOaNotice(String oaId, OaNoticeDO oaNoticeDO, String workcode) throws Exception {
|
|
|
String token = getToken();
|
|
|
-
|
|
|
+ String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY");
|
|
|
HttpHeaders headersOut = new HttpHeaders();
|
|
|
headersOut.add("token", token);
|
|
|
headersOut.add("appid", appid);
|