|
@@ -2,6 +2,8 @@ package com.yizhu.supervise.common.util;
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import openapi.Client;
|
|
import openapi.Client;
|
|
|
import openapi.Response;
|
|
import openapi.Response;
|
|
@@ -22,45 +24,44 @@ public class PostUtil {
|
|
|
|
|
|
|
|
public PostUtil() {
|
|
public PostUtil() {
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public static HisResponseTO post(String method,String jsonStr) {
|
|
|
|
|
|
|
+ public static HisResponseTO post(String method, String jsonStr) {
|
|
|
HisResponseTO<?> hisResponse = new HisResponseTO();
|
|
HisResponseTO<?> hisResponse = new HisResponseTO();
|
|
|
- // Client client = new Client(apiUrl, appKey, appSecret, encodingAesKey);
|
|
|
|
|
-// List bodyList = new ArrayList();
|
|
|
|
|
-// bodyList.add(param);
|
|
|
|
|
- // Request request = new Request(serviceId, method, bodyList);
|
|
|
|
|
- // Response response = null;
|
|
|
|
|
HttpRequest request = HttpRequest.post(apiUrl);
|
|
HttpRequest request = HttpRequest.post(apiUrl);
|
|
|
- // 设置请求头
|
|
|
|
|
- request.header("Content-Type", "application/json"); // 设置Content-Type为JSON格式
|
|
|
|
|
- request.header("Authorization", "Bearer your_access_token_here"); // 示例:设置Authorization头
|
|
|
|
|
- request.header("apiUrl",apiUrl);
|
|
|
|
|
- request.header("appKey", appKey);
|
|
|
|
|
- request.header("appSecret", appSecret);
|
|
|
|
|
- request.header("X-Ca-Key", appKey);
|
|
|
|
|
- request.header("X-Ca-Nonce", UUID.randomUUID().toString());
|
|
|
|
|
- request.header("X-Ca-Timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
|
|
- log.info("请求方法:"+method+"request参数" + request);
|
|
|
|
|
- log.info("请求方法:"+method+"实际请求参数" +jsonStr );
|
|
|
|
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
|
|
+ String ts = String.valueOf(System.currentTimeMillis());
|
|
|
String encryptStr = SM4Utils.encryptNationalSerAlgorithmCBC(jsonStr, appSecret);
|
|
String encryptStr = SM4Utils.encryptNationalSerAlgorithmCBC(jsonStr, appSecret);
|
|
|
String contentMd5 = SM3Util.encode(encryptStr);
|
|
String contentMd5 = SM3Util.encode(encryptStr);
|
|
|
- request.header("X-Content-MD5", contentMd5);
|
|
|
|
|
- Map<String,String> headers = new HashMap();
|
|
|
|
|
|
|
+ //签名
|
|
|
|
|
+ Map<String, String> headers = new HashMap();
|
|
|
headers.put("X-Ca-Key", appKey);
|
|
headers.put("X-Ca-Key", appKey);
|
|
|
|
|
+ headers.put("X-Ca-Nonce", uuid);
|
|
|
|
|
+ headers.put("X-Ca-Timestamp", ts);
|
|
|
headers.put("X-Service-Id", serviceId);
|
|
headers.put("X-Service-Id", serviceId);
|
|
|
headers.put("X-Service-Method", method);
|
|
headers.put("X-Service-Method", method);
|
|
|
- String signature = SignUtil.signWithSm3(headers);
|
|
|
|
|
|
|
+ headers.put("X-Content-MD5", contentMd5);
|
|
|
|
|
+ List<String> siginlist = Arrays.asList("X-Service-Id", "X-Service-Method", "X-Ca-Key", "X-Ca-Nonce", "X-Ca-Timestamp", "X-Content-MD5");
|
|
|
|
|
+ String sbStr = SignUtil.buildHeaders(headers, siginlist);
|
|
|
|
|
+ String signature = SM3Util.encode(sbStr);
|
|
|
|
|
+ // 设置请求头
|
|
|
|
|
+ request.header("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
|
+ request.header("X-Ca-Key", appKey);
|
|
|
request.header("X-Ca-Signature", signature);
|
|
request.header("X-Ca-Signature", signature);
|
|
|
- request.header("stringBody",encryptStr);
|
|
|
|
|
|
|
+ request.header("X-Content-MD5", contentMd5);
|
|
|
|
|
+ request.header("X-Service-Method", method);
|
|
|
|
|
+ request.header("X-Service-Id", serviceId);
|
|
|
|
|
+ request.header("X-Ca-Nonce", uuid);
|
|
|
|
|
+ request.header("X-Ca-Timestamp", ts);
|
|
|
|
|
+ request.header("X-Ca-Signature-Headers", "X-Service-Id,X-Service-Method,X-Ca-Key,X-Ca-Nonce,X-Ca-Timestamp,X-Content-MD5");
|
|
|
|
|
+ request.header("signature", signature);
|
|
|
// 设置请求体(JSON格式)
|
|
// 设置请求体(JSON格式)
|
|
|
- request.body(jsonStr);
|
|
|
|
|
|
|
+ request.body(encryptStr);
|
|
|
// 发送请求并获取响应
|
|
// 发送请求并获取响应
|
|
|
try {
|
|
try {
|
|
|
HttpResponse response = request.execute();
|
|
HttpResponse response = request.execute();
|
|
|
log.debug("监管平台返回结果:" + JSONUtils.toString(response));
|
|
log.debug("监管平台返回结果:" + JSONUtils.toString(response));
|
|
|
String body = response.body();
|
|
String body = response.body();
|
|
|
if (body != null) {
|
|
if (body != null) {
|
|
|
- hisResponse = (HisResponseTO)JSONUtils.parse(body, HisResponseTO.class);
|
|
|
|
|
|
|
+ hisResponse = (HisResponseTO) JSONUtils.parse(body, HisResponseTO.class);
|
|
|
hisResponse.setMsg(hisResponse.getBody().getMsg());
|
|
hisResponse.setMsg(hisResponse.getBody().getMsg());
|
|
|
} else {
|
|
} else {
|
|
|
hisResponse.setMsgCode("-1");
|
|
hisResponse.setMsgCode("-1");
|
|
@@ -89,7 +90,7 @@ public class PostUtil {
|
|
|
String body = response.getBody();
|
|
String body = response.getBody();
|
|
|
log.debug("body:" + body);
|
|
log.debug("body:" + body);
|
|
|
if (body != null) {
|
|
if (body != null) {
|
|
|
- fileResponse = (FileResponseTO)JSONUtils.parse(body, fileResponse.getClass());
|
|
|
|
|
|
|
+ fileResponse = (FileResponseTO) JSONUtils.parse(body, fileResponse.getClass());
|
|
|
fileResponse.setMsg("上传成功");
|
|
fileResponse.setMsg("上传成功");
|
|
|
} else {
|
|
} else {
|
|
|
fileResponse.setMsgCode("-1");
|
|
fileResponse.setMsgCode("-1");
|