|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
// import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
+import com.rtrh.core.vo.ListMessage;
|
|
|
import com.rtrh.core.vo.Message;
|
|
|
import com.rtrh.projects.modules.projects.po.SubPreNew;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -134,6 +135,52 @@ public class HttpClientUtil {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public static Object sendPostRequestPage(String url, Object jsonBody, Map<String, String> headers) {
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
+ // 创建 POST 请求
|
|
|
+ HttpPost request = new HttpPost(url);
|
|
|
+
|
|
|
+ // 设置请求头
|
|
|
+ if (headers != null) {
|
|
|
+ for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
+ request.addHeader(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ // 注册Java 8日期时间模块
|
|
|
+ // objectMapper.registerModule(new JavaTimeModule());
|
|
|
+ // 禁用时间戳格式,默认改为ISO-8601格式
|
|
|
+ // objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
+ // 自定义日期格式为数据库兼容格式
|
|
|
+ // objectMapper.setDateFormat(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String jsonBodyStr = objectMapper.writeValueAsString(jsonBody);
|
|
|
+
|
|
|
+ // 设置请求体
|
|
|
+ if (!jsonBodyStr.isEmpty()) {
|
|
|
+ StringEntity entity = new StringEntity(jsonBodyStr, StandardCharsets.UTF_8);
|
|
|
+ entity.setContentType("application/json");
|
|
|
+ request.setEntity(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送请求并获取响应
|
|
|
+ try (CloseableHttpResponse response = httpClient.execute(request)) {
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
+ if (entity != null) {
|
|
|
+ String responseBody = EntityUtils.toString(entity, StandardCharsets.UTF_8);
|
|
|
+ if (!responseBody.isEmpty()){
|
|
|
+ return JSON.parseObject(responseBody, CommonMessage.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public static Object sendPostRequest(String url, Object jsonBody) {
|
|
|
return sendPostRequest(url, jsonBody, null);
|
|
|
}
|
|
@@ -143,4 +190,14 @@ public class HttpClientUtil {
|
|
|
String inUrl = resourceBundle.getString("app.fgw.in.url");
|
|
|
return sendPostRequest(inUrl + s, jsonBody);
|
|
|
}
|
|
|
+
|
|
|
+ public static Object fgwPostRequest(String s, Object jsonBody,String type) {
|
|
|
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("config");
|
|
|
+ String inUrl = resourceBundle.getString("app.fgw.in.url");
|
|
|
+ if (ResponseRows.COMMONMESSAGE.getType().equals(type)){
|
|
|
+ return sendPostRequestPage(inUrl + s, jsonBody,null);
|
|
|
+ }else{
|
|
|
+ return sendPostRequest(inUrl + s, jsonBody);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|