Ver código fonte

修改了 后勤 数据同步接口 的参数传递

zhanghao 2 meses atrás
pai
commit
614f526490

+ 61 - 0
project-common/src/main/java/com/project/common/utils/http/HttpUtils.java

@@ -1,5 +1,6 @@
 package com.project.common.utils.http;
 
+import com.alibaba.fastjson2.JSON;
 import com.project.common.constant.Constants;
 import com.project.common.exception.ServiceException;
 import com.project.common.utils.StringUtils;
@@ -14,6 +15,7 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
 import java.security.cert.X509Certificate;
+import java.util.Map;
 
 /**
  * 通用http发送方法
@@ -219,6 +221,65 @@ public class HttpUtils {
      * 向指定 URL 发送POST方法的请求
      *
      * @param url   发送请求的 URL
+     * @param map 请求参数,请求参数应该是 requestBody 的形式。
+     * @return 所代表远程资源的响应结果
+     */
+    public static String sendJsonPost(String url, Map<String, Object> map) {
+        String param = JSON.toJSONString(map);
+        PrintWriter out = null;
+        BufferedReader in = null;
+        StringBuilder result = new StringBuilder();
+        try {
+            log.info("sendPost - {}", url);
+            URL realUrl = new URL(url);
+            URLConnection conn = realUrl.openConnection();
+            conn.setRequestProperty("accept", "*/*");
+            conn.setRequestProperty("connection", "Keep-Alive");
+            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+            conn.setRequestProperty("Accept-Charset", "utf-8");
+            conn.setRequestProperty("content-type", "application/json");
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            out = new PrintWriter(conn.getOutputStream());
+            out.print(param);
+            out.flush();
+            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+            log.info("recv - {}", result);
+        } catch (ConnectException e) {
+            throw new ServiceException(e.getMessage());
+            //log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
+        } catch (SocketTimeoutException e) {
+            log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
+            throw new ServiceException(e.getMessage());
+        } catch (IOException e) {
+            log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
+            throw new ServiceException(e.getMessage());
+        } catch (Exception e) {
+            log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
+            throw new ServiceException(e.getMessage());
+        } finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
+            }
+        }
+        return result.toString();
+    }
+
+    /**
+     * 向指定 URL 发送POST方法的请求
+     *
+     * @param url   发送请求的 URL
      * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
      * @return 所代表远程资源的响应结果
      */

Diferenças do arquivo suprimidas por serem muito extensas
+ 7 - 6
project-zcustom/src/main/java/com/project/zcustom/tools/LogisticsService.java


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff