Result Callback
Update:
Callback Interface Overview
For the callback of the asynchronous interface …/batchCheck/async for the batch image moderation service,
it is used to push the asynchronous detection and moderation result set to the client. The client needs to implement
an interface to receive the result set according to the following specifications.
Interface Description
When using the asynchronous batch task submission interface, the batch callback can be specified by adding the
parameter callbackWaitForAll
or configuring it in the Console - Service Configuration.
Once the batch moderation task is completed, the moderation result set will be pushed to the client through this
interface.
Note: The priority of callbackWaitForAll
is higher than the Console - Service Configuration.
Interface Authentication
The client can authenticate the interface using the secret key information assigned after configuring the callback
parameters. The specific method is as follows:
-
Signature Algorithm
- Sort the received request body parameters in ascending order based on the
ASCII table
of the parameter names.
- Concatenate the sorted parameters into a string. Fields with
NULL
parameter values should be ignored. The format is: key1 + value1 + key2 + value2...
.
- Append the secret key obtained from the console configuration to the string generated in the previous step.
- Encode the resulting string using
UTF-8
and encrypt it using MD5
to generate the complete signature string.
-
Example Code
/**
* Generate Signature
*
* @param secretKey Background secret key
* @param params Map of interface request parameter names and values, excluding the signature parameter name
*/
public static String signature(String secretKey, Map<String, String> params) {
// 1. Sort by the ASCII table of map.key in ascending order
String[] keys = params.keySet().toArray(new String[0]);
Arrays.sort(keys);
// 2. Concatenate parameters in order into a string
StringBuilder signBuilder = new StringBuilder();
for (String key : keys) {
signBuilder.append(key).append(params.get(key));
}
// 3. Append the secret key to the end of the string
signBuilder.append(secretKey);
// 4. Encode the string using UTF-8
byte[] signBytes = signBuilder.toString().getBytes(StandardCharsets.UTF_8);
// 5. Encode using MD5(hex)
return DigestUtils.md5Hex(signBytes);
}
Integration Instructions
- Protocol Specification: The client must provide an interface that supports the
http
protocol and the post
request method.
- Interface Performance: The client must ensure the stability and reliability of the interface.
- Retry on Failure: If the client’s callback response does not meet the specified success criteria, the push is
considered failed. The system will retry at intervals of 10 seconds, up to 3 times. If the third attempt fails, no
further pushes will be made.
Request Specification
-
Request URL and Method
Name
Value
callbackUrl
Callback URL (http protocol)
HTTP_METHOD
POST
-
Request Headers
Header
Required
Type
Description
Content-Type
Yes
String
Fixed value: application/json
signature
Yes
String
Signature to verify the request’s validity. Refer to the authentication algorithm.
-
Request Parameters
Parameter
Type
Description
appId
String
Project ID
checkType
String
Detection project identifier. For images, it is image-check
.
results
List
Moderation result set
-
TaskResult
Parameter
Type
Description
taskId
String
Task ID returned when submitting the asynchronous moderation task.
result
String
JSON-formatted string of the moderation result. Refer to the synchronous single detection - HTTP response.
-
Request Response
After receiving the callback result, the client’s interface needs to return a response. The interface response code
status code should be 0. If an exception occurs during callback processing, the response code
status code should be
500 or 4xx. The response information should be in JSON format, with the following fields:
Name
Type
Required
Description
code
Number
Yes
Response code. A value of 0 indicates a successful callback.
message
String
No
Detailed description information
-
An example of a request pushed
POST <callbackUrl>
Content-Type: application/json
signature: <signature>
{
"appId": "1234",
"checkType": "image-check",
"results": [
{
"taskId": "task_a",
"result": "{\"errorCode\":0,\"code\":0,\"result\":2,\"imageSpams\":[{\"code\":0,\"result\":2,\"tags\":[{\"tag\":200,\"level\":2,\"confidence\":76}]}],\"gender\":[],\"taskId\":\"task_a\",\"extraInfo\":{\"userId\":123}}"
},
{
"taskId": "task_b",
"result": "{\"errorCode\":0,\"code\":0,\"result\":2,\"imageSpams\":[{\"code\":0,\"result\":2,\"tags\":[{\"tag\":200,\"level\":2,\"confidence\":76}]}],\"gender\":[],\"taskId\":\"task_b\",\"extraInfo\":{\"userId\":456}}"
}
]
}
Callback Interface Overview
For the callback of the asynchronous interface …/batchCheck/async for the batch image moderation service, it is used to push the asynchronous detection and moderation result set to the client. The client needs to implement an interface to receive the result set according to the following specifications.
Interface Description
When using the asynchronous batch task submission interface, the batch callback can be specified by adding the
parameter callbackWaitForAll
or configuring it in the Console - Service Configuration.
Once the batch moderation task is completed, the moderation result set will be pushed to the client through this
interface.
Note: The priority of callbackWaitForAll
is higher than the Console - Service Configuration.
Interface Authentication
The client can authenticate the interface using the secret key information assigned after configuring the callback parameters. The specific method is as follows:
-
Signature Algorithm
- Sort the received request body parameters in ascending order based on the
ASCII table
of the parameter names. - Concatenate the sorted parameters into a string. Fields with
NULL
parameter values should be ignored. The format is:key1 + value1 + key2 + value2...
. - Append the secret key obtained from the console configuration to the string generated in the previous step.
- Encode the resulting string using
UTF-8
and encrypt it usingMD5
to generate the complete signature string.
- Sort the received request body parameters in ascending order based on the
-
Example Code
/** * Generate Signature * * @param secretKey Background secret key * @param params Map of interface request parameter names and values, excluding the signature parameter name */ public static String signature(String secretKey, Map<String, String> params) { // 1. Sort by the ASCII table of map.key in ascending order String[] keys = params.keySet().toArray(new String[0]); Arrays.sort(keys); // 2. Concatenate parameters in order into a string StringBuilder signBuilder = new StringBuilder(); for (String key : keys) { signBuilder.append(key).append(params.get(key)); } // 3. Append the secret key to the end of the string signBuilder.append(secretKey); // 4. Encode the string using UTF-8 byte[] signBytes = signBuilder.toString().getBytes(StandardCharsets.UTF_8); // 5. Encode using MD5(hex) return DigestUtils.md5Hex(signBytes); }
Integration Instructions
- Protocol Specification: The client must provide an interface that supports the
http
protocol and thepost
request method. - Interface Performance: The client must ensure the stability and reliability of the interface.
- Retry on Failure: If the client’s callback response does not meet the specified success criteria, the push is considered failed. The system will retry at intervals of 10 seconds, up to 3 times. If the third attempt fails, no further pushes will be made.
Request Specification
-
Request URL and Method
Name Value callbackUrl Callback URL (http protocol) HTTP_METHOD POST -
Request Headers
Header Required Type Description Content-Type Yes String Fixed value: application/json signature Yes String Signature to verify the request’s validity. Refer to the authentication algorithm. -
Request Parameters
Parameter Type Description appId String Project ID checkType String Detection project identifier. For images, it is image-check
.results List Moderation result set -
TaskResult
Parameter Type Description taskId String Task ID returned when submitting the asynchronous moderation task. result String JSON-formatted string of the moderation result. Refer to the synchronous single detection - HTTP response. -
Request Response
After receiving the callback result, the client’s interface needs to return a response. The interface response code
status code should be 0. If an exception occurs during callback processing, the response code
status code should be
500 or 4xx. The response information should be in JSON format, with the following fields:
Name | Type | Required | Description |
---|---|---|---|
code | Number | Yes | Response code. A value of 0 indicates a successful callback. |
message | String | No | Detailed description information |
-
An example of a request pushed
POST <callbackUrl> Content-Type: application/json signature: <signature> { "appId": "1234", "checkType": "image-check", "results": [ { "taskId": "task_a", "result": "{\"errorCode\":0,\"code\":0,\"result\":2,\"imageSpams\":[{\"code\":0,\"result\":2,\"tags\":[{\"tag\":200,\"level\":2,\"confidence\":76}]}],\"gender\":[],\"taskId\":\"task_a\",\"extraInfo\":{\"userId\":123}}" }, { "taskId": "task_b", "result": "{\"errorCode\":0,\"code\":0,\"result\":2,\"imageSpams\":[{\"code\":0,\"result\":2,\"tags\":[{\"tag\":200,\"level\":2,\"confidence\":76}]}],\"gender\":[],\"taskId\":\"task_b\",\"extraInfo\":{\"userId\":456}}" } ] }