用前必读
介绍如何使用API。
使用API前请必读,本章将介绍如何使用API
API网关地址:api.link.aliyun.com
在API参考中您可以查看到需要调用的API列表

点击进入具体API介绍后,您可以看到对应接口路径、版本号、请求参数等
AppKey的获取及授权
有两个地方:
在数字工厂中可以创建AppKey/AppSecret以及对AppKey进行访问授权
设置->阿里生态->通用系统对接配置

应用托管
物联网应用托管服务会为应用颁发AppKey/AppSecret
详情见https://help.aliyun.com/document_detail/114818.html
JAVA调用示例
参考 SDK 章节
package com.aliyun.iotapigateway;
import com.aliyun.iotapigateway.models.CommonParams;
import com.aliyun.iotapigateway.models.Config;
import com.aliyun.iotapigateway.models.IoTApiRequest;
import com.aliyun.tea.TeaResponse;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
public class ClientTest {
@Test
public void apiTest() throws Exception{
Config config = new Config();
config.appKey = System.getenv("IOT_APP_KEY");
config.appSecret = System.getenv("IOT_APP_SECRET");
config.domain = "api.link.aliyun.com";
Client client = new Client(config);
Map<String, Object> params = new HashMap<>();
params.put("id", 1);
CommonParams req = new CommonParams();
req.apiVer = "1.0.0";
IoTApiRequest body = new IoTApiRequest();
body.params = params;
body.request = req;
RuntimeOptions runtime = new RuntimeOptions();
TeaResponse teaResponse = client.doRequest("/industry/factorycalendar/plannedshutdown/getbyid", "HTTPS",
"POST", null, body, runtime);
Object obj = Common.readAsJSON(teaResponse.body);
Map<String, Object> result = Common.assertAsMap(obj);
System.out.println(JSON.toJSONString(result, true));
}
}
出参示例:
# 未授权
{
"code":403.0,
"id":"481bdcaf-3bdb-4fc1-b154-022e1878e68316558028952621",
"localizedMsg":"请求被禁止",
"message":"request forbidden."
}
# 业务错误
{
"code":500.0,
"id":"36826d3b-2df9-4005-a7dc-70a369233e7e16558037360011",
"localizedMsg":"服务端错误",
"message":"can't find record by id:1"
}
# 成功
{
"id": "4de2c367-c1db-417c-aa15-8c585e595d92",
"code": 200,
"message": null,
"localizedMsg": null,
"data": {
"id": 1,
"ftyModelId": 123,
"ftyModelValue": 1,
"name": "周末",
"type": 2,
"dayOfWeek": 7,
"beginTime": "08:00:00",
"endTime": "16:00:00",
"description": "周日休息一天"
}
}
出参JSON对象介绍
KEY | VALUE | 是否可选 | 说明 |
code | 403 200 | 必选 | 返回码 403 表示appKey未授权,需要对该AppKey进行API授权 200 表示业务调用成功 |
message | "request forbidden." "success" | 可选 | 返回值的说明 |
data | JSON对象 | 可选 | 返回的业务对象 详情见API介绍中的"返回数据" |