物接入IoT Hub

    权限组管理

    创建权限组

    CreateDomainRequest request = new CreateDomainRequest()
            .withName("domainTest")                // 设置权限组名字
            .withType(Domain.DomainType.NORMAL)    // 设置权限组类型
            .withDescription("domain description");  // 设置权限组描述
     
    AccessDetailResponse response = client.createDomain(request);
     
    String userName = response.getUsername(); // tcp协议的物接入endpoint
    String tcpEndpoint = response.getTcpEndpoint(); // 支持ssl的物接入endpoint
    String sslEndpoint = response.getWssEndpoint(); // 支持wss的物接入endpoint
    String key = response.getKey(); // 物接入Thing密钥

    删除权限组

    client.removeDomain("domainTest");

    获取权限组列表

    int pageNo = 1;
    int pageSize = 10;
    String orderBy = "name";
    DomainListResponse response = client.getDomains(pageNo, pageSize, orderBy, null, null, null, null);
    Domain domain = response.getDomains().get(0);
    String name = domain.getName(); // 权限组名称
    Domain.DomainType type = domain.getType(); // 权限组类型
    int deviceNum = domain.getDeviceNum(); // 权限组包含的设备数
    String description = domain.getDescription(); // 权限组描述
    long createTime = domain.getCreateTime(); // 权限组创建的时间
    long lastUpdatedTime = domain.getLastUpdatedTime(); // 权限组更新的时间

    获取权限组详情

    DomainDetail domainDetail = client.getDomainDetail("domainTest");
    String name = domainDetail.getName(); // 权限组的名称
    List<String> devices = domainDetail.getDevices(); // 设备列表
    Domain.DomainType type = domainDetail.getType(); // 权限组类型
    int deviceNum = domainDetail.getDeviceNum(); // 设备数量
    String description = domainDetail.getDescription(); // 权限组描述
    long createTime = domainDetail.getCreateTime(); // 创建时间
    long lastUpdatedTime = domainDetail.getLastUpdatedTime(); // 最后更新时间

    权限组中更改设备

    client.removeDomain("domainTest");
    List<String> addList = new ArrayList<String>(1);
    addList.add("deviceName1");
    List<String> removedList = new ArrayList<String>(1);
    removedList.add("deviceName2");
    UpdateDomainDevicesRequest request = new UpdateDomainDevicesRequest();
    request.setAddedDevices(addList);
    request.setRemovedDevices(removedList);
    UpdateDomainDevicesResponse response = client.modifyDomainDevices("domainTest", request);
    List<String> addedDevices = response.getAddedDevices(); // 成功添加的设备名称列表
    List<String> removedDevices = response.getRemovedDevices(); // 成功移除的设备名称列表

    更新权限组注册信息

    UpdateDomainRegistryInfoRequest request = new UpdateDomainRegistryInfoRequest();
    request.setDescription("new domain description");
    client.modifyDomainRegistryInfo("domainTest", request); // 更新对应名称的domain的描述信息

    获取权限组接入信息

    AccessDetailResponse accessDetailResponse = client.getDomainAccessDetail("domainTest");
    accessDetailResponse.getUsername(); // endpointName/thingName
    accessDetailResponse.getTcpEndpoint(); // tcp协议的物接入endpoint
    accessDetailResponse.getSslEndpoint(); // ssl协议的物接入endpoint
    accessDetailResponse.getWssEndpoint(); // wss的物接入endpoint
    accessDetailResponse.getKey(); // 物接入Thing密钥

    更新权限组密钥

    AccessDetailResponse accessDetailResponse = client.updateDomainSecretKey("domainTest");
    accessDetailResponse.getUsername(); // endpointName/thingName
    accessDetailResponse.getTcpEndpoint(); // tcp协议的物接入endpoint
    accessDetailResponse.getSslEndpoint(); // ssl协议的物接入endpoint
    accessDetailResponse.getWssEndpoint(); // wss的物接入endpoint
    accessDetailResponse.getKey(); // 物接入Thing密钥

    获取及查询设备列表

    int pageNo = 1;
    int pageSize = 10;
    String order = "asc";
    String orderBy = "name";
    DomainDeviceListResponse domainDeviceListResponse = client.getDomainDeviceList("domainTest", pageNo, pageSize, orderBy, order, null, null, null);
    int amount = domainDeviceListResponse.getAmount(); // 设备总数
    List<DeviceInDomain> devices = domainDeviceListResponse.getDevices(); // 设备列表
    DeviceInDomain devicesInDomain = devices.get(0);
    String deviceName = devicesInDomain.getDeviceName(); // 设备名称
    boolean existed = devicesInDomain.getExisted(); // 是否存在于改权限组内
    int domainNum = devicesInDomain.getDomainNum(); // 设备被包含在不同权限组内的数目
    上一篇
    模板管理
    下一篇
    规则引擎