From 5d0b8109b4e56463343ad23f75d1a1c1153ce5f9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 22 十一月 2022 15:02:25 +0800
Subject: [PATCH] 更改下入口

---
 AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java |  173 ++++++++++++++++++++++++---------------------------------
 1 files changed, 74 insertions(+), 99 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 fa2aed9..444c507 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
@@ -7,6 +7,7 @@
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.google.gson.reflect.TypeToken;
+import com.mm.android.deviceaddmodule.LCDeviceEngine;
 import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
 import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil;
 import com.mm.android.deviceaddmodule.mobilecommon.utils.MD5Helper;
@@ -32,23 +33,15 @@
 
     public static JsonObject execute(Map<String, Object> paramsMap, String method,int timeOut) throws BusinessException {
         Map<String, Object> map = paramsInit(paramsMap);
-        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;
+        if (CONST.isHdlServer()) {
+            jsonResult = doPost(CONST.HOST + "/home-wisdom/imou/openapi/" + method, map, timeOut);
         } else {
-            jsonObj = doPost(CONST.HOST + "/openapi/" + method, map, timeOut);
-            LogUtil.debugLog(TAG, "url::" + method + "\n" + "response result锛�" + jsonObj.toString());
-            if (jsonObj == null) {
+            jsonResult = doPost(CONST.HOST + "/openapi/" + method, map, timeOut);
+            if (jsonResult == null) {
                 throw new BusinessException("openApi response is null");
             }
-            jsonResult = jsonObj.getAsJsonObject("result");
+            jsonResult = jsonResult.getAsJsonObject("result");
         }
 
         if (jsonResult == null) {
@@ -71,53 +64,14 @@
         }
     }
 
-    public static JsonObject execute(String json, String method,int timeOut) throws BusinessException {
-        // 杩斿洖json
-        LogUtil.debugLog(TAG, "request result锛�" + json.toString());
-        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;
-        }
-        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");
-        }
-        String code = jsonResult.get("code").getAsString();
-        if (!"0".equals(code)) {
-            String msg = jsonResult.get("msg").getAsString();
-            throw new BusinessException(code + msg);
-        }
-        try {
-            JsonObject jsonData = jsonResult.getAsJsonObject("data");
-            if (jsonData ==null){
-                jsonData=new JsonObject();
-            }
-            return jsonData;
-        } catch (Throwable e) {
-            BusinessException businessException = new BusinessException(e);
-            throw businessException;
-        }
-    }
 
     private static JsonObject doPost(String url, Map<String, Object> map, int timeOut) throws BusinessException {
         Gson gson = new Gson();
-        map.put("homeId",1547099040465408002L);
-        String json =null;
-        JsonObject jsonObject = new JsonObject();
-        if(url.contains("hdlcontrol.com")) {
+        map.put("homeId", LCDeviceEngine.newInstance().getHomeId());
+        String json;
+        JsonObject jsonObject;
+        if(CONST.isHdlServer()) {
             if (map.containsKey("params")) {
                 Map<String, Object> tempMap = (Map<String, Object>) map.get("params");
                 map.remove("params");
@@ -161,28 +115,6 @@
         return jsonObject;
     }
 
-    private static JsonObject doPost(String url, String json, int timeOut) throws BusinessException {
-        Gson gson = new Gson();
-        JsonObject jsonObject = new JsonObject();
-        try {
-            LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json.toString());
-            String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut);
-            jsonObject =  new JsonParser().parse(openApi).getAsJsonObject();
-        } catch (IOException e) {
-            BusinessException b = new BusinessException(e);
-            if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException
-                    || e instanceof UnknownHostException
-                    || e instanceof UnknownServiceException || e instanceof SSLException
-                    || e instanceof SocketException) {
-                b.errorDescription = "鎿嶄綔澶辫触锛岃妫�鏌ョ綉缁�";
-            }
-            throw b;
-        } catch (Throwable e) {
-            BusinessException b = new BusinessException(e);
-            throw b;
-        }
-        return jsonObject;
-    }
 
     private static Map<String, Object> paramsInit(Map<String, Object> paramsMap) {
         long time = System.currentTimeMillis() / 1000;
@@ -208,26 +140,69 @@
         return map;
     }
 
+//    public static JsonObject execute(String json, String method,int timeOut) throws BusinessException {
+//        // 杩斿洖json
+//        LogUtil.debugLog(TAG, "request result锛�" + json.toString());
+//        JsonObject jsonResult=null;
+//        if (CONST.isHdlServer()) {
+//            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;
+//        }
+//        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");
+//        }
+//        String code = jsonResult.get("code").getAsString();
+//        if (!"0".equals(code)) {
+//            String msg = jsonResult.get("msg").getAsString();
+//            throw new BusinessException(code + msg);
+//        }
+//        try {
+//            JsonObject jsonData = jsonResult.getAsJsonObject("data");
+//            if (jsonData ==null){
+//                jsonData=new JsonObject();
+//            }
+//            return jsonData;
+//        } catch (Throwable e) {
+//            BusinessException businessException = new BusinessException(e);
+//            throw businessException;
+//        }
+//    }
 
-    /**
-     * 鍩烘湰绫诲瀷鍔犲瘑
-     * <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;
-    }
+
+//    private static JsonObject doPost(String url, String json, int timeOut) throws BusinessException {
+//        Gson gson = new Gson();
+//        JsonObject jsonObject = new JsonObject();
+//        try {
+//            LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json.toString());
+//            String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut);
+//            jsonObject =  new JsonParser().parse(openApi).getAsJsonObject();
+//        } catch (IOException e) {
+//            BusinessException b = new BusinessException(e);
+//            if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException
+//                    || e instanceof UnknownHostException
+//                    || e instanceof UnknownServiceException || e instanceof SSLException
+//                    || e instanceof SocketException) {
+//                b.errorDescription = "鎿嶄綔澶辫触锛岃妫�鏌ョ綉缁�";
+//            }
+//            throw b;
+//        } catch (Throwable e) {
+//            BusinessException b = new BusinessException(e);
+//            throw b;
+//        }
+//        return jsonObject;
+//    }
+
 }

--
Gitblit v1.8.0