综述:

物联网应用中台致力于快速构建IoT场景智能化解决方案。结合平台预集成的大量行业智能硬件和软件,并协同阿里云及生态的力量,实现数字社区的相关应用及解决方案的能力的交付,相关操作流程如下图所示。

1. SI应用服务平台产品设备创建

1.1 创建AIBOX产品与摄像头产品

登录阿里云应用服务平台,“设备管理 - 产品 - 创建产品”,如下图所示。

1.1.1 AIBOX产品

注意:在创建AIBOX产品时,所属品类请选择“标准品类:边缘计算/视频内容分析”,节点类型请选择“网关设备”,如下图所示。

1.1.2 摄像头产品

注意:在创建摄像头产品时,所属品类请选择“标准品类:智能生活/家居安防/摄像头”,节点类型请选择“直连设备”,如下图所示。

1.2 创建AIBOX设备与摄像头设备

登录阿里云应用服务平台,“设备管理 - 设备 - 添加设备”,如下图所示。

1.2.1 AIBOX设备

注意:在产品选择一栏,选择之前在1.1.1流程中创建的AIBOX产品,如下图所示。

1.2.2 摄像头设备

注意:在产品选择一栏,选择之前在1.1.2流程中创建的摄像头产品。

在这里添加设备的方式有两种:添加设备(单台设备添加)和批量添加,这里我们选择批量添加,如下图所示。

添加完成后点击“下载设备证书”(下载好的设备证书 都以“.csv”结尾,例如“设备证书.csv”),如下图所示。

1.2.3 设备三元组介绍

在之后的流程中,会多次提及到的“设备三元组”,具体的查看方式:在“设备”中,选择想要获取设备三元组的设备,点击查看,如下图所示。

ProductKey、DeviceName、DeviceSecret三个数据即为设备唯一标识,本篇文档中统称为设备三元组,如下图所示。

2. AIBOX控制台设备操作

2.1 登录AIBOX控制台

登录边缘控制台:即AIBOX的IP + 端口8080进行登录访问。

注意:主机网络需要和设备在同一个网段下。

登录的账号密码:admin/admin

登录后可进行设备的相关配置操作,如下图所示。

2.2 添加本地摄像头

初始化的AIBOX不包含任何设备,您需要将您的IPC设备加入到AIBOX中,点击“设备管理 - 添加设备”进行设备信息的相关配置,如下图所示。

添加设备的弹出菜单,设备名称为自定义,请根据实际需要自行定义。

设备类型目前支持设备和网关两种。如您需要通过接入NVR等网关设备来接入挂载的IPC,则选择“网关”,如直接接入IPC设备则选择“设备“即可。

协议类型目前支持国标、ONVIF两种标准协议和海康、大华、宇视(暂未上线正式版本)私有协议,以及rtsp直接接入。

2.2.1 国标设备

以海康的摄像头为例(大华、宇视等基本类似),如下图所示。

2.2.2 ONVIF设备

与国标一致,在摄像头参数中确认ONVIF信息,需要在控制台上填入IP、 端口、用户名和密码。

2.3 算法任务管理

AIBOX为很多算法提供了SaaS应用及相应的界面,在SaaS应用中,您可以很方便的配置不同算法独有的参数,查看算法实时和历史结果,如下图所示。

介绍如何给摄像头配置算法

2.4 设备上云

将获取的AIBOX三元组导入控制台,即可使AIBOX在云端上线。

在“上云配置 - 设置三元组”栏目中,点击“上传三元组 - 文件上传”可以导入您从云端获取到的摄像头三元组到AIBOX中(“文件上传”中的文件选择我们在之前1.2.2步骤中下载好的“设备证书.csv”即可),如下图所示。

2.5 本地摄像头设备和设备三元组映射

选择“摄像头身份 - 编辑”,进行本地设备与云端设备身份映射,如下图所示。

选择相对应的云端设备三元组后点击确定进行匹配,匹配成功后云端身份显示“已分配”,如下图所示。

3. SI应用服务平台项目配置

3.1 创建项目

登录阿里云应用服务平台创建“数字社区”项目,如下图所示。

3.1.1 完善项目信息

  • 基础信息:填写项目名称、部署环境(选择公有云)、项目时间、相关人员信息等,如下图所示。
  • 能力:选择数字社区能力,点击提交,如下图所示。

注意:“数字社区布防服务”和“数字社区实人认证”是需要管理员审批的,需要开通请联系管理员审批。

3.2 项目绑定设备

打开创建好的数字社区项目,项目状态选择“集成态”,点击“设备管理”模块,进行设备绑定,如下图所示。

点击“绑定设备”,选择需要绑定的设备,完成设备和项目的绑定,如下图所示。

3.3 获取AppKey和AppSecret

项目状态选择“开发态”,我们可以获取到“AppKey和AppSecret”,这两对数值是项目在SI应用服务平台的唯一标识,可用于之后的API接口调用的鉴权(API接口调用请看流程“5.数字社区API接口调用”),如下图所示。

4. 数字社区入驻

4.1 申请入驻数字社区管理平台

请注意,入驻成功后不要通过页面上的创建小区等功能进行操作,请使用接口对小区进行创建。

**

5. 数字社区API接口调用

5.1 小区管理API示例

5.1.1 获取POID列表

/solution/community/paas/poid/query 1.0.0 获取小区piod列表

示例代码:

/**
 * 数字社区--用户组管理--获取POID列表API
 *
 * @author wangkai
 *返回示例: "{"parent":"B023B0A9PY","address":"紫荆花路69号","distance":[],"biz_ext":{"cost":[],"rating":[]},"pname":"浙江省","importance":[],"biz_type":[],"cityname":"杭州市","type":"地名地址信息;门牌信息;楼栋号","photos":[],"typecode":"190403","shopinfo":"2","poiweight":[],"childtype":"308","adname":"西湖区","name":"桂花城紫云苑5幢","location":"120.091789,30.281922","tel":[],"shopid":[],"id":"B023B19DJA"}",
 */
public class CommunityGetPoidTest {
    private final static String appKey = "30239797";//项目的Appkey
      private final static String appSecret = "****************";//项目的Appsecret
    private final static String iotGatewayHost = "api.link.aliyun.com";//固定请求网关路由

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.putParam("keywords", "九龙");
        request.putParam("city", "香港");
        request.putParam("citylimit", true);
        request.putParam("pageSize", 20);
        request.putParam("pageNo", 5);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/poid/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }

返回示例:

其中id的返回值即为piod。

5.1.2 创建小区

/solution/community/paas/community/apply 1.0.0 创建小区

示例代码:

/**
 * 创建小区【需审核】
 */
public class CommunityApplyTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.putParam("poid", "B0FFF0EG44");
        request.putParam("name", "九龙站宾馆");
        request.putParam("address", "金龙楼(九龙城道)");
        request.putParam("serviceStartTime", "2020-06-18");
        request.putParam("serviceEndTime", "2020-07-18");
        request.putParam("certificate", "http://store.is.autonavi.com/showpic/b357310b426d30bd596b4244e04d9f2b");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/community/apply", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }

返回示例:

5.1.3 获取小区列表

/solution/community/paas/community/query 1.0.0 获取小区列表

示例代码:

/**
 * 获取小区列表
 */
public class CommunityQueryTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        //request.putParam("projectId", "a124sMKXmb6CWBL2");
        //request.putParam("applyStatus", "2");
        //request.putParam("pageSize", 20);
        //request.putParam("pageNo", 5);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/community/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }

返回示例:

5.1.4 查询小区信息【包括审核状态】

/solution/community/paas/community/detail/get 1.0.0 获取小区详情

示例代码:

/**
 * 查询小区信息
 */
public class CommunityGetDetailTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.putParam("communityId", "1504");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/community/detail/get", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.1.5 根据设备查询小区信息

/solution/community/paas/device/community/get 1.0.0 根据项目Id获取

示例代码:

/**
 * 根据设备查询小区信息
 */
public class DeviceCommunityGetTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
       String deviceIdentityDTO="{'type' : 'PK_AND_DN','iotId' : '','productKey' : 'a12BH8167id' ,'deviceName' : 'edgebox-014addc8'}";
        request.putParam("deviceIdentity", JSON.parse(deviceIdentityDTO));
        System.out.println(request);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/device/community/get", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.2 数字社区小区鉴权API

5.2.1 获取小区授权token

/solution/community/paas/token/get POST 1.0.0 获取云端资源Token;该接口对于同一个res(小区id,参见请求参数说明)在token失效前仅需要调用一次,如果再次调用,则会生成新的cloudToken,并会导致之前的cloudToken失效

示例代码:

/**
 * 获取小区授权token
 */
public class PaasTokenGetTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        Long communityId= Long.valueOf(1504);
        request.putParam("communityId", communityId);
        //request.putParam("appid", "12p3ii-4i1-49-1230");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/token/get", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }

}

返回示例:

5.2.2 刷新小区授权token

/solution/community/paas/token/refresh 1.0.0 刷新云端Token

请求示例:

/**
 * 刷新小区授权token
 */
public class PaasTokenRefreshTets {
    private final static String appKey = "30239797";
     private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.putParam("cloudToken", "db004377afcd46e8a71f043b6971daa6");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/token/refresh", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }

返回示例:

5.3 图片上传API

5.3.1 获取图片上传ticket

/solution/community/oss/ticket/get 1.0.1 获取oss上传图片ticket

示例代码:

/**
 * 数字社区--用户组管理--新建用户组API
 *
 * @author wangkai
 */
public class AddGroupTest {
    private final static String appKey = "30239797";
     private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.1");
        request.putParam("type", "picture");

        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/oss/ticket/get", request, true);
        JSONObject data = JSON.parseObject(new String(response.getBody(), StandardCharsets.UTF_8));
        JSONObject keys = data.getJSONObject("data");
    }
}

返回示例:

其中data的值即为返回的ticket信息

{"accessId":"LTAI7HWGDtXi9VqD","signature":"GWMUuwa0JJy6TdHjlvr+wz+RNjA=","expire":1594184353,"host":"iotx-homelink-aquarius-prd.oss-cn-hangzhou.aliyuncs.com","dir":"4AF52878CE8B4AC5A8F9D8CCF2902C8B/picture/1c1145e0ebee47e4a2c9160f2f27cdca","policy":"eyJleHBpcmF0aW9uIjoiMjAyMC0wNy0wOFQwNDo1OToxMy43NjZaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCI0QUY1Mjg3OENFOEI0QUM1QThGOUQ4Q0NGMjkwMkM4Qi9waWN0dXJlLzFjMTE0NWUwZWJlZTQ3ZTRhMmM5MTYwZjJmMjdjZGNhLyJdXX0="}

获取oss上传的授权后,采用http的post请求向oss上传图片文件

public static String upload2(File file, String host, String dir, String policy,
                               String accessKeyId, String signature)
            throws ClientProtocolException, IOException {
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        CloseableHttpResponse httpResponse = null;
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(200000)
                .setSocketTimeout(200000000).build();
        HttpPost httpPost = new HttpPost(host);
        httpPost.setConfig(requestConfig);
        MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
        multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
        multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        //处理文件名乱码
        ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8);

        multipartEntityBuilder.addTextBody("key", dir + "/" + file.getName(), contentType);
        multipartEntityBuilder.addTextBody("policy", policy);
        multipartEntityBuilder.addTextBody("OSSAccessKeyId", accessKeyId);
        multipartEntityBuilder.addTextBody("success_action_status", "200");
        multipartEntityBuilder.addTextBody("callback", "");
        multipartEntityBuilder.addTextBody("signature", signature);
        multipartEntityBuilder.addBinaryBody("file", file);

        HttpEntity httpEntity = multipartEntityBuilder.build();
        httpPost.setEntity(httpEntity);

        httpResponse = httpClient.execute(httpPost);
        HttpEntity responseEntity = httpResponse.getEntity();
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(responseEntity.getContent()));
            StringBuffer buffer = new StringBuffer();
            String str = "";
            while (!StringUtils.isEmpty(str = reader.readLine())) {
                buffer.append(str);
            }
            System.out.println(buffer.toString());
        }

        httpClient.close();
        if (httpResponse != null) {
            httpResponse.close();
        }

        // 返回oss中的目录文件地址
        return dir + "/" + file.getName();
    }

5.4 数字社区用户管理API

5.4.1 新建用户组

/solution/community/paas/user/group/add 1.0.0 新建用户组

示例代码:

/**
 * 数字社区--用户组管理--新建用户组API
 *
 * @author wangkai
 */
public class AddGroupTest {
    private final static String appKey = "30239797";
     private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        Long communityId= Long.valueOf(1504);
        request.setCloudToken("3ffd38999f0649dea102affc9397f4ee");
        request.putParam("communityId", communityId);
        request.putParam("userGroupName", "王凯");
        request.putParam("userGroupType", "RESIDENT");

        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/add", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

其中data的值即为userGroupId(用户组id)

5.4.2 更新用户组

/solution/community/paas/user/group/update 1.0.0 更新用户组

请求示例:

/**
 * 更新用户组
 */
public class UpdateGroupTest {
    private final static String appKey = "30239797";
     private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.setCloudToken("3ffd38999f0649dea102affc9397f4ee");
        request.putParam("userGroupName", "王凯02");
        request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/update", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }

返回示例:

5.4.3 删除用户组

/solution/community/paas/user/group/delete 1.0.0 删除用户组

请求示例:

/**
 * 删除用户组
 */
public class DeleteGroupTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.setCloudToken("3ffd38999f0649dea102affc9397f4ee");
        request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/delete", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.4.4 查询用户组

/solution/community/paas/user/group/query 1.0.0 查询用户组

请求示例:

/**
 * 删除用户组
 */
public class DeleteGroupTest {
    private final static String appKey = "30239797";
   private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.setCloudToken("3ffd38999f0649dea102affc9397f4ee");
        request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/delete", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.4.5 添加用户

path 版本 描述
/solution/community/paas/user/add 1.0.0 添加用户

请求示例:

/**
 * 添加用户
 */
public class UserAddTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.setCloudToken("3ffd38999f0649dea102affc9397f4ee");
        request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");
        request.putParam("userName", "李白");
        request.putParam("mobile", "18658822801");
        //request.putParam("idNo", "xzxxxx");
        request.putParam("sex", 2);
        request.putParam("age", 22);
        //  request.putParam("faceImageUrl", "https://iotx-homelink-aquarius-prd.oss-cn-hangzhou.aliyuncs.com/59FBB8C4DE304F29A1626B96B2DE7096/faceimage/43339b66b592413681c2ece668e6587e/lALPD3lGqxlIEyrM0s0BJg_294_210.png_720x720g.jpg");
    request.putParam("faceImageUrl", "59FBB8C4DE304F29A1626B96B2DE7096/faceimage/43339b66b592413681c2ece668e6587e/lALPD3lGqxlIEyrM0s0BJg_294_210.png_720x720g.jpg");

       ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/add", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.4.6 用户组添加用户

/solution/community/paas/user/group/member/add 1.0.0 用户组添加用户

请求示例:

/**
 * 用户组添加用户
 */
public class GroupMemberAddTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");
        request.putParam("identityId", "50cb0A852dd16143fe34294606f1dbee16e40006");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/member/add", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.4.7 小区用户查询

/solution/community/paas/user/query 1.0.0 小区用户查询

请求示例:

/**
 * 小区用户查询
 */
public class UserQueryTest {
    private final static String appKey = "30332082";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.putParam("communityId", 1504L);
        request.setCloudToken("65252cabdaa14cb19cf004f9b79996dd");
        //request.putParam("identityId", "141241");
        //request.putParam("faceId", "3423463fss");
        //request.putParam("userName", "桂花城");
        //request.putParam("faceImageUrl", "3242342");
        //request.putParam("idNo", "1321414124");
        //request.putParam("age", 23);
        //request.putParam("sex", 1);
        //request.putParam("mobile", "18658822801");
        request.putParam("pageSize", 20);
        request.putParam("pageNo", 1);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.5 数字社区设备API

5.5.1 添加设备到小区

/solution/community/paas/device/add 1.0.0 添加设备到小区

请求示例:

/**
 * 添加设备到小区
 */
public class DeviceAddTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        Long communityId= Long.valueOf(1504);
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("communityId", communityId);
        String deviceIdentity="{'type' : 'PK_AND_DN','productKey' : 'a12BH8167id' ,'deviceName' : 'edgebox-014addc8'}";
        request.putParam("deviceIdentity", JSON.parse(deviceIdentity));
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/device/add", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.5.2 小区设备列表

/solution/community/paas/device/query 1.0.0 小区设备列表

请求示例:

/**
 * 小区设备列表
 */
public class DeviceQueryTest {
    private final static String appKey = "30239797";
  private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        Long communityId= Long.valueOf(1504);
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("communityId", communityId);
        request.putParam("pageNo", 5);
        request.putParam("pageSize", 20);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/device/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.5.3 租户设备列表

/solution/community/paas/tenant/device/query 1.0.0 租户设备列表

请求示例:

/**
 *租户设备列表
 */
public class TenantDeviceQueryTest {
    private final static String appKey = "30239797";
   private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        request.putParam("queryType", "OWNED");
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("pageNo", 5);
        request.putParam("pageSize", 20);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/tenant/device/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.5.4 查询推流地址

/vision/stream/query 2.0.0 查询推流地址

请求示例:

/**
 * 查询推流地址
 */
public class VisionStreamQueryTest {
    private final static String appKey = "30239797";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("2.0.0");
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("iotId", "23121421421");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/vision/stream/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.5.5 获取录像记录

/vision/record/query 2.0.0 获取录像记录

请求示例:

/**
 * 获取录像记录
 */
public class VisionRecordQueryTest {
    private final static String appKey = "30239797";
  private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("2.0.0");
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("iotId", "23121421421");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/vision/record/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.5.6 获取历史文件播放地址

/vision/vod/getbyfilename 2.0.0 获取录像记录播放地址

请求示例:

/**
 * 获取历史文件播放地址
 */
public class VisionRecordQueryTest {
    private final static String appKey = "30239797";
     private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("2.0.0");
        request.setCloudToken("cfc08a3e8ff446548171b9ae48dd58a8");
        request.putParam("iotId", "23121421421");
        request.putParam("fileName", "xxxx1231jjadxx");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/vision/record/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(),
            "UTF-8"));
    }
}

返回示例:

5.6 数字社区布防服务API

5.6.1 AIBOX用户组布防

/solution/community/paas/user/group/deploy 1.0.0 用户组布防

请求示例:

/**
 * AIBOX用户组布防
 */
public class deployTest {
    private final static String appKey = "30332082";
    private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        //request.setCloudToken("9e3c9efa1f194d11bc20872daaeccd1d");
        request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");//
        request.putParam("iotId", "Tr9WBsRq15TmnhYUFV8v000000");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/deploy", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.6.2 小区布防记录查

请求方式 post
接口版本 1.0.0

请求示例:

/**
 * 小区布防记录查询
 */
public class queryTest {
    private final static String appKey = "30332082";
   private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);
        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        //request.setCloudToken("05647c0487134eeeb64752a2115c8a62");
        //request.putParam("userGroupId", "0vMh1RKgJQqkZtsu1ZBTa0jwG3KAntp5");
        request.putParam("communityId", 1504L);
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/solution/community/paas/user/group/deploy/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.7 数字社区人行服务API

5.7.1 人行轨迹检索

/home/face/user/trace/query 1.0.0 人行轨迹检索

请求示例:

/**
 * 人行轨迹检索
 */
public class UserTraceQueryTest {
    private final static String appKey = "30239797";
     private final static String appSecret = "****************";
    private final static String iotGatewayHost = "api.link.aliyun.com";

    public static void main(String[] args) throws UnsupportedEncodingException {
        IoTApiClientBuilderParams ioTApiClientBuilderParams =
            new IoTApiClientBuilderParams();
        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);
        SyncApiClient syncClient = new SyncApiClient(ioTApiClientBuilderParams);

        IoTApiRequest request = new IoTApiRequest();
        //设置api的版本
        request.setApiVer("1.0.0");
        long now = System.currentTimeMillis();
        long period = (1000*60*60*24)*365;
        long start = (now-period);
        long end = (now-period)+24;
        request.putParam("startTM", start);
        request.putParam("endTM", end);
        request.putParam("faceId", "50800A187b22c53ca3ca80a987e6c3b58c5b8152");
        ApiResponse response = syncClient.postBody(iotGatewayHost,
            "/home/face/user/trace/query", request, true);
        System.out.println("response code = " + response.getCode() + " response = " + new String(response.getBody(), "UTF-8"));
    }
}

返回示例:

5.7.2 人行数据订阅

实时订阅人行数据,用于业务层做流程组装。

CustomerFlowBasicFaceData 1.1

请求示例:

/**
 * 人行数据订阅
 */
public class CustomerFlowBasicFaceTopic {
    private final static String appKey = "30332082";
    private final static String appSecret = "****************";
    private final static String endPoint = "https://%s.iot-as-http2.cn-shanghai.aliyuncs.com:443";

    public static void main(String[] args) {
        String endpoint = String.format(endPoint, appKey);
        // 连接配置
        Profile profile = Profile.getAppKeyProfile(endpoint, appKey, appSecret);
        // 构造客户端
        MessageClient client = MessageClientFactory.messageClient(profile);

        // 数据接收
        client.connect(messageToken -> {
            System.out.println(messageToken.getMessage());
            JSONObject jsonObject = JSON.parseObject(new String(messageToken.getMessage().getPayload()));
            return MessageCallback.Action.CommitSuccess;
        });

        try {
            Thread.sleep(1000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        MessageCallback messageCallback = new MessageCallback() {
            @Override
            public Action consume(MessageToken messageToken) {
                Message m = messageToken.getMessage();
                System.out.println("++++++++"+m);
                return Action.CommitSuccess;
            }
        };
        String topic = String.format("/sys/%s/dop/model/data/change", appKey);
        client.setMessageListener(topic, messageCallback);
    }
}

返回示例: