From 8172572f01c0baa527085243e010afa4bec5efcc Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期五, 31 十月 2025 17:33:38 +0800
Subject: [PATCH] 陕西2025版接口调整3-新增接口页面
---
src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java | 109 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 91 insertions(+), 18 deletions(-)
diff --git a/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java b/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java
index 8476f64..3b14e06 100644
--- a/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java
+++ b/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java
@@ -1,33 +1,36 @@
package com.fzzy.push.whhpjl;
import com.alibaba.fastjson.JSON;
-import com.fzzy.api.entity.ApiConfs;
+import com.fzzy.push.whhpjl.dto.WhjlPullReqDto;
+import com.fzzy.push.whhpjl.dto.WhjlPullRespDto;
import com.fzzy.push.whhpjl.dto.WhjlReqDto;
import com.fzzy.push.whhpjl.dto.WhjlRespDto;
import lombok.extern.slf4j.Slf4j;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
+import org.springframework.stereotype.Component;
+
+import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* 姝︽眽鍐涚伯鐪佸钩鍙�-涓婁紶鏁版嵁鏈嶅姟绫�
+ *
* @author czt
- * @date 2023/08/04
+ * @date 2023/10/23
*/
@Slf4j
+@Component
public class Whjl2023HttpClientUtil {
/**
- * post formData
+ * 鏁版嵁涓婃姤post璇锋眰
+ *
* @param url
+ * @param reqData
* @return
- * @throws Exception
*/
- @SuppressWarnings("resource")
- public static WhjlRespDto postPushData(String url, WhjlReqDto reqData , ApiConfs apiConfs) throws Exception {
- log.info("---------鎺ュ彛璇锋眰鍦板潃锛�" +url+ "----------鍙傛暟锛�" + reqData.toString() +"---------");
+ public WhjlRespDto postPushData(String url, WhjlReqDto reqData) throws Exception {
+ log.info("---------鎺ュ彛璇锋眰鍦板潃锛�" + url + "----------鍙傛暟锛�" + JSON.toJSONString(reqData) + "---------");
BufferedReader in = null;
URL urls = new URL(url);
HttpURLConnection connection = null;
@@ -35,7 +38,6 @@
String rs = "";
WhjlRespDto responseDto;
try {
-
connection = (HttpURLConnection) urls.openConnection();
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
connection.setDoOutput(true);
@@ -48,7 +50,8 @@
connection.setRequestMethod("POST");
outputStream = connection.getOutputStream();
- outputStream.write(reqData.toString().getBytes("UTF-8"));
+
+ outputStream.write(JSON.toJSONString(reqData).getBytes("UTF-8"));
try {
connection.connect();
if (connection.getResponseCode() == 200) {
@@ -64,18 +67,88 @@
} catch (Exception e) {
System.out.println("鍙戠敓寮傚父");
- log.error(e.getMessage(),e);
+ log.error(e.getMessage(), e);
rs = null;
- return new WhjlRespDto(99,e.getMessage());
+ return new WhjlRespDto(99, e.getMessage());
}
- log.info("---------鎺ュ彛杩斿洖锛�" + rs +"---------");
- responseDto = JSON.parseObject(rs,WhjlRespDto.class);
- if(responseDto == null ) return new WhjlRespDto(99,"鎺ュ彛璇锋眰鍙戠敓鏈煡閿欒");
+ log.info("---------鎺ュ彛杩斿洖锛�" + rs + "---------");
+ responseDto = JSON.parseObject(rs, WhjlRespDto.class);
+ if (responseDto == null) return new WhjlRespDto(99, "鎺ュ彛璇锋眰鍙戠敓鏈煡閿欒");
return responseDto;
} finally {
try {
outputStream.close();
- if (in != null){
+ if (in != null) {
+ in.close();
+ }
+ } catch (Exception e) {
+ }
+ outputStream = null;
+ if (connection != null)
+ connection.disconnect();
+ connection = null;
+ }
+ }
+
+ /**
+ * 鏁版嵁涓婃姤post璇锋眰
+ *
+ * @param url
+ * @param reqData
+ * @return
+ */
+ public WhjlPullRespDto postPullData(String url, WhjlPullReqDto reqData) throws Exception {
+ log.info("---------鎺ュ彛璇锋眰鍦板潃锛�" + url + "----------鍙傛暟锛�" + JSON.toJSONString(reqData) + "---------");
+ BufferedReader in = null;
+ URL urls = new URL(url);
+ HttpURLConnection connection = null;
+ OutputStream outputStream = null;
+ String rs = "";
+ WhjlPullRespDto responseDto;
+ try {
+ connection = (HttpURLConnection) urls.openConnection();
+ connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");
+ connection.setRequestProperty("Accept", "*/*");
+ connection.setRequestProperty("Range", "bytes=" + "");
+ connection.setConnectTimeout(20000);
+ connection.setReadTimeout(30000);
+ connection.setRequestMethod("POST");
+
+ outputStream = connection.getOutputStream();
+
+ outputStream.write(JSON.toJSONString(reqData).getBytes("UTF-8"));
+ try {
+ connection.connect();
+ if (connection.getResponseCode() == 200) {
+ in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
+ String line = "";
+ while ((line = in.readLine()) != null) {
+ rs += line;
+ }
+ } else {
+ log.error("http鐘舵�侊細" + connection.getResponseCode());
+ log.error("http娑堟伅锛�" + connection.getResponseMessage());
+ }
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ rs = null;
+ return new WhjlPullRespDto(99, null);
+ }
+ log.info("---------鎺ュ彛杩斿洖锛�" + rs + "---------");
+ responseDto = JSON.parseObject(rs, WhjlPullRespDto.class);
+
+ if (responseDto == null) {
+ return new WhjlPullRespDto(99, "鎺ュ彛璇锋眰鍙戠敓鏈煡閿欒");
+ }
+ return responseDto;
+ } finally {
+ try {
+ outputStream.close();
+ if (in != null) {
in.close();
}
} catch (Exception e) {
--
Gitblit v1.9.3