Skip to main content

Signing Overview

Our signature algorithm.

We recommend using our ready-made SDKs or modules
If we already provide an SDK for your language (PHP, Python, NodeJS, Golang, or Java), we do not recommend re-implementing the signature yourself.
Developing directly with the SDK saves you a lot of integration work.

Integrating on your own
If you insist on implementing the signature yourself, we strongly recommend using this debugger to verify it:

SDK

Modules & Plugins

We provide plugin modules that help you integrate with our product faster.

1. System Parameters​

The system parameters are as follows:

  • accessKeyId: The requester's accessKeyId, assigned by the system after API (reseller) access is granted.
  • timestamp: Timestamp in the format YYYY-mm-ddTHH:ii:ssZ, e.g. 2019-10-10T12:00:01Z. Note that it must be the time in the Beijing time zone (UTC+8, China), and the deviation must not exceed 15 minutes.
  • nonce: Idempotency token, consisting of English letters (upper/lower case) and digits, up to 32 characters. Developers must ensure it does not collide within any 24-hour period.
  • sign: Signature. The API request URI + system parameters + business parameters are sorted and used as the data, then digested with sha256 using the accessKeySecret and base64-encoded. For the exact generation rules, see Signature.
tip

PHP code example

<?php
$defaultTimeZone = date_default_timezone_get(); // Save the time zone before signing
date_default_timezone_set('PRC'); // Switch to UTC+8

$parameters['accessKeyId'] = $this->accessKeyId;
$parameters['nonce'] = uniqid();
$parameters['timestamp'] = date('Y-m-d\TH:i:s\Z'); // Get the timestamp
date_default_timezone_set($defaultTimeZone); // Restore the time zone from before signing

2. Preparing Parameters​

First, merge the system parameters into the business parameters, with business parameters taking precedence:

tip

PHP code example

<?php
$defaultTimeZone = date_default_timezone_get(); // Save the time zone before signing
date_default_timezone_set('PRC'); // Switch to UTC+8

$parameters['accessKeyId'] = $this->accessKeyId;
$parameters['nonce'] = uniqid();
$parameters['timestamp'] = date('Y-m-d\TH:i:s\Z'); // Get the timestamp
date_default_timezone_set($defaultTimeZone); // Restore the time zone from before signing

// The code above is from the previous step
$business_parameters = [/* business parameters */];

// Trim leading and trailing whitespace from the business parameters
function trimize($business_parameters) {
foreach($business_parameters as $key => $value) {
if (is_string($value)) {
// When the value is an array, its child items must also be trimmed
$business_parameters[$key] = trim($value);
if ('' === $business_parameters[$key]) {
$business_parameters[$key] = null;
}
} else if (is_array($value)) {
$business_parameters[$key] = trimize($value);
}
}
return $business_parameters;
}
$business_parameters = trimize($business_parameters);

$parameters = array_merge($parameters, isset($arguments[1]) ? $arguments[1] : []);

ksort($parameters);

3. URLEncode and HTTP_Build_Query() Explained​

a. URLEncode (both keys and values must be encoded):

Our server requires integrators to replace-encode the following characters appearing in request parameters. For characters not listed in the dictionary below (e.g., Chinese characters), you may use your language's built-in urlencode function:

Source characterEncodedNotes
 +Space
\n%0ANewline
\r%0D
!%21
"%22
#%23
$%24
%%25
&%26
'%27
(%28
)%29
*%2A
+%2B
,%2C
/%2F
:%3A
;%3B
<%3C
=%3D
>%3E
?%3F
@%40
[%5B
\%5C
]%5D
^%5E
`%60
{%7B
|%7C
}%7D
~%7E

b. HTTP_Build_Query:

Example 1

{
"accessKeyId": "test_key=",
"timestamp": "2024-04-23T02:50:50Z",
"nonce": "/n241z!"
}

should be converted to

accessKeyId=test_key%3D&nonce=%2Fn241z%21&timestamp=2024-04-23T02%3A50%3A50Z

Example 2

{
"accessKeyId": "test_key=",
"domain_dcv": {
"mydomain.com": "dns",
"*.mydomain.com": "dns",
"bbs.mydomain2.com": "webmaster@mydomain2.com",
},
"timestamp": "2024-04-23T02:50:50Z",
"nonce": "/n241z!"
}

should be converted to

accessKeyId=test_key%3D&domain_dcv%5Bbbs.mydomain2.com%5D=webmaster%40mydomain2.com&domain_dcv%5Bmydomain.com%5D=dns&domain_dcv%5B%2A.mydomain2.com%5D=dns&nonce=%2Fn241z%21&timestamp=2024-04-23T02%3A50%3A50Z

4. Signature​

Take the full relative path of the requested API (without the domain part and without the query string after ?), together with all parameters merged in step 2, and concatenate them into a single string in the form urlencode(key1)=urlencode(value1)&urlencode(key2)=urlencode(value2). Then sign it with sha256 using accessKeySecret as the encryption key:

tip

PHP code example

<?php
$defaultTimeZone = date_default_timezone_get(); // Save the time zone before signing
date_default_timezone_set('PRC'); // Switch to UTC+8

$parameters['accessKeyId'] = $this->accessKeyId;
$parameters['nonce'] = uniqid();
$parameters['timestamp'] = date('Y-m-d\TH:i:s\Z'); // Get the timestamp
date_default_timezone_set($defaultTimeZone); // Restore the time zone from before signing

$business_parameters = [/* business parameters */];
// Trim leading and trailing whitespace from the business parameters
function trimize($business_parameters) {
foreach($business_parameters as $key => $value) {
if (is_string($value)) {
// When the value is an array, its child items must also be trimmed
$business_parameters[$key] = trim($value);
if ('' === $business_parameters[$key]) {
$business_parameters[$key] = null;
}
} else if (is_array($value)) {
$business_parameters[$key] = trimize($value);
}
}
return $business_parameters;
}
$business_parameters = trimize($business_parameters);
$parameters = array_merge($parameters, isset($arguments[1]) ? $arguments[1] : []);

ksort($parameters);
// The code above is from the previous steps
$parameters['sign'] = base64_encode(hash_hmac(
'sha256',
$resource . '?' .http_build_query($parameters),
$this->accessKeySecret,
true // Be sure to use raw output, not hexadecimal
));

$uri = $this->apiOrigin . $resource;

// You can now send the request to $uri, with $parameters as the GET/POST parameters