From b3513b1713bb979d0a69c5a8c4ddcd038f184e6e Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 22 十一月 2022 13:59:20 +0800
Subject: [PATCH] 可以测试

---
 AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java |  108 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 93 insertions(+), 15 deletions(-)

diff --git a/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java b/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java
index e2317b7..fa2aed9 100644
--- a/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java
+++ b/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java
@@ -1,17 +1,23 @@
 package com.mm.android.deviceaddmodule.openapi;
 
+import android.text.TextUtils;
+
 import com.google.gson.Gson;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
+import com.google.gson.reflect.TypeToken;
 import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
 import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil;
 import com.mm.android.deviceaddmodule.mobilecommon.utils.MD5Helper;
 
 import org.apache.http.conn.ConnectTimeoutException;
+import org.json.JSONObject;
 
 import java.io.IOException;
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
+import java.net.URLDecoder;
 import java.net.UnknownHostException;
 import java.net.UnknownServiceException;
 import java.util.HashMap;
@@ -26,13 +32,25 @@
 
     public static JsonObject execute(Map<String, Object> paramsMap, String method,int timeOut) throws BusinessException {
         Map<String, Object> map = paramsInit(paramsMap);
-        // 杩斿洖json
-        JsonObject jsonObj = doPost(CONST.HOST + "/openapi/" + method, map,timeOut);
-        LogUtil.debugLog(TAG, "url::"+method+"\n"+"response result锛�" + jsonObj.toString());
-        if (jsonObj == null) {
-            throw new BusinessException("openApi response is null");
+        JsonObject jsonObj = null;
+        JsonObject jsonResult = null;
+        if (CONST.HOST.contains("hdlcontrol.com")) {
+            // 杩斿洖json
+            jsonObj = doPost(CONST.HOST + "/home-wisdom/imou/openapi/" + method, map, timeOut);
+            LogUtil.debugLog(TAG, "url::" + method + "\n" + "response result锛�" + jsonObj.toString());
+            if (jsonObj == null) {
+                throw new BusinessException("openApi response is null");
+            }
+            jsonResult = jsonObj;
+        } else {
+            jsonObj = doPost(CONST.HOST + "/openapi/" + method, map, timeOut);
+            LogUtil.debugLog(TAG, "url::" + method + "\n" + "response result锛�" + jsonObj.toString());
+            if (jsonObj == null) {
+                throw new BusinessException("openApi response is null");
+            }
+            jsonResult = jsonObj.getAsJsonObject("result");
         }
-        JsonObject jsonResult = jsonObj.getAsJsonObject("result");
+
         if (jsonResult == null) {
             throw new BusinessException("openApi response is null");
         }
@@ -43,8 +61,8 @@
         }
         try {
             JsonObject jsonData = jsonResult.getAsJsonObject("data");
-            if (jsonData ==null){
-                jsonData=new JsonObject();
+            if (jsonData == null) {
+                jsonData = new JsonObject();
             }
             return jsonData;
         } catch (Throwable e) {
@@ -56,12 +74,24 @@
     public static JsonObject execute(String json, String method,int timeOut) throws BusinessException {
         // 杩斿洖json
         LogUtil.debugLog(TAG, "request result锛�" + json.toString());
-        JsonObject jsonObj = doPost(CONST.HOST + "/openapi/" + method, json,timeOut);
-        LogUtil.debugLog(TAG, "URL::"+method+"\n"+"response result锛�" + jsonObj.toString());
-        if (jsonObj == null) {
-            throw new BusinessException("openApi response is null");
+        JsonObject jsonResult=null;
+        if (CONST.HOST.contains("hdlcontrol.com")) {
+            JsonObject jsonObj = doPost(CONST.HOST + "/home-wisdom/imou/openapi/"  + method, json, timeOut);
+            LogUtil.debugLog(TAG, "URL::"+method+"\n"+"response result锛�" + jsonObj.toString());
+            if (jsonObj == null) {
+                throw new BusinessException("openApi response is null");
+            }
+            jsonResult = jsonObj;
         }
-        JsonObject jsonResult = jsonObj.getAsJsonObject("result");
+        else {
+            JsonObject jsonObj = doPost(CONST.HOST + "/openapi/" + method, json, timeOut);
+            LogUtil.debugLog(TAG, "URL::"+method+"\n"+"response result锛�" + jsonObj.toString());
+            if (jsonObj == null) {
+                throw new BusinessException("openApi response is null");
+            }
+            jsonResult = jsonObj.getAsJsonObject("result");
+        }
+
         if (jsonResult == null) {
             throw new BusinessException("openApi response is null");
         }
@@ -84,10 +114,35 @@
 
     private static JsonObject doPost(String url, Map<String, Object> map, int timeOut) throws BusinessException {
         Gson gson = new Gson();
-        String json = gson.toJson(map);
+        map.put("homeId",1547099040465408002L);
+        String json =null;
         JsonObject jsonObject = new JsonObject();
+        if(url.contains("hdlcontrol.com")) {
+            if (map.containsKey("params")) {
+                Map<String, Object> tempMap = (Map<String, Object>) map.get("params");
+                map.remove("params");
+                map.remove("id");
+                map.remove("system");
+                for (Map.Entry<String, Object> temp : tempMap.entrySet()) {
+                    if ("page".equals(temp.getKey())) {
+                        map.put("pageNo", temp.getValue());
+                    }
+                    else {
+                        if("token".equals(temp.getKey())){
+                            continue;
+                        }
+                        map.put(temp.getKey(), temp.getValue());
+                    }
+                }
+            }
+
+            json = gson.toJson(HttpClient.encrypt(map));
+        }else{
+            json = gson.toJson(map);
+        }
+
         try {
-            LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json.toString());
+            LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json);
             String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut);
             jsonObject =  new JsonParser().parse(openApi).getAsJsonObject();
         } catch (IOException e) {
@@ -152,4 +207,27 @@
         map.put("id", id);
         return map;
     }
+
+
+    /**
+     * 鍩烘湰绫诲瀷鍔犲瘑
+     * <p>
+     * 鍒ゆ柇褰撳墠鍊兼槸鍚﹂渶瑕佸弬涓庣鍚嶏紝淇濇寔璺熶簯绔竴鑷�
+     * 绌哄瓧绗︿覆涓嶅弬涓�
+     * 鏁扮粍,闆嗗悎涓嶅弬涓�
+     *
+     * @return ture 闇�瑕佸姞瀵�
+     */
+    private static boolean valueNeedSign(String valueStr) {
+        try {
+            if (TextUtils.isEmpty(valueStr)) return false;
+            final char[] strChar = URLDecoder.decode(valueStr, "utf-8")
+                    .substring(0, 1).toCharArray();
+            final char firstChar = strChar[0];
+            return firstChar != '{' && firstChar != '[';
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
 }

--
Gitblit v1.8.0