Asynchronous Moderation Callback
Update:
Callback Interface Overview
Callback for the asynchronous interface of the image moderation service .../check/asyn
and .../batchCheck/async
, used to push asynchronous moderation results to client, client need to implement the interface for receiving results according to the following specifications.
Interface Description
The result will be pushed to the client with taskId
as the dimension. There are 2 configuration methods for the callback function:
- Method 1: Please configure the callback URL (http protocol), callback area, and callback key in
Console-Service Configuration
. The callback key is automatically generated after configuring the callback parameters.
- Method 2: When submitting a task through the asynchronous interface, carry the corresponding callback parameters. See the Image Asynchronous Moderation Document.
Please note that Method 2
has a higher priority than Method 1
. If you use the interface parameter input method when submitting a task, the callback parameters configured on the console will become invalid. Please ensure that the parameters are passed correctly. In addition, when passing parameters in the interface, make sure that callback url
and callback key
are not empty, otherwise the callback will not take effect. The client needs to ensure the availability and stability of the callback receiving interface to ensure that the pushed result data can be received correctly.
Interface Authentication
Client can perform interface authentication through the key information fields assigned after configuring the callback parameters. The specific method is as follows:
-
Signature Algorithm
1> Sort the received request body parameters in ascending order of the ASCII code table.
2> Append the sorted parameters into a string. The format is: key1 + value1 +key2 + value2…
3> Append the key generated after configuring the callback parameters to the string generated in step 2>.
4> Use UTF-8 to encode the string generated in step 3>, encrypt it using MD5 to generate the signature parameter value, and put it into the request header.
-
Example code
/**
Generate signature
@param secretKey key generated in Console-Service Configuration
@param params Interface request parameter name and parameter value map, excluding signature parameter name
@return
*/
public static String signature(String secretKey, Map<String, String params){
String[] keys = params.keySet().toArray(new String[0]);
Arrays.sort(keys);
StringBuilder signBuilder = new StringBuilder();
for (String key : keys) {
signBuilder.append(key).append(params.get(key));
}
signBuilder.append(secretKey);
try {
return DigestUtils.md5Hex(signBuilder.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// error
}
return null;
}
Access Instructions
- Protocol description: Client needs to provide an interface that supports the post request method of the http protocol.
- Interface performance: Client needs to maintain the stability and reliability of the interface.
- Retry after failed: After we receive the customer callback response, if it does not meet the specified acceptance success specifications, we will consider the push to have failed. It will be pushed three times at a specified interval of 10 seconds. If it fails for the third time, it will not be pushed further.
Request Instructions
-
Request Address and Method
Parameter
Value
callbackUrl
Callback Url(http protocol)
HTTP_METHOD
POST
-
Request Header
Header
Required
Type
Description
Content-Type
Required
String
Fixed value:application/json
signature
Required
String
Signature, verify the legitimacy of the request, refer to the authentication algorithm
-
Request Parameters
Parameter
Type
Description
appId
String
Project ID
taskId
String
When submitting asynchronous review, the returned task ID
result
String
Moderation result
checkType
String
Type of moderation,for image: image-check
-
result Format
Please refer to Single Image Synchronous Moderation - HTTP Response
- Request Response
After receiving the result of our callback, the client’s interface needs to return response information. When the interface responds, the code
is 0. When a callback exception occurs, the response code
should be 500, or 4xx; the response information is in json format, the fields are defined as follows:
Parameter
Type
Required
Description
code
Number
Required
Response code. A code value of 0 means the callback is successful.
message
String
Optional
Detailed description information
Callback Interface Overview
Callback for the asynchronous interface of the image moderation service .../check/asyn
and .../batchCheck/async
, used to push asynchronous moderation results to client, client need to implement the interface for receiving results according to the following specifications.
Interface Description
The result will be pushed to the client with taskId
as the dimension. There are 2 configuration methods for the callback function:
- Method 1: Please configure the callback URL (http protocol), callback area, and callback key in
Console-Service Configuration
. The callback key is automatically generated after configuring the callback parameters. - Method 2: When submitting a task through the asynchronous interface, carry the corresponding callback parameters. See the Image Asynchronous Moderation Document.
Please note that Method 2
has a higher priority than Method 1
. If you use the interface parameter input method when submitting a task, the callback parameters configured on the console will become invalid. Please ensure that the parameters are passed correctly. In addition, when passing parameters in the interface, make sure that callback url
and callback key
are not empty, otherwise the callback will not take effect. The client needs to ensure the availability and stability of the callback receiving interface to ensure that the pushed result data can be received correctly.
Interface Authentication
Client can perform interface authentication through the key information fields assigned after configuring the callback parameters. The specific method is as follows:
-
Signature Algorithm
1> Sort the received request body parameters in ascending order of the ASCII code table.
2> Append the sorted parameters into a string. The format is: key1 + value1 +key2 + value2…
3> Append the key generated after configuring the callback parameters to the string generated in step 2>.
4> Use UTF-8 to encode the string generated in step 3>, encrypt it using MD5 to generate the signature parameter value, and put it into the request header.
-
Example code
/**
Generate signature
@param secretKey key generated in Console-Service Configuration
@param params Interface request parameter name and parameter value map, excluding signature parameter name
@return
*/
public static String signature(String secretKey, Map<String, String params){
String[] keys = params.keySet().toArray(new String[0]);
Arrays.sort(keys);
StringBuilder signBuilder = new StringBuilder();
for (String key : keys) {
signBuilder.append(key).append(params.get(key));
}
signBuilder.append(secretKey);
try {
return DigestUtils.md5Hex(signBuilder.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// error
}
return null;
}
Access Instructions
- Protocol description: Client needs to provide an interface that supports the post request method of the http protocol.
- Interface performance: Client needs to maintain the stability and reliability of the interface.
- Retry after failed: After we receive the customer callback response, if it does not meet the specified acceptance success specifications, we will consider the push to have failed. It will be pushed three times at a specified interval of 10 seconds. If it fails for the third time, it will not be pushed further.
Request Instructions
-
Request Address and Method
Parameter Value callbackUrl Callback Url(http protocol) HTTP_METHOD POST -
Request Header
Header Required Type Description Content-Type Required String Fixed value:application/json signature Required String Signature, verify the legitimacy of the request, refer to the authentication algorithm -
Request Parameters
Parameter Type Description appId String Project ID taskId String When submitting asynchronous review, the returned task ID result String Moderation result checkType String Type of moderation,for image: image-check -
result Format
Please refer to Single Image Synchronous Moderation - HTTP Response
- Request Response
After receiving the result of our callback, the client’s interface needs to return response information. When the interface responds, the code
is 0. When a callback exception occurs, the response code
should be 500, or 4xx; the response information is in json format, the fields are defined as follows:
Parameter | Type | Required | Description |
---|---|---|---|
code | Number | Required | Response code. A code value of 0 means the callback is successful. |
message | String | Optional | Detailed description information |