Skip to main content

Getting Started

Public Parameters

Arcvideo Cloud's API (exclude Upload API) contains five public parameters: action, accessKey, version, timestamp and signature.

ParameterDescription
actionThe name of the API
accessKeyThe AccessKey of assigned to the user.
versionThe api version
timestampThe invoke time in milliseconds since january 1 1970.
signatureThe signature according to the Signature Rule below

Signature Generation

The signature string is generated by the following steps:

  1. Generate a string by sorting all parameters by name (CASE-INSENSITIVE-ORDER) and add accessSecret to the string header;
  2. Call the algorithm HmacSHA256 to generate a signature for the string;
  3. Each api generates a different signature based on the input parameters

Example

Let's use API: Get Account Information as an example to illustrate the generation of signatures, The five parameters of this interface are accessKey, action, version, timestamp, and signature: ​ accessSecret = "5GcXHNYdAVVdFW0yervG"

accessKey = "a020e193-0f1"
action = "getUser"
version = "2.0"
timestamp= "1466488681033"

then the signature value of the api is called:

signature = hmacSHA256Encrypt("5GcXHNYdAVVdFW0yervGaccessKey=a020e193-0f1action=getUsertimestamp=1466488681033version=2.0", "5GcXHNYdAVVdFW0yervG") = 3d864184117e240ad4def677c48fbba509a1d0d48ea5dfb9e914c587ae3ce5bf

Response Format

The API response value is in json format as follows:

{
"code": 0, // integer, error code (0 means success)
"message": "success", // string, error message or "success"
"result": ..., // string/json, return data
"success": true // boolean, true or false
}

Sample Code

Encryption

SHA256 Hmac signature generates a 64 bit string, as shown in the following code:

public static String hmacSHA256Encrypt(String plainText, String accessSecret) throws Exception {
Mac mac = Mac.getInstance("HmacSHA256");
byte[] secretByte = accessSecret.getBytes("UTF-8");
byte[] dataBytes = plainText.getBytes("UTF-8");
SecretKey secret = new SecretKeySpec(secretByte, "HMACSHA256");
mac.init(secret);
byte[] doFinal = mac.doFinal(dataBytes);
byte[] hexB = new Hex().encode(doFinal);
String signature = new String(hexB);
return signature;
}

Signature

public static String generateSignature(HashMap<String, Object> param, String secret) throws Exception {
if (StringUtils.isBlank(secret) || MapUtils.isEmpty(param)) {
return null;
}
List<String> keyList = new ArrayList<String>(param.keySet());
Collections.sort(keyList, String.CASE_INSENSITIVE_ORDER);
StringBuilder sb = new StringBuilder(secret);
for (String key :keyList) {
if (param.get(key) != null && !key.equals("signature")) {
sb.append(key);
sb.append("=");
sb.append(param.get(key));
}
}
String signature = hmacSHA256Encrypt(sb.toString(), secret);
return signature;
}

Api Calls

String ACCESSKEY = "a020e193-0f1";
String ACCESSSECRT = "5GcXHNYdAVVdFW0yervG";
String URI = "http://api-az-cn.danghongyun.com/rest?" ;
HashMap<String,String> params = new HashMap<String,String>();
params.put("accessKey", ACCESSKEY);
params.put("signature", generateSignature(params, ACCESSSECRT));
String request = createURL(URI, params);
String httpReslut = HttpUtil.get(request);
System.out.println(httpReslut);
return JSON.parseArray(httpReslut);