From e7b78e0a428fa54d94c1b274a4305640b2859e80 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 15 十一月 2021 15:15:57 +0800
Subject: [PATCH] 2021-11-15 1.更新

---
 HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java |  135 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 112 insertions(+), 23 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 77eb6fa..4223f60 100644
--- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
+++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -13,9 +13,15 @@
 import android.util.Log;
 import android.view.View;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.chad.library.adapter.base.BaseQuickAdapter;
 import com.chad.library.adapter.base.listener.OnItemClickListener;
+import com.hdl.sdk.common.utils.IdUtils;
+import com.hdl.sdk.common.utils.IpUtils;
+import com.hdl.sdk.connect.HDLLink;
+import com.hdl.sdk.connect.bean.AuthenticateRequest;
+import com.hdl.sdk.connect.bean.GatewaySearchBean;
 import com.hdl.sdk.connect.config.HDLLinkConfig;
 import com.hdl.sdk.connect.socket.HDLAuthSocket;
 import com.hdl.sdk.connect.socket.HDLSocket;
@@ -25,6 +31,9 @@
 import com.hdl.sdk.socket.SocketOptions;
 import com.hdl.sdk.socket.codec.MessagePipeLine;
 
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -46,8 +55,8 @@
         tv = findViewById(R.id.state_tv);
         rv = findViewById(R.id.rv);
         rv.setLayoutManager(new LinearLayoutManager(this));
-        HDLLinkConfig.getInstance().setLocalEncrypt(true);
-        HDLLinkConfig.getInstance().setLocalSecret("5648d9b9cafd30dd");
+
+        checkIfCertified();
 
         ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
             @Override
@@ -66,6 +75,7 @@
         beans.add(new DemoBean("鐘舵�佷笂鎶�"));
         beans.add(new DemoBean("璇诲彇鐘舵��"));
         beans.add(new DemoBean("鍏ョ綉璁よ瘉"));
+        beans.add(new DemoBean("鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎"));
         demoAdapter = new DemoAdapter(beans);
         rv.setAdapter(demoAdapter);
 
@@ -148,33 +158,24 @@
                         // HDLSocket.getInstance().propertyRead();
                         break;
                     case 6:
-                        //鍏ョ綉璁よ瘉
-                        HDLAuthSocket.getInstance().sendAuthenticateRequest(new HDLAuthSocket.CallBack() {
+//                        //鍏ョ綉璁よ瘉
+                        sendAuthenticateRequest();
+                        break;
+                    case 7:
+//                        //濡傛灉宸茬粡璁よ瘉鍚庯紝鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎
+                        HDLLink.getInstance().searchGateway(new HDLAuthSocket.SearchGatewayCallBack() {
                             @Override
-                            public void onError(String error) {
-                                Log.i("TAG", "onError: 璁よ瘉澶辫触");
-//                                tv.setText("璁よ瘉澶辫触");
-//                                responseTv.setText(error);
+                            public void onEnd(String error) {
+                                tv.setText("缃戝叧涓嶅湪绾�");
                             }
 
                             @Override
-                            public void onSuccess(String data) {
-                                tv.setText("璁よ瘉鎴愬姛");
-                                responseTv.setText(data);
+                            public void onSuccess(GatewaySearchBean gatewaySearchBean) {
+                                tv.setText("缃戝叧鍦ㄧ嚎");
+                                responseTv.setText("缃戝叧id锛�"+gatewaySearchBean.getGatewayId());
+//                                Log.i("TAG", "onSuccess: 鎼滅储鎴愬姛锛�"+gatewaySearchBean.getGatewayId());
                             }
                         });
-
-//                        HDLAuthSocket.getInstance().searchGateway("1406844230123372545", new HDLAuthSocket.SearchGatewayCallBack() {
-//                            @Override
-//                            public void onEnd(String error) {
-//
-//                            }
-//
-//                            @Override
-//                            public void onSuccess(GatewaySearchBean gatewaySearchBean) {
-//                                Log.i("TAG", "onSuccess: 鎼滅储鎴愬姛锛�"+gatewaySearchBean.getGatewayId());
-//                            }
-//                        });
 
 
                         break;
@@ -182,5 +183,93 @@
             }
         });
     }
+    public void showToast(String text) {
+        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
+    }
 
+
+    void checkIfCertified(){
+        boolean isCertified = HDLLink.getInstance().checkIfCertified();
+        showToast(isCertified?"宸茬粡璁よ瘉杩�":"鏈璇�");
+    }
+
+    /**
+     * 鍏ョ綉璁よ瘉
+     */
+    void sendAuthenticateRequest(){
+
+        String macStr = "AA000000000000BB";
+        String secret = "87ae414b7a853f65";
+        String mac_key = stringToMD5(stringToMD5(macStr + secret));
+
+        String versionString = "HDL_V1.0.1";
+        String time = String.valueOf(System.currentTimeMillis());
+
+        //1.璁剧疆璁よ瘉淇℃伅
+        AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean();
+        requestBean.setMAC(macStr);
+        requestBean.setSupplier("HDL");
+        requestBean.setFirmwareVersion(versionString);
+        requestBean.setHardwareModel("1956F");
+        AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean();
+        authbean.setSpk("ir.module");
+        authbean.setMACKey(mac_key);
+        authbean.setRequest(requestBean);
+
+        //2.璁剧疆璁惧淇℃伅
+        AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
+        infoBean.setDeviceMAC(macStr);
+        infoBean.setIPMAC(macStr);
+        infoBean.setDeviceName("HDL闈㈡澘");
+        infoBean.setDeviceModel("HDL");
+        infoBean.setAccessMode("WIFI");
+        infoBean.setIPAddress(IpUtils.getIP(this));
+
+
+        infoBean.setOID("010105000000FE08");
+        infoBean.setSid("010105000000FE08110100000000");
+//        infoBean.set
+        AuthenticateRequest.VersionBean[] versionBeans = new AuthenticateRequest.VersionBean[]{new AuthenticateRequest.VersionBean("FW", versionString), new AuthenticateRequest.VersionBean("HW", "1956F")};
+        infoBean.setVersions(versionBeans);
+        AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, infoBean, authbean);
+
+        String ip = IpUtils.getBroadcastAddress();
+//        ip = "192.168.10.102";
+
+        HDLLink.getInstance().sendAuthenticateRequest(ip, request, new HDLAuthSocket.CallBack() {
+            @Override
+            public void onError(String error) {
+                Log.i("TAG", "onError: 璁よ瘉澶辫触");
+            }
+
+            @Override
+            public void onSuccess(String data) {
+                tv.setText("璁よ瘉鎴愬姛");
+                responseTv.setText(data.toString());
+            }
+        });
+    }
+
+
+    String stringToMD5(String text) {
+        byte[] hash;
+        try {
+            hash = MessageDigest.getInstance("MD5").digest(text.getBytes("UTF-8"));
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+            return null;
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+            return null;
+        }
+
+        StringBuilder hex = new StringBuilder(hash.length * 2);
+        for (byte b : hash) {
+            if ((b & 0xFF) < 0x10)
+                hex.append("0");
+            hex.append(Integer.toHexString(b & 0xFF));
+        }
+
+        return hex.toString();
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0