1, access information
1.1 Request address
API request address: replace subPath with each API address.
| Node | Address | Request example |
|---|---|---|
| Domestic central node | https://castack-gncenter.cheersucloud.com/openapi/ | https://castack-gncenter.cheersucloud.com/openapi/{subPath} |
| Overseas central node | https://castack-hwcenter.cheersucloud.com/openapi/ | https://castack-hwcenter.cheersucloud.com/openapi/{subPath} |
1.2 Signature algorithm
-
Request header carries: X-ak:AK
-
URL must include timestamp and signature
-
Example: /openapi/v2/instance/page/list?time=1640494526&sign=*
- time: unit seconds, participates in calculating the sign value
- sign: calculated using AK, SK, and time with the corresponding encryption algorithm
- The platform provides AK and SK to users
- Encryption algorithm: sha256, key=SK, encryption code example is as follows
public static String ak = "f2fcddffd0de46da811414216c5b225c";
public static String sk = "a01d33f69000405cb3eb44143fa9cd11";
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
String url = "http://127.0.0.1:1800/openapi/v2/instance/page/list";
LocalDateTime now = LocalDateTime.now();
long data = now.toEpochSecond(ZoneOffset.UTC);
String hmacSHA256 = BaseTest.hmacSHA256(sk, String.valueOf(data));
String requestUrl = url + "?time=" + data + "&sign=" + hmacSHA256;
HttpRequest request = HttpUtil.createPost(requestUrl)
.header("Content-Type", "application/json")
.header("cache-control", "no-cache")
.header("X-ak", ak);
Map<String, Object> map = new HashMap<>();
map.put("pageNum", 1);
map.put("pageSize", 10);
request.body(JSON.toJSONString(map));
// 发送请求并获取响应
HttpResponse response = request.execute();
System.out.println(response.body());
}
public static String hmacSHA256(String key, String data) throws NoSuchAlgorithmException, InvalidKeyException {
// 获取一个 HMAC SHA-256 的 Mac 实例
Mac mac = Mac.getInstance("HmacSHA256");
// 创建一个 SecretKeySpec 实例
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
// 初始化 Mac 实例
mac.init(secretKeySpec);
// 执行 HMAC SHA-256 运算
byte[] rawHmac = mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
// 将原始字节数组转换为十六进制字符串
StringBuilder hexString = new StringBuilder();
for (byte b : rawHmac) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
1.3 Response specification
Response format:
| Parameter name | Parameter description | Whether to return | Data type | Description |
|---|---|---|---|---|
| code | Return code | Yes | interger(int32) | 200 indicates the response succeeded |
| message | Return processing message | Yes | string | |
| timestamp | Timestamp | Optional | integer(int64) | |
| traceId | Request processing ID | Optional | string | |
| result | Returned data object, encapsulating the specific data of the response | Yes | object |
http status code:
| Status code | Description | Description |
|---|---|---|
| 200 | OK | Result |
| 201 | Created | |
| 401 | Unauthorized | |
| 403 | Forbidden | |
| 404 | Not Found |
1.4 Calling notes
All the following request calls need to add this to the request header X-akandwrap, and add the time to the url address time and signature verification value sign
curl -X POST -H 'X-ak:3d17155dec2a4076ac8dbe500d53765c' -H 'wrap:false' -H 'Content-Type: application/json' http://192.168.130.241:1800/openapi/v2/instance/page/list?time=1720774436&sign=3bbf04e6c524bc028d543148ea55447cad066f896431980e01d80488d1212807 -d '{"pageNum":1,"pageSize":10,"projectId":"project_admin"}'
1.5 Data structure
Default return:
{
"body": {
"result": {/*返回根据接口功能的数据*/
...
},
"traceId": "C91320230805160421278",
"code": 200,
"message": "操作成功",
"timestamp": 1691222661324
},
"ret": {
"code": 200, /*200表示成功,非200表示错误*/
"msg": "操作成功"
}
}
Returned when the wrap parameter value in the request HEADER is false: