From a8c3ca4f1d9433e914325222ae5f26da2f9e2489 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期四, 14 九月 2023 18:05:37 +0800
Subject: [PATCH] 增加了住宅id功能

---
 HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java |  228 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 159 insertions(+), 69 deletions(-)

diff --git a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
index 73cae8c..ffa64df 100644
--- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
+++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -1,8 +1,10 @@
 package com.hdl.hdlsdk;
 
 import android.Manifest;
+import android.content.Context;
 import android.content.Intent;
-import android.os.Build;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.util.Log;
@@ -15,7 +17,6 @@
 import androidx.activity.result.ActivityResultLauncher;
 import androidx.activity.result.contract.ActivityResultContracts;
 import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
@@ -28,29 +29,32 @@
 import com.hdl.sdk.common.event.DeleteNetworkListener;
 import com.hdl.sdk.common.event.EventListener;
 import com.hdl.sdk.common.exception.HDLLinkException;
+import com.hdl.sdk.common.utils.AllTopicManagerUtils;
 import com.hdl.sdk.common.utils.IdUtils;
 import com.hdl.sdk.common.utils.LogUtils;
 import com.hdl.sdk.common.utils.gson.GsonConvert;
 import com.hdl.sdk.connect.HDLLink;
 import com.hdl.sdk.connect.bean.LinkResponse;
+import com.hdl.sdk.connect.bean.request.AttributesRequest;
 import com.hdl.sdk.connect.bean.request.AuthenticateRequest;
 import com.hdl.sdk.connect.bean.request.DeviceControlRequest;
+import com.hdl.sdk.connect.bean.request.ListSidRequest;
 import com.hdl.sdk.connect.bean.request.ListUploadRequest;
 import com.hdl.sdk.connect.bean.response.BaseLocalResponse;
 import com.hdl.sdk.connect.bean.response.GatewaySearchBean;
+import com.hdl.sdk.connect.bean.response.UpdateInfo;
 import com.hdl.sdk.connect.callback.HDLLinkCallBack;
 import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack;
 import com.hdl.sdk.connect.cloud.CallBackListener;
+import com.hdl.sdk.connect.cloud.CheckAppVersionListener;
 import com.hdl.sdk.connect.cloud.HDLException;
 import com.hdl.sdk.connect.config.HDLLinkConfig;
 import com.hdl.sdk.connect.socket.HDLAuthSocket;
-import com.hdl.sdk.connect.utils.AesUtil;
 
 import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.List;
 import java.util.Map;
 
@@ -72,24 +76,6 @@
     protected void onDestroy() {
         super.onDestroy();
         removeAllTopicsListener();
-    }
-
-    void initDeviceInfo() {
-        AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
-        infoBean.setDeviceMAC("f2c5d8bad48f");
-        infoBean.setIPMAC("f2c5d8bad48f");
-        infoBean.setDeviceName("闊充箰鎾斁鍣�");//璁惧鍚嶅瓧
-        infoBean.setDeviceModel("MCLog.431");//璁惧鍨嬪彿
-        infoBean.setAccessMode("WIFI");
-        infoBean.setIPGateway("192.168.1.1");
-        infoBean.setIPAddress("192.168.1.103");
-        infoBean.setGateway_type("screen.touch");
-        infoBean.setHw_version("HW2.0");
-        infoBean.setFw_version("Fw1.0");
-        infoBean.setOID("010105000000FE11");//姣忎釜璁惧oid閮借涓嶄竴鏍�
-        infoBean.setSid("110105000000FE08110100000011");//姣忎釜璁惧鐨剆id閮借涓嶄竴鏍�
-        infoBean.setSupplier("JINMAOYUN");
-        HDLLinkConfig.getInstance().setDeviceInfoBean(infoBean);
     }
 
     void applyDeviceSecret() {
@@ -134,63 +120,30 @@
 
     }
 
-    /**
-     * 鍏ョ綉璁よ瘉
-     */
-    void sendAuthenticateRequest() {
-        tv.setText("寮�濮嬪叆缃戣璇�...");
+    void checkAppVersion() {
+        tv.setText("寮�濮嬫娴嬫洿鏂�...");
         responseTv.setText("");
-        //璁よ瘉鎻愪氦鍙傛暟鍑嗗
-//
-//        //娴嬭瘯鏈嶅姟鍣�
-//        String spkStr = "music.standard";//浜у搧spk
-//        String macStr = "AA000000000000AF";//璁惧鍞竴MAC鍦板潃
-//        String secret = "44b360eb74b7ba64";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
 
-//        姝e紡鏈嶅姟鍣�
-        String spkStr = "screen.touch";//浜у搧spk
-//        String macStr = "AA00000000000100";//璁惧鍞竴MAC鍦板潃
-        String macStr = editText.getText().toString();//璁惧鍞竴MAC鍦板潃
-//        String secret = "e186beeb7974998e";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
+//        //姝e紡鏈嶅姟鍣�
+        String appKey = "i8hR07jzrIS";//appkey
+        String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret
 
-        String mac_key = stringToMD5(stringToMD5(macStr + secret));
-        String versionString = "HDL_V1.0.1";//
-        String time = String.valueOf(System.currentTimeMillis());
-        HDLLinkConfig.getInstance().getDeviceInfoBean().setDeviceMAC(macStr);
-//        HDLLinkConfig.getInstance().setCurrentGateway(infoBean);
+        String appCode = "1697150870315999233";//appCode
 
-        //1.璁剧疆璁よ瘉淇℃伅
-        AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean();
-        requestBean.setMAC(macStr);
-        requestBean.setSupplier("JINMAOYUN");
-        requestBean.setFirmwareVersion(versionString);
-        requestBean.setHardwareModel("1956F");
-//        HDLLinkConfig.getInstance().setRequestBean(requestBean);
-
-        AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean();
-        authbean.setSpk(spkStr);
-        authbean.setMACKey(mac_key);
-        authbean.setRequest(requestBean);
-        HDLLinkConfig.getInstance().setAuthBean(authbean);
-
-        //HDLLinkConfig.getInstance().getDeviceInfoBean()杩欎釜鍒濆鍖栫殑鏃跺�欒鍏堣缃ソ
-        AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean);
-        HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() {
+        HDLLink.getInstance().checkAppVersion(this, appKey, appSecret, getAppVersionName(this), appCode, new CheckAppVersionListener() {
             @Override
-            public void onError(HDLLinkException e) {
-                tv.setText("璁よ瘉澶辫触" + e.getCode());
-                responseTv.setText(e.getMsg());
-                Log.e(TAG, "onError: 璁よ瘉澶辫触 " + e.getCode());
+            public void onSuccess(UpdateInfo info) {
+                tv.setText("鏈夋柊鏇存柊");
+                responseTv.setText(info.toString());
             }
 
-            @RequiresApi(api = Build.VERSION_CODES.O)
             @Override
-            public void onSuccess(String msg) {
-                tv.setText("璁よ瘉鎴愬姛");
-                responseTv.setText(msg.toString());
-                localSecret.setText("瀵嗛挜锛�" + HDLLinkConfig.getInstance().getLocalSecret());
+            public void onError(HDLException e) {
+                tv.setText("妫�娴嬫洿鏂板け璐�");
+                responseTv.setText(e.getMsg());
             }
         });
+
     }
 
     public void UploadDeviceAuth(String mac, String result, String message, String auth_code) {
@@ -239,6 +192,8 @@
             }
         });
 
+        UploadSidList();
+
         ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
             @Override
             public void onActivityResult(Map<String, Boolean> result) {
@@ -265,6 +220,7 @@
         beans.add(new DemoBean("UDP鍙戦�侊紝鐩戝惉涓婚鍥炲锛屽甫閲嶅彂甯﹀洖璋�"));
         beans.add(new DemoBean("TCP鍙戦�侊紝鐩戝惉涓婚鍥炲锛屽甫閲嶅彂甯﹀洖璋�"));
         beans.add(new DemoBean("閫�缃�"));
+        beans.add(new DemoBean("妫�娴嬫洿鏂�"));
         demoAdapter = new DemoAdapter(beans);
         rv.setAdapter(demoAdapter);
 
@@ -342,6 +298,10 @@
                     case 15:
                         //閫�缃�
                         deleteNetwork();
+                        break;
+                    case 16:
+                        //妫�娴嬫洿鏂�
+                        checkAppVersion();
                         break;
                 }
             }
@@ -426,6 +386,73 @@
         HDLLink.getInstance().removeAllTopicsListener(allTopicsListener);
     }
 
+    void initDeviceInfo()
+    {
+        AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
+        infoBean.setDeviceMAC("AA00000000000100");
+        infoBean.setIPMAC("AA00000000000100");
+        infoBean.setDeviceName("闊充箰鎾斁鍣�");//璁惧鍚嶅瓧
+        infoBean.setDeviceModel("MCLog.431");//璁惧鍨嬪彿
+        infoBean.setAccessMode("WIFI");
+        infoBean.setIPGateway("192.168.1.1");
+        infoBean.setIPAddress("192.168.1.116");
+        infoBean.setGateway_type("music.standard");
+        infoBean.setHw_version("HW2.0");
+        infoBean.setFw_version("Fw1.0");
+        infoBean.setOID("010105000000FE11");//姣忎釜璁惧oid閮借涓嶄竴鏍�
+        infoBean.setSid("110105000000FE08110100000011");//姣忎釜璁惧鐨剆id閮借涓嶄竴鏍�
+        HDLLinkConfig.getInstance().setDeviceInfoBean(infoBean);
+    }
+
+    /**
+     * 鍏ョ綉璁よ瘉
+     */
+    void sendAuthenticateRequest() {
+        tv.setText("寮�濮嬪叆缃戣璇�...");
+        //璁よ瘉鎻愪氦鍙傛暟鍑嗗
+
+//        娴嬭瘯鏈嶅姟
+//        String spkStr = "ir.module";//浜у搧spk
+//        String macStr = "AA000000000000AF";//璁惧鍞竴MAC鍦板潃
+//        String secret = "44b360eb74b7ba64";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
+
+//        姝e紡鏈嶅姟鍣�
+        String spkStr = "screen.mirror";//浜у搧spk
+        String macStr = "AA00000000000100";//璁惧鍞竴MAC鍦板潃
+        String secret = "e186beeb7974998e";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
+
+        String mac_key = stringToMD5(stringToMD5(macStr + secret));
+        String versionString = "HDL_V1.0.1";//
+        String time = String.valueOf(System.currentTimeMillis());
+        HDLLinkConfig.getInstance().getDeviceInfoBean().setDeviceMAC(macStr);
+
+        //1.璁剧疆璁よ瘉淇℃伅
+        AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean();
+        requestBean.setMAC(macStr);
+        requestBean.setSupplier("WISE");
+        requestBean.setFirmwareVersion(versionString);
+        requestBean.setHardwareModel("1956F");
+        AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean();
+        authbean.setSpk(spkStr);
+        authbean.setMACKey(mac_key);
+        authbean.setRequest(requestBean);
+        //HDLLinkConfig.getInstance().getDeviceInfoBean()杩欎釜鍒濆鍖栫殑鏃跺�欒鍏堣缃ソ
+        AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean);
+        HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() {
+            @Override
+            public void onError(HDLLinkException e) {
+                tv.setText("璁よ瘉澶辫触");
+                responseTv.setText(e.getMsg());
+                Log.i("TAG", "onError: 璁よ瘉澶辫触");
+            }
+
+            @Override
+            public void onSuccess(String msg) {
+                tv.setText("璁よ瘉鎴愬姛");
+                responseTv.setText(msg.toString());
+            }
+        });
+    }
 
     String stringToMD5(String text) {
         byte[] hash;
@@ -787,4 +814,67 @@
             }
         });
     }
+
+    private void UploadSidList() {
+        tv.setText("涓婃姤Sid鍒楄〃...");
+        responseTv.setText("");
+
+        //1.璁剧疆璁惧淇℃伅
+        AuthenticateRequest.AuthenticateDeviceInfoBean authenticateDeviceInfoBean = HDLLinkConfig.getInstance().getDeviceInfoBean();
+
+        ListSidRequest request = new ListSidRequest();
+        request.setOid(authenticateDeviceInfoBean.getOID());
+        request.setName("sid鍚嶇О");
+        request.setOmodel(authenticateDeviceInfoBean.getDeviceModel());
+        request.setSid("12345678");//褰撳墠sid鐨�
+        request.setSpk("light.switch");//褰撳墠spk鍚嶇О锛屾牴鎹疄闄呰澶囨潵瀹氫箟
+        request.setFrom(authenticateDeviceInfoBean.getOID());//鏉ヨ嚜鍝釜缃戝叧锛屽鏋滄椂Link缃戠粶璁惧锛屽垯濉嚜韬玱id锛涘鏋滄槸椹卞姩鍒欎笉闇�瑕佹瀛楁
+
+        AttributesRequest attributes = new AttributesRequest();
+        attributes.setKey("on_off");
+        attributes.setData_type("string");
+        List<Object> valueList=new ArrayList<>();
+        valueList.add("on");
+        valueList.add("off");
+        attributes.setValue(valueList);
+        //娣诲姞鏀寔鐨勫睘鎬у垪琛�
+        List<AttributesRequest> attributesList = new ArrayList<>();
+        request.setAttributes(attributesList);
+        List<ListSidRequest> sidRequestList = new ArrayList<>();
+        sidRequestList.add(request);
+        HDLLink.getInstance().UploadSidList(sidRequestList, new HDLLinkCallBack() {
+            @Override
+            public void onError(HDLLinkException error) {
+                tv.setText(error.getMsg());
+            }
+
+            @Override
+            public void onSuccess(String data) {
+                tv.setText("涓婃姤sid鍒楄〃鎴愬姛");
+                responseTv.setText(data);
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇APP鐗堟湰
+     *
+     * @param context
+     * @return
+     */
+    public static String getAppVersionName(Context context) {
+        String versionName = "0";
+        try {
+            PackageManager packageManager = context.getPackageManager();
+            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
+            versionName = packageInfo.versionName;
+            if (TextUtils.isEmpty(versionName)) {
+                versionName = "0";
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return versionName;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.8.0