下行 SDK 使用说明

1.1 RPC 调用 inner

1.1.1 添加依赖

  • 根据不同的 zk 环境,可以分别调用到开发环境、测试环境和正式环境
  • 通过内网仓库获取最新依赖
<dependency>
    <groupId>com.seewo.iot</groupId>
    <artifactId>iot-platform-service-api</artifactId>
    <version>${iot-platform-service-api.version}</version>
</dependency>

1.1.2 接口说明

  • 主要接口包括产品管理、设备管理、网关和子设备管理、设备标签管理、topic管理等。
  • 调用方在获取依赖的同时可以获取到源码,源码中对方法的使用有具体的解释。
  • 部分接口作了参数校验,采用的是hibernate-validator,若调用 RPC 报错,请留意是否为参数校验不通过。
  • 接口返回值统一为com.seewo.mis.common.response.BaseResponse<T>,该对象包含属性:
属性 类型 说明
code String 响应码: 6 位,调用成功为000000,参考系统错误码
message String 异常信息,若调用不成功,则此属性作为说明
data T 业务内容

1.2 HTTP 调用

  • HTTP调用方式不需要依赖dubbo环境,用户同样可以方便地调用不同环境的接口。
  • HTTP接口只包含常用接口,调用前需了解接口请求说明和签名检验方式,参考:HTTP接口文档
  • Java用户可使用封装的SDK,其他用户根据接口文档自行调用。

1.2.1 java SDK使用简介

  • 通过内网仓库获取最新依赖
<dependency>
    <groupId>com.seewo.iot.platform</groupId>
    <artifactId>iot-platform-sdk-api</artifactId>
    <version>${iot-platform-sdk-api.version}</version>
</dependency>
  • 调用接口
// 必要配置
IotPlatformApiProperties iotProperties = new IotPlatformApiProperties()
                .setUrl("请求基本地址,请查阅环境")
                .setIotAccessKey("your appKey")
                .setIotAppSecret("your appSecret");
IotPlatformApi iotPlatformApi = new IotPlatformApi(iotProperties);
// 初始化API
IotDeviceApi iotDeviceApi = iotPlatformApi.initService(IotDeviceApi.class);
IotTopicApi iotTopicApi = iotPlatformApi.initService(IotTopicApi.class);
IotTopologyApi iotTopologyApi = iotPlatformApi.initService(IotTopologyApi.class);

// 调用接口
BaseResponse<DataPage<DeviceListRespDto>> deviceList = iotDeviceApi.getDeviceList("", "", "", 1, 10);

System.err.println(deviceList);
  • 额外依赖

非maven引入依赖时,需手动添加以下依赖。间接依赖需自行排查。

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.26</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.58</version>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>3.14.0</version>
</dependency>