主动回调说明
易盾提供主动回调和被动回调数据两种方式,主动回调以数据为维度设置回调地址;易盾方产品回调数据后,主动调用客户提供的http地址将回调数据推送给客户
主动回调接入
客户接入主动回调的方式很简单,只需要在调用在线检测接口请求参数中指定了回调通知参数callbackUrl(即一个http(s)协议接口的URL),则需要支持POST方法,传输数据编码采用utf-8
业务类型 | 回调参数名称 | 类型 | 最大长度 | 描述 |
---|---|---|---|---|
点播音视频 | callbackUrl | String | 256 | 点播音视频提交参数中添加callbackUrl字段 |
您服务端接收到我们推送的结果后,返回的HTTP状态码为200时,表示推送成功,其他的HTTP状态码均视为您接收失败,我们将每隔10分钟推送一次,如果一直失败,持续一天后不再推送;我们主动回调数据接口超时时间设置为2s,为了保证顺利接收数据,客户需保证接收接口性能稳定并且保证幂等性。
请求方法
客户提供的主动回调数据接收接口,需支持 POST 方法。
字符编码
所有接口的请求数据编码皆为 utf-8。
请求公共参数
| 参数名称 | 类型 | 是否必传 | 描述 | |----------|------|------|------|-----| | secretId | String | Y | 产品秘钥 id ,由易盾反垃圾云服务分配,产品标识 | | businessId | String | Y | 业务id ,由易盾反垃圾云服务分配,业务标识 | | signature | String | Y | 请求签名,用来验证此次请求的合法性,具体算法见 接口鉴权 | | callbackData | String | Y | 主动回调推送数据,格式为json字符串 |
secretId,businessId,signature参数用来给数据接收接口做签名鉴权用
接口鉴权
客户主动回调接收接口可以通过业务开通时易盾分配的密钥信息字段进行接口鉴权,鉴权粒度是否要精确到业务级别,用户可以根据需要自行决定
/**
* 通过HttpServletRequest做签名验证
*
* @param request
* @return
*/
public static boolean verifySignature(HttpServletRequest request) {
String secretId = request.getParameter("secretId");
String businessId = request.getParameter("businessId");
String signature = request.getParameter("signature");
if (StringUtils.isEmpty(secretId) || StringUtils.isEmpty(signature)) {
// 签名参数为空,直接返回失败
return false;
}
Map<String, String> params = Maps.newHashMap();
for (String paramName : request.getParameterMap().keySet()) {
if (!"signature".equals(paramName)) {
params.put(paramName, request.getParameter(paramName));
}
}
// SECRETKEY:产品私有密钥 SECRETID:产品密钥ID BUSINESSID:业务ID,开通服务时,易盾会提供相关密钥信息
String serverSignature = getSignature(SECRETKEY, params);
return signature.equals(serverSignature) && SECRETID.equals(secretId) && BUSINESSID.equals(businessId);
}
/**
* 生成签名信息
* @param secretKey 产品私钥
* @param params 接口请求参数名和参数值map,不包括signature参数名
* @return
* @throws UnsupportedEncodingException
*/
public static String genSignature(String secretKey, Map<String, String> params) throws UnsupportedEncodingException {
// 1. 参数名按照ASCII码表升序排序
String[] keys = params.keySet().toArray(new String[0]);
Arrays.sort(keys);
// 2. 按照排序拼接参数名与参数值
StringBuffer paramBuffer = new StringBuffer();
for (String key : keys) {
paramBuffer.append(key).append(params.get(key) == null ? "" : params.get(key));
}
// 3. 将secretKey拼接到最后
paramBuffer.append(secretKey);
// 4. MD5是128位长度的摘要算法,用16进制表示,一个十六进制的字符能表示4个位,所以签名后的字符串长度固定为32个十六进制字符。
return DigestUtils.md5Hex(paramBuffer.toString().getBytes("UTF-8"));
}
点播音视频解决方案主动回调数据结构
callbackData为Json字符串,机审数据结构如下:
{
"dataId": "783282705",
"taskId": "535ac5612221476ab16328fed530de03",
"callback": "1594002736",
"result": 2,
"evidences": {
"text": {
"action": 2,
"taskId": "535ac5612221476ab16328fed530de03",
"labels": [
{
"label": 100,
"level": 2,
"details": {
"hint": [
"肛好遇奸你"
]
}
}
]
},
"images": [
{
"name": "535ac5612221476ab16328fed530de03",
"taskId": "2ceff6bf9fda41d79acd9a3bb9f26055",
"labels": [
{
"label": 100,
"level": 2,
"rate": 0.992854
},
{
"label": 500,
"level": 0,
"rate": 0.0
},
{
"label": 300,
"level": 0,
"rate": 0.0
},
{
"label": 400,
"level": 0,
"rate": 0.0
},
{
"label": 110,
"level": 0,
"rate": 0.0
},
{
"label": 200,
"level": 0,
"rate": 0.0
},
{
"label": 210,
"level": 0,
"rate": 0.0
},
{
"label": 900,
"level": 0,
"rate": 0.0
}
]
}
],
"audio": {
"action": 1,
"asrStatus": 3,
"asrResult": 0,
"taskId": "535ac5612221476ab16328fed530de03",
"labels": [
{
"label": 500,
"level": 1,
"details": {
"hint": [
{
"value": "共和国",
"segments": [
{
"startTime": 9,
"endTime": 19
}
]
}
],
"hitType": 30
}
}
]
},
"video": {
"taskId": "535ac5612221476ab16328fed530de03",
"status": 0,
"level": 2,
"evidences": [
{
"type": 1,
"url": "https://illegal-video.nosdn.127.net/535ac5612221476ab16328fed530de03_1594002739807.jpg",
"beginTime": 30200,
"endTime": 30200,
"labels": [
{
"label": 400,
"level": 1,
"rate": 0.964954
}
]
}
]
}
}
}
人审数据结构如下:
{
"dataId":"909562765",
"taskId":"72d39d4ee4c44084ad066cc99821684f",
"callback":"1589175393",
"result":2,
"reviewEvidences":{
"reason":"涉及暴恐",
"detail":{
"audio":[
{
"startTime":7,
"endTime":7,
"description":"删除暴恐视频"
}
],
"video":[
{
"url":"******",
"startTime":4000,
"endTime":4000,
"description":"删除暴恐视频"
}
]
}
}
}