REST API 指南


获取 API Key 及文档

用户登录 FIT2CLOUD 云管平台后,点击 右上角工具链的用户头像后,进入 【API Key】页面,如下图所示:

用户可以创建一个或者多个 API Access Key 和 Secret Key。

点击【查看 API】,用户可以查询到平台各个模块所开放的所有 REST API,如下图所示。

API 调用示例代码(Java)

import javax.crypto.spec.SecretKeySpec;

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

import java.net.HttpURLConnection;

import java.net.URL;

import java.util.UUID;

/**

* Created by liqiang on 2018/10/18.

*/

public class ApiDemo{

static String accessKey = "psbbCe9qtW3laRBk";

static String secretKey = "ZdZ5nbhTBX6ShMb2";

public static void main(String[] args) {

try {

URL url = new URL("https://rdtest2.fit2cloud.com/dashboard/user/info");

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

urlConnection.setRequestProperty("Accept", "application/json;charset=UTF-8");

urlConnection.setRequestProperty("accessKey", accessKey);

String signature = aesEncrypt(accessKey + "|" + UUID.randomUUID().toString() + "|" + System.currentTimeMillis(), secretKey, accessKey);

urlConnection.setRequestProperty("signature", signature);

InputStream is = urlConnection.getInputStream();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

byte[] buffer = new byte[1024];

int len = 0;

while (-1 != (len = is.read(buffer))) {

baos.write(buffer, 0, len);

baos.flush();

}

System.out.println(urlConnection.getResponseCode());

System.out.println(baos.toString("utf-8"));

} catch (Exception e) {

e.printStackTrace();

}

}

public static String aesEncrypt(String src, String secretKey, String iv) throws Exception {

byte[] raw = secretKey.getBytes("UTF-8");

SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

IvParameterSpec iv1 = new IvParameterSpec(iv.getBytes());

cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, iv1);

byte[] encrypted = cipher.doFinal(src.getBytes("UTF-8"));

return Base64.encodeBase64String(encrypted);

}

}

results matching ""

    No results matching ""