|
@@ -1,22 +1,34 @@
|
|
|
package com.siwei.apply.utils;
|
|
package com.siwei.apply.utils;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.siwei.apply.domain.NodeAttachment;
|
|
import com.siwei.apply.domain.NodeAttachment;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
+import static com.siwei.common.core.utils.RsaUtil.decryptByPrivateKey;
|
|
|
|
|
+import static com.siwei.common.core.utils.RsaUtil.encryptByPublicKey;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 服务类工具
|
|
* 服务类工具
|
|
|
*/
|
|
*/
|
|
|
public class ServiceUtil {
|
|
public class ServiceUtil {
|
|
|
-
|
|
|
|
|
private static final long EXPIRY_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
|
|
private static final long EXPIRY_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
|
|
|
private static final String SECRET_KEY = "siwei"; // Secret key for signature
|
|
private static final String SECRET_KEY = "siwei"; // Secret key for signature
|
|
|
private static final String TIME_KEY = "?time="; // time
|
|
private static final String TIME_KEY = "?time="; // time
|
|
|
private static final String DOMAIN = "http://192.168.60.219/prod-api/apply"; // doman
|
|
private static final String DOMAIN = "http://192.168.60.219/prod-api/apply"; // doman
|
|
|
|
|
+ private static final String THIRD_API_PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAI1O4yrVG7/Eg1M0G1f/bRDV1ABUpRSSBxvfAxh4dL2W7ApMCz+Krs3xushcQzTOsVuxPGAjgXB906iUEyUJoefnixiKthYV56kzVeXtIw+J1Tbnc1ujTvhWNUkaJYxLCTw+8Z/kASL0XNKImSgzNsB6YQ/ZlYa0kBUEFrs0RBStAgMBAAECgYAxOrqJwZTZSm02H4EnNyWYJ+aj9tlMQVOYsikx7UU+h8XUEIoaqQYdWYnpI7uGOjwv5Z9THwuJVUzX/j5tON3el/eMeOCdnRaSzprY90ceKPr13TezIy6PvyZbH0JRua7Qwu+Klh8GL/6s5lZfs3VAM3qImSE+O86SlL+GbdLiAQJBANF5zA/a8KGkm7yremftARqvfOTy+PQxXXXE7tbWqE5P/t4/feZI45OKoNNId1EGFs4nIS/G+p99AEO80sQNnVUCQQCssUV6h6ddEp3SAVfDSB1Ss0i35kd5GRZT5v+atA9ETAyP37o8ZqnFln1blG95Afp7qy0NcP+ltGCZZftOBdn5AkAv+SXbx7duPYWRKvBolqW3F9ORl3eebSPLUeOk/hojfTyQZ5gMwkqkQo5cdO8mdi+I3PtDtt0042rJGJhoX/nVAkEAqJekGdxHgzDCjJws/wPvRKatDoQtMMdSKfUxgunYobeQ6ADmQ0OC6NhjZ73BGiTZUlSp9h5kJnSzfe626dQCmQJBAM7heHLxlzNY65ziyTp5RkShxmp/yEi6d4cFzZ5/UyFDWW/vphrbKezsKK5rpbFmQjNhFcAk61+O+70J0V8Yoh8="; // doman
|
|
|
|
|
+ private static final String THIRD_API_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCoVP+LpSUfIL6r2nvN/TYOmBGGJT/6vB2Us8Qhk/4ZhmPIo1PE/8ovpdFcNXaYGbtd6/32dkotxFgMxiLdHFHii3EaBL6PXUYHiZWnIRz79gmttHQGDXhOVRGbldNHOZXWBBrek8/GWDk6Z5jgUFhi3K5853JU5fIc8w5TGyVs7wIDAQAB";
|
|
|
|
|
+ private static final String THIRD_API_BASE_URL = "http://10.224.1.228:10001/dsp-register-server/dspRegisterService/proxyService/proxyThirdPlatformService";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(ServiceUtil.class);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取指定目录下的子children list
|
|
* 获取指定目录下的子children list
|
|
@@ -85,10 +97,10 @@ public class ServiceUtil {
|
|
|
List<Map<String, String>> list = (List<Map<String, String>>) childMap.get("children");
|
|
List<Map<String, String>> list = (List<Map<String, String>>) childMap.get("children");
|
|
|
for (Map<String, String> map : list) {
|
|
for (Map<String, String> map : list) {
|
|
|
String fileName = map.get("name");
|
|
String fileName = map.get("name");
|
|
|
- if(StringUtils.isNotBlank(fileName)){
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(fileName)) {
|
|
|
String SignedUrl = attachmentId + "/" + childName + "/" + fileName;
|
|
String SignedUrl = attachmentId + "/" + childName + "/" + fileName;
|
|
|
String signedRes = fileUrlSigned(SignedUrl, timestamp);
|
|
String signedRes = fileUrlSigned(SignedUrl, timestamp);
|
|
|
- String path = DOMAIN+ "/public/offer/download/"+signedRes+"/"+timestamp+"/"+attachmentId+"/"+childName+"/"+fileName;
|
|
|
|
|
|
|
+ String path = DOMAIN + "/public/offer/download/" + signedRes + "/" + timestamp + "/" + attachmentId + "/" + childName + "/" + fileName;
|
|
|
map.put("path", path);
|
|
map.put("path", path);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -98,8 +110,6 @@ public class ServiceUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
// Validate the URL by checking its timestamp and signature
|
|
// Validate the URL by checking its timestamp and signature
|
|
|
public static boolean isUrlValid222(String url, long originalTimestamp) {
|
|
public static boolean isUrlValid222(String url, long originalTimestamp) {
|
|
|
try {
|
|
try {
|
|
@@ -175,4 +185,57 @@ public class ServiceUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 使用HttpClient 获取远程加解密数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getRemoteDataByHttpClient(String queryMethod, Map<String, Object> paramMap) throws Exception {
|
|
|
|
|
+ // 1. 公钥私钥
|
|
|
|
|
+ String privateKey = THIRD_API_PRIVATE_KEY;
|
|
|
|
|
+ String publicKey = THIRD_API_PUBLIC_KEY;
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 三方提供其公钥(这里用我方公钥模拟三方公钥,联调时替换为真实三方公钥)
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ String time = sdf.format(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 组装业务数据
|
|
|
|
|
+ Map<String, Object> dataMap = new HashMap<>(4);
|
|
|
|
|
+ dataMap.putAll(paramMap);
|
|
|
|
|
+// dataMap.put("ywbh", "");
|
|
|
|
|
+// dataMap.put("bdcdyh", "360122011006GB00318F00010001");
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 对象转 JSON -> 公钥加密 -> URLEncode
|
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
+ String json = mapper.writeValueAsString(dataMap);
|
|
|
|
|
+ logger.info("入参:{} ", json);
|
|
|
|
|
+ String encrypted = encryptByPublicKey(publicKey, json);
|
|
|
|
|
+ //System.out.println("密文: " + encrypted);
|
|
|
|
|
+ logger.info("密文:{} ", encrypted);
|
|
|
|
|
+ String payload = encrypted;
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 设置header参数(含 M方法参数 x-method)
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>(16);
|
|
|
|
|
+ headers.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
|
|
+ headers.put("Accept", "application/json");
|
|
|
|
|
+ headers.put("x-area-code", "360100");
|
|
|
|
|
+ headers.put("x-industry-code", "FC");
|
|
|
|
|
+ headers.put("x-method", queryMethod);
|
|
|
|
|
+ headers.put("x-sender-id", "YMGD20260709");
|
|
|
|
|
+ headers.put("x-version", "1.0");
|
|
|
|
|
+ headers.put("x-timestamp", time);
|
|
|
|
|
+ headers.put("x-format", "json");
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 使用HttpClientUtil 发起远程POST请求
|
|
|
|
|
+ String resp = HttpClientUtil.doPostJson(THIRD_API_BASE_URL, payload, headers);
|
|
|
|
|
+ //System.out.println("响应原文: " + resp);
|
|
|
|
|
+ logger.info("响应原文:{} ", resp);
|
|
|
|
|
+ // 8. 用我方私钥解密响应密文
|
|
|
|
|
+ String plain = decryptByPrivateKey(privateKey, resp);
|
|
|
|
|
+ //System.out.println("响应解密明文: " + plain);
|
|
|
|
|
+ logger.info("响应解密明文:{} ", plain);
|
|
|
|
|
+ return plain;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|