From 4f9401588905d9290fb9793f15f209767f2b08e1 Mon Sep 17 00:00:00 2001 From: JIAL <2287346125@qq.com> Date: Wed, 17 Jan 2024 16:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E7=85=A4=E6=8A=A5=E4=BB=B7=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/JN/utils/HttpHelper.java | 59 ++++++- .../resources/static/paymethod/css/index.css | 0 .../resources/static/paymethod/js/index.js | 0 .../static/zmquotation/css/index.css | 12 ++ .../resources/static/zmquotation/js/index.js | 0 .../resources/templates/bizquery/index.html | 1 + .../resources/templates/paymethod/index.html | 54 ++++++ .../templates/zmquotation/index.html | 158 ++++++++++++++++++ 8 files changed, 281 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/static/paymethod/css/index.css create mode 100644 src/main/resources/static/paymethod/js/index.js create mode 100644 src/main/resources/static/zmquotation/css/index.css create mode 100644 src/main/resources/static/zmquotation/js/index.js create mode 100644 src/main/resources/templates/paymethod/index.html create mode 100644 src/main/resources/templates/zmquotation/index.html diff --git a/src/main/java/com/JN/utils/HttpHelper.java b/src/main/java/com/JN/utils/HttpHelper.java index ad80154..254b186 100644 --- a/src/main/java/com/JN/utils/HttpHelper.java +++ b/src/main/java/com/JN/utils/HttpHelper.java @@ -1,10 +1,9 @@ package com.JN.utils; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; +import org.apache.http.*; import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; @@ -15,6 +14,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import javax.net.ssl.SSLContext; @@ -26,6 +26,8 @@ import java.net.URLEncoder; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -87,6 +89,57 @@ public class HttpHelper { return null; } + /** + * @title httpPost + * @description 支持传入自己的head头的post请求 + * @author JIAL + * @param: url + * @param: params + * @param: headers + * @updateTime 2024/1/17 10:34 + * @return: java.lang.String + */ + public static String httpPost(String url, Map params, Map headers) throws Exception { + HttpPost post = new HttpPost(url); + + // Add custom headers + if (headers != null && !headers.isEmpty()) { + for (Map.Entry entry : headers.entrySet()) { + post.addHeader(entry.getKey(), entry.getValue()); + } + } + + // Set request body if params is not null + if (params != null && !params.isEmpty()) { + List formParams = new ArrayList<>(); + for (Map.Entry entry : params.entrySet()) { + formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); + } + UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formParams, Consts.UTF_8); + post.setEntity(urlEncodedFormEntity); + } + + HttpResponse httpresponse = null; + CloseableHttpClient httpClient = null; + + try { + httpClient = declareHttpClientSSL(url); + httpresponse = httpClient.execute(post); + HttpEntity httpEntity = httpresponse.getEntity(); + String result = EntityUtils.toString(httpEntity, REQ_ENCODEING_UTF8); + return result; + } catch (ClientProtocolException e) { + System.out.println(String.format("http请求失败,uri{%s},exception{%s}", new Object[] { url, e })); + } catch (IOException e) { + System.out.println(String.format("IO Exception,uri{%s},exception{%s}", new Object[] { url, e })); + } finally { + if (null != httpClient) + httpClient.close(); + } + + return null; + } + private static CloseableHttpClient declareHttpClientSSL(String url) { if (url.startsWith("https://")) { return sslClient(); diff --git a/src/main/resources/static/paymethod/css/index.css b/src/main/resources/static/paymethod/css/index.css new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/static/paymethod/js/index.js b/src/main/resources/static/paymethod/js/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/static/zmquotation/css/index.css b/src/main/resources/static/zmquotation/css/index.css new file mode 100644 index 0000000..824b62d --- /dev/null +++ b/src/main/resources/static/zmquotation/css/index.css @@ -0,0 +1,12 @@ +.container { + display: flex; + height: 100vh; +} + +.center-container { + text-align: center; + margin: auto; + width: 80%; + height: 100vh; + +} \ No newline at end of file diff --git a/src/main/resources/static/zmquotation/js/index.js b/src/main/resources/static/zmquotation/js/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/templates/bizquery/index.html b/src/main/resources/templates/bizquery/index.html index c8c6039..049f6f9 100644 --- a/src/main/resources/templates/bizquery/index.html +++ b/src/main/resources/templates/bizquery/index.html @@ -71,6 +71,7 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/zmquotation/index.html b/src/main/resources/templates/zmquotation/index.html new file mode 100644 index 0000000..69c9299 --- /dev/null +++ b/src/main/resources/templates/zmquotation/index.html @@ -0,0 +1,158 @@ + + + + + 报价 + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ + + + + + + + + + + + + \ No newline at end of file