From f2a3965a672fca33831d361872874fec104846d5 Mon Sep 17 00:00:00 2001
From: Runt <qingingrunt2010@qq.com>
Date: Fri, 29 Aug 2025 11:37:21 +0000
Subject: [PATCH] 文件选择优化

---
 libmvi/src/main/java/com/runt/open/mvi/retrofit/Interceptor/HttpLoggingInterceptor.java |   64 ++++++++++++++------------------
 1 files changed, 28 insertions(+), 36 deletions(-)

diff --git a/libmvi/src/main/java/com/runt/open/mvi/retrofit/Interceptor/HttpLoggingInterceptor.java b/libmvi/src/main/java/com/runt/open/mvi/retrofit/Interceptor/HttpLoggingInterceptor.java
index ee2fbb0..18ef45b 100644
--- a/libmvi/src/main/java/com/runt/open/mvi/retrofit/Interceptor/HttpLoggingInterceptor.java
+++ b/libmvi/src/main/java/com/runt/open/mvi/retrofit/Interceptor/HttpLoggingInterceptor.java
@@ -2,13 +2,10 @@
 
 import android.util.Log;
 
-import com.google.gson.Gson;
-import com.runt.open.mvi.OpenApplication;
-import com.runt.open.mvi.data.PhoneDevice;
 import com.runt.open.mvi.retrofit.net.NetWorkCost;
-import com.runt.open.mvi.retrofit.net.NetWorkListenear;
+import com.runt.open.mvi.retrofit.net.NetWorkListener;
 import com.runt.open.mvi.retrofit.utils.HttpPrintUtils;
-import com.runt.open.mvi.utils.DeviceUtil;
+import com.runt.open.mvi.retrofit.utils.RSAUtils;
 
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -40,31 +37,17 @@
  * @purpose Created by Runt (qingingrunt2010@qq.com) on 2020-10-21.
  */
 
-public class HttpLoggingInterceptor extends AddHeadersInterceptor {
+public class HttpLoggingInterceptor extends OpenInterceptor {
 
     final String TAG = "HttpLogging";
-
-    private boolean printLog ;
-
-    public HttpLoggingInterceptor(){
-        this(true);
-    }
-    public HttpLoggingInterceptor(boolean printLog) {
-        this.printLog = printLog;
-    }
 
     @Override
     public Response intercept(Chain chain) throws IOException {
 
         Request requestTemp = chain.request();
         int hashCode = requestTemp.hashCode();
-        if(printLog) {
-            Log.d(TAG, "hashcode:" + hashCode);
-        }
-        Request.Builder requestBuild = requestTemp.newBuilder()
-                .addHeader("device", new Gson().toJson(PhoneDevice.getDevice()))
-                .addHeader("appVersion",  DeviceUtil.getAppVersionName(OpenApplication.Companion.getApplication()))
-                .addHeader("os", DeviceUtil.isHarmonyOS()? "harmony" : "android");
+        Log.d(TAG, "hashcode:" + hashCode);
+        Request.Builder requestBuild = addHeaders(requestTemp);
         /*if(UserBean.getUser() != null){
             requestBuild.addHeader("token",UserBean.getUser().getToken());
         }*/
@@ -74,19 +57,17 @@
         try {
             logArrays.addAll(getRequestLog(request));
             int position = logArrays.size() +2;
-            response = chain.proceed(request);
+            response = proceed(chain,request);
             logArrays.addAll(getResponseLog(response));
-            NetWorkCost netWorkCost = NetWorkListenear.workCostMap.get(hashCode);
+            NetWorkCost netWorkCost = NetWorkListener.workCostMap.get(hashCode);
             if(netWorkCost != null) {
                 logArrays.add(position, "<-- costtimes : " + netWorkCost);
             }
-            NetWorkListenear.workCostMap.remove(hashCode);
+            NetWorkListener.workCostMap.remove(hashCode);
             new Thread(){
                 @Override
                 public void run() {
-                    if(printLog) {
-                        HttpPrintUtils.getInstance().printLog(logArrays, true);//线程安全方法,需在新线程执行,避免阻塞当前线程,导致程序无响应
-                    }
+                    HttpPrintUtils.getInstance().printLog(logArrays, true);//线程安全方法,需在新线程执行,避免阻塞当前线程,导致程序无响应
                 }
             }.start();
         } catch (JSONException e) {
@@ -96,20 +77,18 @@
             e.printStackTrace();
         } catch (Exception e) {
             logArrays.add("<-- response url:" + URLDecoder.decode(request.url().toString(), "UTF-8"));
-            NetWorkCost netWorkCost = NetWorkListenear.workCostMap.get(hashCode);
+            NetWorkCost netWorkCost = NetWorkListener.workCostMap.get(hashCode);
             if (netWorkCost != null) {
                 netWorkCost.total = new Date().getTime() - netWorkCost.total;
                 logArrays.add("<-- costtimes : " + netWorkCost);
             }
-            NetWorkListenear.workCostMap.remove(hashCode);
+            NetWorkListener.workCostMap.remove(hashCode);
             logArrays.add("<-- response failed " + e.getLocalizedMessage());
             logArrays.add("<--                 " + e.toString());
             new Thread(){
                 @Override
                 public void run() {
-                    if(printLog) {
-                        HttpPrintUtils.getInstance().printLog(logArrays, false);//线程安全方法,需在新线程执行,避免阻塞当前线程,导致程序无响应
-                    }
+                    HttpPrintUtils.getInstance().printLog(logArrays, false);//线程安全方法,需在新线程执行,避免阻塞当前线程,导致程序无响应
                 }
             }.start();
             throw e;//抛出异常,用于请求接收信息
@@ -117,12 +96,16 @@
         return response;
     }
 
+    protected Response proceed(Chain chain,Request request) throws IOException {
+        return chain.proceed(request);
+    }
+
     /**
      * 请求数据信息
      * @param request
      * @return
      */
-    private ArrayList<String> getRequestLog(Request request) throws IOException, JSONException {
+    protected ArrayList<String> getRequestLog(Request request) throws IOException, JSONException {
         RequestBody requestBody = request.body();
         ArrayList<String> logArrays = new ArrayList<>();
         String requestStartMessage = "--> " + request.method() + ' ' + URLDecoder.decode(request.url().toString() ,"UTF-8")+ ' ' ;
@@ -195,7 +178,7 @@
      * @throws IOException
      * @throws JSONException
      */
-    private ArrayList<String> getResponseLog(Response response) throws IOException, JSONException {
+    protected ArrayList<String> getResponseLog(Response response) throws IOException, JSONException {
         ArrayList<String> logArrays = new ArrayList<>();
         ResponseBody responseBody = response.body();
         long contentLength = responseBody.contentLength();
@@ -223,7 +206,16 @@
                 if (contentLength != 0) {
                     String str = buffer.clone().readString(charset);
                     if(str.trim().indexOf("{") == 0) {
-                        logArrays.add(new JSONObject(str).toString(4));
+                        JSONObject object = new JSONObject(str);
+                        if(object.has("body")){
+                            try {
+                                logArrays.add(new JSONObject(RSAUtils.decryptVerify(object.getString("body"))).toString(4));
+                            } catch (Exception e) {
+                                throw new RuntimeException(e);
+                            }
+                        }else{
+                            logArrays.add(object.toString(4));
+                        }
                     }else if(str.trim().indexOf("[") == 0) {
                         logArrays.add(new JSONArray(str).toString(4));
                     }else{

--
Gitblit v1.9.1