Răsfoiți Sursa

1.4.2 optimize:

xwh 3 săptămâni în urmă
părinte
comite
4d45e295fc

+ 2 - 3
app/build.gradle

@@ -44,9 +44,8 @@ android {
             // 服务器地址
             // 通用
             buildConfigField("String", "BASE_URL", "\"https://hhomc.hz-hanghui.com:8096/\"")
-            buildConfigField("String", "BASE_URL_WEBSOCKET", "\"wss://hhomc.hz-hanghui.com:18096/\"")
-          //  buildConfigField("String", "BASE_URL_WEBSOCKET", "\"ws://115.227.34.58:18096/\"")
-
+          //  buildConfigField("String", "BASE_URL_WEBSOCKET", "\"wss://hhomc.hz-hanghui.com:18096/\"")
+            buildConfigField("String", "BASE_URL_WEBSOCKET", "\"ws://115.227.34.58:19086/\"")
             // 故宫
 //            buildConfigField("String", "BASE_URL", "\"https://aiotota.dpm.org.cn/\"")
 //            buildConfigField("String", "BASE_URL_WEBSOCKET", "\"wss://aiotota.dpm.org.cn/\"")

+ 1 - 192
app/src/main/java/com/hh/hhomc/http/CommonAddAndHandleInterceptor.java

@@ -88,202 +88,11 @@ public class CommonAddAndHandleInterceptor implements Interceptor {
         Response originalResponse = chain.proceed(newRequest);
         LogUtils.i(mTag + "调用拦截器处理获取结果originalResponse" + originalResponse);
 
-        // 返回体
-        ResponseBody responseBody = originalResponse.body();
 
-        Response newResponse = null;
 
-        try {
-            JSONObject jsonObject = new JSONObject(responseBody.string());
-
-            Object result = null;
-            try {
-                result = jsonObject.get(serverResult);
-            } catch (JSONException e) {
-                e.printStackTrace();
-                // 处理服务端没有返回result的情况
-                LogUtils.i(mTag + "需要处理,原始返回的Json没有result字段");
-                JSONObject newJsonObject = new JSONObject();
-                JSONObject obj = new JSONObject();
-                newJsonObject.put(serverResult, obj); // serverResult: {}
-                newJsonObject.put("code", jsonObject.getInt("code"));
-                newJsonObject.put("message", jsonObject.getString("message"));
-                newJsonObject.put("success", jsonObject.getBoolean("success"));
-                LogUtils.i(mTag + "newJsonObject:" + newJsonObject.toString());
-
-                //获取返回值类型
-                MediaType mediaType = responseBody.contentType();
-                newResponse = new Response.Builder()
-                        .code(200)
-                        .body(ResponseBody.create(mediaType,
-
-                                newJsonObject.toString()))
-                        .request(newRequest)
-                        .protocol(Protocol.HTTP_1_1)
-                        .message("OK")
-                        .build();
-                LogUtils.i(mTag + "newResponse:" + newResponse.toString());
-
-                //拿到结果进行处理后返回
-                return newResponse;
-            }
-
-            //接下来都是有result字段的处理
-
-            LogUtils.i(mTag + "result:" + result);
-
-//            if(result.equals(null)){
-//                LogUtils.i(mTag+"equals(null)");
-//            }
-//            if(jsonObject.has(serverResult)){
-//                LogUtils.i(mTag+"has(\"result\")");
-//            }
-
-
-            if (result.equals(null)) {
-                // 处理serverResult: null 的情况 result或data取决于服务端返回数据名
-
-                JSONObject newJsonObject = new JSONObject();
-                LogUtils.i(mTag + "需要处理,原始返回的Json--result==null");
-                JSONObject obj = new JSONObject();
-//                    obj.put("list", jsonObject.getJSONArray("data"));
-                newJsonObject.put(serverResult, obj); // serverResult: {}
-                newJsonObject.put("code", jsonObject.getInt("code"));
-                newJsonObject.put(message, jsonObject.getString(message));
-//                newJsonObject.put("success", jsonObject.getBoolean("success"));
-                LogUtils.i(mTag + "newJsonObject:" + newJsonObject.toString());
-
-                //获取返回值类型
-                MediaType mediaType = responseBody.contentType();
-                newResponse = new Response.Builder()
-                        .code(200)
-                        .body(ResponseBody.create(mediaType,
-
-                                newJsonObject.toString()))
-                        .request(newRequest)
-                        .protocol(Protocol.HTTP_1_1)
-                        .message("OK")
-                        .build();
-                LogUtils.i(mTag + "newResponse:" + newResponse.toString());
-
-                //拿到结果进行处理后返回
-                return newResponse;
-
-            } else if (jsonObject.get(serverResult) instanceof JSONArray) {
-                // 处理result是数组的情况
-                JSONObject newJsonObject = new JSONObject();
-                LogUtils.i(mTag + "需要处理,原始返回的Json--result是数组");
-                JSONObject obj = new JSONObject();
-                obj.put("list", jsonObject.getJSONArray(serverResult));
-                newJsonObject.put(serverResult, obj);
-                newJsonObject.put("code", jsonObject.getInt("code"));
-                newJsonObject.put(message, jsonObject.getString(message));
-//                newJsonObject.put("success", jsonObject.getBoolean("success"));
-                LogUtils.i("newJsonObject:" + newJsonObject.toString());
-
-                //获取返回值类型
-                MediaType mediaType = responseBody.contentType();
-
-                newResponse = new Response.Builder()
-                        .code(200)
-                        .body(ResponseBody.create(mediaType,
-
-                                newJsonObject.toString()))
-                        .request(newRequest)
-                        .protocol(Protocol.HTTP_1_1)
-                        .message("OK")
-                        .build();
-                LogUtils.i(mTag + "newResponse:" + newResponse.toString());
-
-                //拿到结果进行处理后返回
-                return newResponse;
-
-            } else if (jsonObject.get(serverResult) instanceof String) {
-                // 处理result是string的情况
-                JSONObject newJsonObject = new JSONObject();
-                LogUtils.i(mTag + "需要处理,原始返回的Json--result是string");
-                JSONObject obj = new JSONObject();
-                obj.put("string", jsonObject.getString(serverResult));
-                newJsonObject.put(serverResult, obj);
-                newJsonObject.put("code", jsonObject.getInt("code"));
-                newJsonObject.put(message, jsonObject.getString(message));
-//                newJsonObject.put("success", jsonObject.getBoolean("success"));
-                LogUtils.i("newJsonObject:" + newJsonObject.toString());
-
-                //获取返回值类型
-                MediaType mediaType = responseBody.contentType();
-
-                newResponse = new Response.Builder()
-                        .code(200)
-                        .body(ResponseBody.create(mediaType,
-
-                                newJsonObject.toString()))
-                        .request(newRequest)
-                        .protocol(Protocol.HTTP_1_1)
-                        .message("OK")
-                        .build();
-                LogUtils.i(mTag + "newResponse:" + newResponse.toString());
-
-                //拿到结果进行处理后返回
-                return newResponse;
-
-            } else if (jsonObject.get(serverResult) instanceof Integer) {
-                // 处理result是Integer的情况
-                JSONObject newJsonObject = new JSONObject();
-                LogUtils.i(mTag + "需要处理,原始返回的Json--result是Integer");
-                JSONObject obj = new JSONObject();
-                obj.put("intValue", jsonObject.getInt(serverResult));
-                newJsonObject.put(serverResult, obj);
-                newJsonObject.put("code", jsonObject.getInt("code"));
-                newJsonObject.put(message, jsonObject.getString(message));
-//                newJsonObject.put("success", jsonObject.getBoolean("success"));
-                LogUtils.i("newJsonObject:" + newJsonObject.toString());
-
-                //获取返回值类型
-                MediaType mediaType = responseBody.contentType();
-
-                newResponse = new Response.Builder()
-                        .code(200)
-                        .body(ResponseBody.create(mediaType,
-
-                                newJsonObject.toString()))
-                        .request(newRequest)
-                        .protocol(Protocol.HTTP_1_1)
-                        .message("OK")
-                        .build();
-                LogUtils.i(mTag + "newResponse:" + newResponse.toString());
-
-                //拿到结果进行处理后返回
-                return newResponse;
-
-            } else {
-                LogUtils.i(mTag + "非需要处理的url,直接返回");
-                // 重复使用chain.proceed(request)导致会出现重复请求问题
-//                newResponse = chain.proceed(newRequest);
-//                LogUtils.i(mTag + "originalResponse:" + originalResponse.toString());
-//                return newResponse;
-
-                //获取返回值类型
-                MediaType mediaType = responseBody.contentType();
-
-                newResponse = new Response.Builder()
-                        .code(200)
-                        .body(ResponseBody.create(mediaType,
-                                jsonObject.toString()))
-                        .request(newRequest)
-                        .protocol(Protocol.HTTP_1_1)
-                        .message("OK")
-                        .build();
-
-                return newResponse;
-            }
+        return originalResponse;
 
-        } catch (Exception e) {
-            e.printStackTrace();
-            LogUtils.i(mTag + "e--:" + e.toString());
-        }
 //        return  originalResponse.newBuilder().body(responseBody).build();
-        return originalResponse;
 
 
 //        return chain.proceed(request);

+ 1 - 1
config.gradle

@@ -8,7 +8,7 @@ ext {
             minSdkVersion    : 21,
             targetSdkVersion : 30,
             versionCode      : 25,
-            versionName      : "1.4.2"
+            versionName      : "1.4.2.241231"
     ]
     //依赖 配置
     dependencies = [

+ 1 - 1
lib_base/build.gradle

@@ -35,7 +35,7 @@ android {
             buildConfigField("String", "SP_NAME", "\"Sp_Config\"")
         }
         release {
-            buildConfigField("boolean", "LOG_DEBUG", "true")
+            buildConfigField("boolean", "LOG_DEBUG", "false")
             buildConfigField("String", "LOG_TAG", "\"HHOMC\"")
             buildConfigField("String", "SP_NAME", "\"Sp_Config\"")
             minifyEnabled false