本示例介绍使用Alibaba Cloud SDK for Java调用EnableThing接口禁用设备。
前提条件
请在pom.xml文件中增加以下依赖,准确的SDK版本号,参见阿里云开发工具包(SDK)。
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>java.demo</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.4.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-iot -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-iot</artifactId>
<version>6.11.0</version>
</dependency>
</dependencies>
</project>
示例代码
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.iot.model.v20180120.EnableThingRequest;
import com.aliyuncs.iot.model.v20180120.EnableThingResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
public class TestEnableThing {
public static void main(String[] args){
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // 地域ID
"<your-access-key-id>", // 您的AccessKey ID
"<your-access-key-secret>"); // 您的AccessKey Secret
IAcsClient client = new DefaultAcsClient(profile);
// 创建请求接口
EnableThingRequest request = new EnableThingRequest();
// 要解禁的设备ID。
// 说明 如果传入该参数,则无需传入 ProductKey和 DeviceName。
// IotId作为设备唯一标识符,与 ProductKey和 DeviceName组合是一一对应的关系
// 。如果您同时传入 IotId和 ProductKey与 DeviceName组合,则以 IotId为准。
request.setIotId("yourIotId");
// 要解禁的设备所隶属的产品Key。
// 说明 如果传入该参数,需同时传入 DeviceName。
// request.setProductKey("yourProductId");
// 指定解禁的设备的名称。
// 说明 如果传入该参数,需同时传入 ProductKey。
// request.setDeviceName("yourDeviceName");
try {
// 发起请求并获取返回值
EnableThingResponse response = client.getAcsResponse(request);
// 处理业务逻辑
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
在文档使用中是否遇到以下问题
更多建议
匿名提交