panlili2024
2025-03-05 db29d92c6974d50f0ebb9328834c44a69c6054bb
HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -35,6 +35,7 @@
import com.hdl.sdk.common.exception.HDLLinkException;
import com.hdl.sdk.common.utils.IdUtils;
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.SPUtils;
import com.hdl.sdk.common.utils.gson.GsonConvert;
import com.hdl.sdk.connect.HDLLink;
import com.hdl.sdk.connect.bean.LinkResponse;
@@ -44,6 +45,7 @@
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.BindInfoBean;
import com.hdl.sdk.connect.bean.response.GatewaySearchBean;
import com.hdl.sdk.connect.bean.response.UpdateInfo;
import com.hdl.sdk.connect.callback.HDLLinkCallBack;
@@ -51,8 +53,13 @@
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.cloud.bean.GatewayInfo;
import com.hdl.sdk.connect.cloud.listener.GatewayListener;
import com.hdl.sdk.connect.cloud.listener.SibichiListener;
import com.hdl.sdk.connect.cloud.bean.AiLoginInfo;
import com.hdl.sdk.connect.config.HDLLinkConfig;
import com.hdl.sdk.connect.socket.HDLAuthSocket;
import com.hdl.sdk.sourceos.utils.SPKey;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
@@ -79,21 +86,12 @@
    private List<SceneBean> sceneList = new ArrayList<>();
    private List<SceneDetailBean> sceneDetailList = new ArrayList<>();
    private List<SceneDetailBean> roomSceneList = new ArrayList<>();
    private GatewayInfo gatewayInfo;
    void applyDeviceSecret() {
        tv.setText("开始申请设备密钥...");
        responseTv.setText("");
//        //正式服务器
//        String appKey = "i8hR07jzrIS";//appkey
//        String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret
        //测试服务器
        String appKey = "FcRyUJlLJFF";
        String appSecret = "wz8wn75ABidx8vXcFGUotqhwFkTaYvvJ";
//        String appKey = "L2OZliZRxHc";
//        String appSecret = "aCIWSvJDOukXfx3kivsKW11x9xdR3IbV";
        String supplier = "JINMAOYUN";//厂商
//        String mac = "AA00000000000100";//设备唯一MAC地址
        String mac = editText.getText().toString();
@@ -103,8 +101,8 @@
            Toast.makeText(this, "mac不能为空!", Toast.LENGTH_SHORT).show();
            return;
        }
        HDLLink.getInstance().applyDeviceSecret(this, appKey, appSecret, supplier, mac, spk, new CallBackListener() {
        //调用云端接口需初始化HDLLink.getInstance().initCloud();
        HDLLink.getInstance().applyDeviceSecret(supplier, mac, spk, new CallBackListener() {
            @Override
            public void onError(HDLException e) {
                tv.setText("申请失败");
@@ -126,13 +124,10 @@
        tv.setText("开始检测更新...");
        responseTv.setText("");
//        //正式服务器
        String appKey = "i8hR07jzrIS";//appkey
        String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret
        String appCode = "1697150870315999233";//appCode
        HDLLink.getInstance().checkAppVersion(this, appKey, appSecret, getAppVersionName(this), appCode, new CheckAppVersionListener() {
        //调用云端接口需初始化HDLLink.getInstance().initCloud();
        HDLLink.getInstance().checkAppVersion(getAppVersionName(this), appCode, new CheckAppVersionListener() {
            @Override
            public void onSuccess(UpdateInfo info) {
                tv.setText("有新更新");
@@ -142,6 +137,59 @@
            @Override
            public void onError(HDLException e) {
                tv.setText("检测更新失败");
                responseTv.setText(e.getMsg());
            }
        });
    }
    void getSibichiToken() {
        tv.setText("获取思必驰token...");
        responseTv.setText("");
        BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO);
        String clientId = "4ED634B5A7AD97A770A52AC00FF43805";//思必驰clientId
        //调用云端接口需初始化HDLLink.getInstance().initCloud();
        HDLLink.getInstance().getSibichiToken(bindInfoBean.getHomeId(), clientId, new SibichiListener() {
            @Override
            public void onSuccess(AiLoginInfo info) {
                tv.setText("思必驰token");
                responseTv.setText(info.toString());
            }
            @Override
            public void onError(HDLException e) {
                tv.setText("获取思必驰token失败");
                responseTv.setText(e.getMsg());
            }
        });
    }
    void syncMainGateway() {
        tv.setText("获取主网关信息...");
        responseTv.setText("");
        BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO);
        if (bindInfoBean == null) {
            Toast.makeText(this, "请先扫码绑定住宅!", Toast.LENGTH_SHORT).show();
            return;
        }
        //调用云端接口需初始化HDLLink.getInstance().initCloud();
        HDLLink.getInstance().syncMainGateway(bindInfoBean.getHomeId(), new GatewayListener() {
            @Override
            public void onSuccess(GatewayInfo info) {
                tv.setText("获取主网关信息");
                responseTv.setText(info.toString());
                if (info != null) {
                    HDLLinkConfig.getInstance().setGatewayId(info.getGatewayId());
                }
            }
            @Override
            public void onError(HDLException e) {
                tv.setText("获取主网关信息失败");
                responseTv.setText(e.getMsg());
            }
        });
@@ -180,7 +228,7 @@
        selectnetwork();
        checkIfCertified();
        initDeviceInfo();//初始化
        //initDeviceInfo();//不走从机入网的方式不需要初始化
        registerAllTopicsListener();
        HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() {
            @Override
@@ -226,6 +274,9 @@
        beans.add(new DemoBean("获取房间场景列表"));
        beans.add(new DemoBean("获取自动化列表"));
        beans.add(new DemoBean("⾃动化启⽤禁⽤"));
        beans.add(new DemoBean("生成二维码绑定住宅"));
        beans.add(new DemoBean("获取思必驰token"));
        beans.add(new DemoBean("获取网关信息"));
        demoAdapter = new DemoAdapter(beans);
        rv.setAdapter(demoAdapter);
@@ -313,6 +364,18 @@
                    case 19:
                        //⾃动化启⽤禁⽤
                        editEnableLogic();
                        break;
                    case 20:
                        //生成二维码绑定住宅
                        startSourceBindActivity();
                        break;
                    case 21:
                        //获取思必驰token
                        getSibichiToken();
                        break;
                    case 22:
                        //获取网关信息
                        syncMainGateway();
                        break;
                }
            }
@@ -418,6 +481,20 @@
    }
    void initLink() {
        //step1:先生成二维码,用onpro扫码绑定住宅获取住宅信息
        BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO);
        if (bindInfoBean != null) {
            HDLLinkConfig.getInstance().setHomeId(bindInfoBean.getHomeId());
            HDLLinkConfig.getInstance().setLocalSecret(bindInfoBean.getLocalSecret());
        }
        //step2:再获取网关信息
        if (gatewayInfo != null) {
            HDLLinkConfig.getInstance().setGatewayId(gatewayInfo.getGatewayId());//当前主网关id
        }
    }
    /**
     * 入网认证
     */
@@ -425,15 +502,9 @@
        tv.setText("开始入网认证...");
        //认证提交参数准备
//        测试服务
//        String spkStr = "ir.module";//产品spk
//        String macStr = "AA000000000000AF";//设备唯一MAC地址
//        String secret = "44b360eb74b7ba64";//通过spk和mac提交云端认证后分配的secret
//        正式服务器
        //正式服务器
        String spkStr = "screen.mirror";//产品spk
        String macStr = "f2c5d8bad48f";//设备唯一MAC地址
//        String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的secret
        String mac_key = stringToMD5(stringToMD5(macStr + secret));
        String versionString = "HDL_V1.0.1";//
@@ -560,7 +631,12 @@
        tv.setText("设备功能属性读取");
        responseTv.setText("");
        List<String> sids = new ArrayList<>();
        sids.add(testLightSid);
        if (devicesList.size() != 0) {
            sids.add(devicesList.get(0).getSid());
        } else {
            sids.add(testLightSid);
        }
        HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
@@ -582,7 +658,11 @@
        tv.setText("读取状态中...");
        responseTv.setText("");
        List<String> list = new ArrayList<>();
        list.add(testLightSid);//要读取设备的sid
        if (devicesList.size() != 0) {
            list.add(devicesList.get(0).getSid());
        } else {
            list.add(testLightSid);//要读取设备的sid
        }
        HDLLink.getInstance().propertyRead(list, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String data) {
@@ -608,7 +688,11 @@
        isOn = !isOn;
        List<DeviceControlRequest> requestList = new ArrayList<>();
        DeviceControlRequest request = new DeviceControlRequest();
        request.setSid(testLightSid);
        if (devicesList.size() != 0) {
            request.setSid(devicesList.get(0).getSid());
        } else {
            request.setSid(testLightSid);//要读取设备的sid
        }
        List<DeviceControlRequest.StatusBean> statusBeanList = new ArrayList<>();
        DeviceControlRequest.StatusBean bean = new DeviceControlRequest.StatusBean();
        bean.setKey("on_off");
@@ -873,7 +957,7 @@
    void getRoomSceneList() {
        tv.setText("获取房间场景列表");
        responseTv.setText("");
        String uid = "64a4fc6f-4eae-4d1d-82e4-40140c802c48";
        String uid = "64a4fc6f-4eae-4d1d-82e4-40140c802c48";//房间uid
        roomSceneList.clear();
        if (sceneDetailList != null && sceneDetailList.size() != 0) {
@@ -905,6 +989,11 @@
        startActivity(intent);
    }
    void startSourceBindActivity() {
        Intent intent = new Intent(this, SourceBindActivity.class);
        startActivity(intent);
    }
    /**
     * TCP发送 只发一次,不监听回复,不重发
     */