From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 22 八月 2024 13:43:47 +0800
Subject: [PATCH] 2024年08月22日13:43:45

---
 app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java |   82 ++++++++++++++++++++++++++++------------
 1 files changed, 57 insertions(+), 25 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
index a72776c..4c0d8ec 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
@@ -62,7 +62,40 @@
     }
 
     /**
-     * 璇锋眰鏈嶅姟鍣�
+     * 璇锋眰鏈嶅姟鍣�(get)
+     * 搴曞眰鏂规硶,寮曠敤搴撶殑鏂规硶
+     *
+     * @param requestUrl 璇锋眰缁濆鍦板潃鎺ュ彛
+     * @param callBack   鍥炶皟
+     * @return -
+     */
+    private Disposable requestGet(String requestUrl, CloudCallBeak<String> callBack) {
+        HdlLogLogic.print("http---鍙戦��---" + requestUrl + "\r\n", isAddToMemory);
+        //寮�鍙戠幆澧冮渶瑕佸姞(鐢ㄦ潵鍖哄垎onpro鍜屽厜浼廰pp浠g爜):HxHttp.builder().headers("x-lbs-version", "hdl-yt")
+        return HxHttp.builder().url(requestUrl).build().get().subscribeWith(new HDLResponse<String>() {
+            @Override
+            public void onResponse(String str) {
+                if (callBack != null) {
+                    callBack.onSuccess(str);
+//                          System.out.println("http---鍥炲---" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString());
+                    HdlLogLogic.print("http---鍥炲---" + requestUrl + "\r\n" + str, isAddToMemory);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                HDLExceptionSubmitUtils.submit(requestUrl, "", e);
+                if (callBack != null) {
+                    callBack.onFailure(e);
+                    HdlLogLogic.print("http---鍥炲---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory);
+                }
+            }
+        });
+
+    }
+
+    /**
+     * 璇锋眰鏈嶅姟鍣�(post)
      * 搴曞眰鏂规硶,寮曠敤搴撶殑鏂规硶
      *
      * @param api      璇锋眰鎺ュ彛
@@ -72,15 +105,15 @@
      */
     private Disposable requestPost(String api, String body, CloudCallBeak<String> callBack) {
         String requestUrl = HDLCloudUserApi.getRequestUrl(api);
-        HdlLogLogic.print("http->鍙戦��->" + requestUrl + "\r\n" + body, isAddToMemory);
+        HdlLogLogic.print("http---鍙戦��---" + requestUrl + "\r\n" + body, isAddToMemory);
         //寮�鍙戠幆澧冮渶瑕佸姞(鐢ㄦ潵鍖哄垎onpro鍜屽厜浼廰pp浠g爜):HxHttp.builder().headers("x-lbs-version", "hdl-yt")
         return HxHttp.builder().url(requestUrl).raw(body).build().post().subscribeWith(new HDLResponse<String>() {
             @Override
             public void onResponse(String str) {
                 if (callBack != null) {
                     callBack.onSuccess(str);
-//                          System.out.println("http->鍥炲->" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString());
-                    HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + str, isAddToMemory);
+//                          System.out.println("http---鍥炲---" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString());
+                    HdlLogLogic.print("http---鍥炲---" + requestUrl + "\r\n" + str, isAddToMemory);
                 }
             }
 
@@ -89,7 +122,7 @@
                 HDLExceptionSubmitUtils.submit(requestUrl, body, e);
                 if (callBack != null) {
                     callBack.onFailure(e);
-                    HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory);
+                    HdlLogLogic.print("http---鍥炲---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory);
                 }
             }
         });
@@ -109,14 +142,14 @@
 
 
         String requestUrl = HDLCloudUserApi.getRequestUrl(api);
-        HdlLogLogic.print("http->鍙戦��->" + requestUrl + "\r\n" + body, isAddToMemory);
+        HdlLogLogic.print("http---鍙戦��---" + requestUrl + "\r\n" + body, isAddToMemory);
         return HxHttp.builder().url(requestUrl).file(body).build().post().subscribeWith(new HDLResponse<String>() {
             @Override
             public void onResponse(String str) {
                 if (callBack != null) {
                     callBack.onSuccess(str);
-//                          System.out.println("http->鍥炲->" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString());
-                    HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + str, isAddToMemory);
+//                          System.out.println("http---鍥炲---" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString());
+                    HdlLogLogic.print("http---鍥炲---" + requestUrl + "\r\n" + str, isAddToMemory);
                 }
             }
 
@@ -125,7 +158,7 @@
                 HDLExceptionSubmitUtils.submit(requestUrl, body, e);
                 if (callBack != null) {
                     callBack.onFailure(e);
-                    HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory);
+                    HdlLogLogic.print("http---鍥炲---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory);
                 }
             }
         });
@@ -166,9 +199,18 @@
                 });
     }
 
+    /**
+     * 璇锋眰(get)鏈嶅姟鍣�
+     *
+     * @param requestUrl 璇锋眰缁濆鍦板潃鎺ュ彛
+     * @param callBack   鍥炶皟
+     */
+    public Disposable requestHttpGet(String requestUrl, CloudCallBeak<String> callBack) {
+        return requestGet(requestUrl, callBack);
+    }
 
     /**
-     * 璇锋眰鏈嶅姟鍣�
+     * 璇锋眰(post)鏈嶅姟鍣�
      *
      * @param api      璇锋眰鎺ュ彛
      * @param body     璇锋眰鍙傛暟(json)
@@ -218,16 +260,6 @@
         this.requestHttpServer(fullUrl, json, isBasicService, isExecute, baseSuccessCallBeak);
     }
 
-    /**
-     * get鏂规硶璇锋眰
-     *
-     * @param url           http鍦板潃
-     * @param cloudCallBeak 鍥炶皟
-     */
-    public void requestHttpGet(String url, CloudCallBeak<String> cloudCallBeak) {
-        this.requestHttpServer(url, cloudCallBeak);
-    }
-
 
     /**
      * 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶
@@ -242,7 +274,7 @@
             @Override
             public void run() {
                 try {
-                    HdlLogLogic.print("http->鍙戦��->" + fullUrl + "\r\n" + json, isAddToMemory);
+                    HdlLogLogic.print("http---鍙戦��---" + fullUrl + "\r\n" + json, isAddToMemory);
                     OkHttpClient okHttpClient = new OkHttpClient();
                     RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), getJson(json));
                     final Request request = new Request.Builder().url(fullUrl)//璇锋眰鐨剈rl
@@ -252,7 +284,7 @@
                         if (response.isSuccessful()) {
                             String s = Objects.requireNonNull(response.body()).string();
                             HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class);
-                            HdlLogLogic.print("http->鍥炲->" + response.request().url() + "\r\n" + s, isAddToMemory);
+                            HdlLogLogic.print("http---鍥炲---" + response.request().url() + "\r\n" + s, isAddToMemory);
                             baseSuccessCallBeak.onSuccess(httpResponsePack);
 
                         } else {
@@ -265,7 +297,7 @@
                         call.enqueue(new Callback() {//寮傛
                             @Override
                             public void onFailure(@NonNull Call call, @NonNull IOException e) {
-                                HdlLogLogic.print("http->鍥炲->" + "\r\n" + e.getMessage(), isAddToMemory);
+                                HdlLogLogic.print("http---鍥炲---" + "\r\n" + e.getMessage(), isAddToMemory);
                             }
 
                             @Override
@@ -275,7 +307,7 @@
                                     String s = Objects.requireNonNull(response.body()).string();
                                     HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class);
                                     baseSuccessCallBeak.onSuccess(httpResponsePack);
-                                    HdlLogLogic.print("http->鍥炲->" + "\r\n" + s, isAddToMemory);
+                                    HdlLogLogic.print("http---鍥炲---" + "\r\n" + s, isAddToMemory);
                                 } else {
                                     baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message()));
                                 }
@@ -284,7 +316,7 @@
                     }
                 } catch (Exception e) {
                     baseSuccessCallBeak.onFailure(new HDLException(-100, e.getMessage()));
-                    HdlLogLogic.print("http->鍥炲->" + "\r\n" + e.getMessage(), isAddToMemory);
+                    HdlLogLogic.print("http---鍥炲---" + "\r\n" + e.getMessage(), isAddToMemory);
                 }
 
             }

--
Gitblit v1.8.0