From 84396f60e368a5f5261ba21121d013ef8bfbf523 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 21 二月 2023 15:42:35 +0800
Subject: [PATCH] 广播绑定状态

---
 AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 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 d08582c..cd6c3a5 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,5 +1,6 @@
 package com.mm.android.deviceaddmodule.openapi;
 
+import android.content.Intent;
 import android.text.TextUtils;
 
 import com.google.gson.Gson;
@@ -53,8 +54,25 @@
         }
         String code = jsonResult.get("code").getAsString();
         if (!"0".equals(code)) {
-            String msg = jsonResult.get("msg").getAsString();
-            throw new BusinessException(code + msg);
+            try {
+                String msg = jsonResult.get("msg").getAsString();
+                if (method.equals("bindDevice")) {
+                    Intent intent = new Intent();
+                    intent.setAction("hdlUserDeviceBind");
+                    intent.putExtra("data", jsonResult.toString());
+                    LCDeviceEngine.newInstance().getContext().sendBroadcast(intent);
+                }
+                throw new BusinessException(code + msg);
+            }catch (Exception exception){
+                String msg = jsonResult.get("message").getAsString();
+                if (method.equals("bindDevice")) {
+                    Intent intent = new Intent();
+                    intent.setAction("hdlUserDeviceBind");
+                    intent.putExtra("data", jsonResult.toString());
+                    LCDeviceEngine.newInstance().getContext().sendBroadcast(intent);
+                }
+                throw new BusinessException(code + msg);
+            }
         }
 
         JsonObject jsonData = new JsonObject();
@@ -106,7 +124,11 @@
             LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json);
             String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut);
             LogUtil.debugLog(TAG, "杩斿洖缁撴灉: \r\n"  + openApi);
-            jsonObject =  new JsonParser().parse(openApi).getAsJsonObject();
+            try {
+                jsonObject = new JsonParser().parse(openApi).getAsJsonObject();
+            }catch (Exception exception){
+                jsonObject = new Gson().fromJson(openApi,JsonObject.class);
+            }
         } catch (IOException e) {
             BusinessException b = new BusinessException(e);
             if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException

--
Gitblit v1.8.0