图片离线结果获取

接口地址

https://as.dun.163yun.com/v4/image/callback/results

接口描述

在线检测接口结果中嫌疑的数据,会进行离线分析和人工审核,这些数据的离线结果需要客户通过该接口进行定时获取。获取离线处理的数据后,下次调用,不会再次返回之前获取过的离线数据。

V3离线检测接口文档请点此下载查看

接口请求频率

小于10s/20次,请求频率过快服务器会拒绝处理。

请求参数

该接口参数与请求公共参数一致,详细见 请求公共参数

响应结果

响应字段如下,响应通用字段已省略,详细见 响应通用字段

antispam 数组数据结构

参数名称类型描述
nameString图片名称(或图片标识)
taskIdString在线接口检测返回的数据请求标识,可以根据该标识查询数据最新结果
actionNumber建议动作,2:建议删除,0:建议通过
labelsjson数组分类信息

labels 数据结构

参数名称类型描述
labelNumber分类信息,100:色情,110:性感,200:广告,210:二维码,300:暴恐,400:违禁,500:涉政
levelNumber分类级别,0:正常,2:确定
rateNumber置信度分数

请求示例

    /** 产品密钥ID,产品标识 */
    private final static String SECRETID = "your_secret_id";
    /** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
    private final static String SECRETKEY = "your_secret_key";
    /** 业务ID,易盾根据产品业务特点分配 */
    private final static String BUSINESSID = "your_business_id";
    /** 易盾内容安全服务图片离线检测结果获取接口地址 */
    private final static String API_URL = "https://as.dun.163yun.com/v4/image/callback/results";
    /** 实例化HttpClient,发送http请求使用,可根据需要自行调参 */
    private static HttpClient httpClient = HttpClient4Utils.createHttpClient(100, 20, 10000, 2000, 2000);

    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Map<String, String> params = new HashMap<String, String>();
        // 1.设置公共参数
        params.put("secretId", SECRETID);
        params.put("businessId", BUSINESSID);
        params.put("version", "v4");
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", String.valueOf(new Random().nextInt()));

        // 2.生成签名信息
        String signature = SignatureUtils.genSignature(SECRETKEY, params);
        params.put("signature", signature);

        // 3.发送HTTP请求,这里使用的是HttpClient工具包,产品可自行选择自己熟悉的工具包发送请求
        String response = HttpClient4Utils.sendPost(httpClient, API_URL, params, Consts.UTF_8);

        // 4.解析接口返回值
        JsonObject resultObject = new JsonParser().parse(response).getAsJsonObject();
        int code = resultObject.get("code").getAsInt();
        String msg = resultObject.get("msg").getAsString();
        if (code == 200) {
            JsonArray resultArray = resultObject.getAsJsonArray("antispam");
            if (resultArray.size() == 0) {
                System.out.println("暂时没有人工复审结果需要获取,请稍后重试!");
            }
            for (JsonElement jsonElement : resultArray) {
                JsonObject jObject = jsonElement.getAsJsonObject();
                String name = jObject.get("name").getAsString();
                String taskId = jObject.get("taskId").getAsString();
                JsonArray labelArray = jObject.get("labels").getAsJsonArray();
                System.out.println(String.format("taskId=%s,name=%s,labels:", taskId, name));
                int maxLevel = -1;
                // 产品需根据自身需求,自行解析处理,本示例只是简单判断分类级别
                for (JsonElement labelElement : labelArray) {
                    JsonObject lObject = labelElement.getAsJsonObject();
                    int label = lObject.get("label").getAsInt();
                    int level = lObject.get("level").getAsInt();
                    double rate = lObject.get("rate").getAsDouble();
                    System.out.println(String.format("label:%s, level=%s, rate=%s", label, level, rate));
                    maxLevel = level > maxLevel ? level : maxLevel;
                }
                switch (maxLevel) {
                    case 0:
                        System.out.println("#图片人工复审结果:最高等级为\"正常\"\n");
                        break;
                    case 2:
                        System.out.println("#图片人工复审结果:最高等级为\"确定\"\n");
                        break;
                    default:
                        break;
                }
            }
        } else {
            System.out.println(String.format("ERROR: code=%s, msg=%s", code, msg));
        }

    }
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""易盾图片离线检测结果获取接口python示例代码
接口文档: http://dun.163.com/api.html
python版本:python2.7
运行:
    1. 修改 SECRET_ID,SECRET_KEY,BUSINESS_ID 为对应申请到的值
    2. $ python image_check_callback_demo.py
"""
__author__ = 'yidun-dev'
__date__ = '2016/3/10'
__version__ = '0.1-dev'

import hashlib
import time
import random
import urllib
import urllib2
import json

class ImageCheckCallbackAPIDemo(object):
    """易盾图片离线检测结果获取接口示例代码"""
    API_URL = "https://as.dun.163yun.com/v4/image/callback/results"
    VERSION = "v4.0"

    def __init__(self, secret_id, secret_key, business_id):
        """
        Args:
            secret_id (str) 产品密钥ID,产品标识
            secret_key (str) 产品私有密钥,服务端生成签名信息使用
            business_id (str) 业务ID,云安全根据产品业务特点分配
        """
        self.secret_id = secret_id
        self.secret_key = secret_key
        self.business_id = business_id

    def gen_signature(self, params=None):
        """生成签名信息
        Args:
            params (object) 请求参数
        Returns:
            参数签名md5值
        """
        buff = ""
        for k in sorted(params.keys()):
            buff += str(k)+ str(params[k])
        buff += self.secret_key
        return hashlib.md5(buff).hexdigest()

    def check(self):
        """请求易盾接口
        Returns:
            请求结果,json格式
        """
        params = {}
        params["secretId"] = self.secret_id
        params["businessId"] = self.business_id
        params["version"] = self.VERSION
        params["timestamp"] = int(time.time() * 1000)
        params["nonce"] = int(random.random()*100000000)
        params["signature"] = self.gen_signature(params)

        try:
            params = urllib.urlencode(params)
            request = urllib2.Request(self.API_URL, params)
            content = urllib2.urlopen(request, timeout=10).read()
            # print content
            # content = "{\"code\":200,\"msg\":\"ok\",\"timestamp\":1453793733515,\"nonce\":1524585,\"signature\":\"630afd9e389e68418bb10bc6d6522330\",\"result\":[{\"image\":\"http://img1.cache.netease.com/xxx1.jpg\",\"labels\":[]},{\"image\":\"http://img1.cache.netease.com/xxx2.jpg\",\"labels\":[{\"label\":100,\"level\":2,\"rate\":0.99},{\"label\":200,\"level\":1,\"rate\":0.5}]},{\"image\":\"http://img1.cache.netease.com/xxx3.jpg\",\"labels\":[{\"label\":200,\"level\":1,\"rate\":0.5}]}]}";
            return json.loads(content)
        except Exception, ex:
            print "调用API接口失败:", str(ex)

if __name__ == "__main__":
    """示例代码入口"""
    SECRET_ID = "your_secret_id" # 产品密钥ID,产品标识
    SECRET_KEY = "your_secret_key" # 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
    BUSINESS_ID = "your_business_id" # 业务ID,易盾根据产品业务特点分配
    image_check_callback_api = ImageCheckCallbackAPIDemo(SECRET_ID, SECRET_KEY, BUSINESS_ID)

    ret = image_check_callback_api.check()
    if ret["code"] == 200:
        results = ret["antispam"]
        if len(results) == 0:
            print "暂时没有人工复审结果需要获取,请稍后重试! "
        for result in results:
            print "taskId=%s,name=%s,labels:" %(result["taskId"],result["name"])
            maxLevel = -1
            for labelObj in result["labels"]:
                label = labelObj["label"]
                level = labelObj["level"]
                rate  = labelObj["rate"]
                print "label:%s, level=%s, rate=%s" %(label, level, rate)
                maxLevel =level if level > maxLevel else maxLevel
            if maxLevel==0:
                print "#图片人工复审结果:最高等级为\"正常\"\n"
            elif maxLevel==2:
                print "#图片人工复审结果:最高等级为\"确定\"\n"

    else:
        print "ERROR: ret.code=%s, ret.msg=%s" % (ret["code"], ret["msg"])
<?php
/** 产品密钥ID,产品标识 */
define("SECRETID", "your_secret_id");
/** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
define("SECRETKEY", "your_secret_key");
/** 业务ID,易盾根据产品业务特点分配 */
define("BUSINESSID", "your_business_id");
/** 易盾内容安全服务图片离线检测结果获取接口地址 */
define("API_URL", "https://as.dun.163yun.com/v4/image/callback/results");
/** api version */
define("VERSION", "v4");
/** API timeout*/
define("API_TIMEOUT", 10);
/** php内部使用的字符串编码 */
define("INTERNAL_STRING_CHARSET", "auto");

/**
 * 计算参数签名
 * $params 请求参数
 * $secretKey secretKey
 */
function gen_signature($secretKey, $params){
    ksort($params);
    $buff="";
    foreach($params as $key=>$value){
        if($value !== null) {
           $buff .=$key;
           $buff .=$value;
        }
    }
    $buff .= $secretKey;
    return md5($buff);
}

/**
 * 将输入数据的编码统一转换成utf8
 * @params 输入的参数
 */
function toUtf8($params){
    $utf8s = array();
    foreach ($params as $key => $value) {
        $utf8s[$key] = is_string($value) ? mb_convert_encoding($value, "utf8", INTERNAL_STRING_CHARSET) : $value;
    }
    return $utf8s;
}

/**
 * 易盾请求接口简单封装
 * $params 请求参数
 */
function check(){
    $params = array();
    $params["secretId"] = SECRETID;
    $params["businessId"] = BUSINESSID;
    $params["version"] = VERSION;
    $params["timestamp"] = sprintf("%d", round(microtime(true)*1000));// time in milliseconds
    $params["nonce"] = sprintf("%d", rand()); // random int

    $params = toUtf8($params);
    $params["signature"] = gen_signature(SECRETKEY, $params);
    // var_dump($params);

    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'timeout' => API_TIMEOUT, // read timeout in seconds
            'content' => http_build_query($params),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents(API_URL, false, $context);
    // var_dump($result);
    if($result === FALSE){
        return array("code"=>500, "msg"=>"file_get_contents failed.");
    }else{
        return json_decode($result, true);
    }
}

// 简单测试
function main(){
    echo "mb_internal_encoding=".mb_internal_encoding()."\n";
    $ret = check();
    var_dump($ret);

    if ($ret["code"] == 200) {
        $result = $ret["antispam"];
        // var_dump($array);
        foreach($result as $index => $image_ret){
            $name = $image_ret["name"];
            $taskId = $image_ret["taskId"];
            $labelArray = $image_ret["labels"];
            echo "taskId={$taskId},name={$name},labels:\n";
            $maxLevel=-1;
            foreach($image_ret["labels"] as $index=>$label){
                echo "label:{$label["label"]}, level={$label["level"]}, rate={$label["rate"]}\n";
            $maxLevel=$label["level"]>$maxLevel?$label["level"]:$maxLevel;
            }
            if($maxLevel==0){
            echo "#图片人工复审结果:最高等级为:正常\n";
            }else if($maxLevel==2){
            echo "#图片人工复审结果:最高等级为:确定\n";
            }
        }
    }else{
        var_dump($ret);
    }
}

main();
?>
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;

namespace Com.Netease.Is.Antispam.Demo
{
    class ImageCallbackDemo
    {
        public static void imageCallBack()
        {
            /** 产品密钥ID,产品标识 */
            String secretId = "your_secret_id";
            /** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
            String secretKey = "your_secret_key";
            /** 业务ID,易盾根据产品业务特点分配 */
            String businessId = "your_business_id";
            /** 易盾内容安全服务图片离线检测结果获取接口地址 */
            String apiUrl = "https://as.dun.163yun.com/v4/image/callback/results";
            Dictionary<String, String> parameters = new Dictionary<String, String>();

            long curr = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
            String time = curr.ToString();

            // 1.设置公共参数
            parameters.Add("secretId", secretId);
            parameters.Add("businessId", businessId);
            parameters.Add("version", "v3");
            parameters.Add("timestamp", time);
            parameters.Add("nonce", new Random().Next().ToString());

            // 2.生成签名信息
            String signature = Utils.genSignature(secretKey, parameters);
            parameters.Add("signature", signature);

            // 3.发送HTTP请求
            HttpClient client = Utils.makeHttpClient();
            String result = Utils.doPost(client, apiUrl, parameters, 10000);
            if(result != null)
            {
                JObject ret = JObject.Parse(result);
                int code = ret.GetValue("code").ToObject<Int32>();
                String msg = ret.GetValue("msg").ToObject<String>();
                if (code == 200)
                {
                    JArray array = (JArray)ret.SelectToken("antispam");
                    if (array == null || !array.HasValues)
                    {
                        Console.WriteLine("暂时没有图片人工复审结果需要获取,请稍后重试!");
                    }

                    foreach (var item in array)
                    {
                        JObject tmp = (JObject)item;
                        String name = tmp.GetValue("name").ToObject<String>();
                        String taskId = tmp.GetValue("taskId").ToObject<String>();
                        JArray labels = (JArray)tmp.SelectToken("labels");
                        Console.WriteLine(String.Format("taskId={0},name={1},labels:", taskId, name));
                        int maxLevel = -1;
                        // 产品需根据自身需求,自行解析处理,本示例只是简单判断分类级别
                        foreach (var lable in labels)
                        {
                            JObject lableData = (JObject)lable;
                            int label = lableData.GetValue("label").ToObject<Int32>();
                            int level = lableData.GetValue("level").ToObject<Int32>();
                            double rate = lableData.GetValue("rate").ToObject<Double>();
                            Console.WriteLine(String.Format("label:{0}, level={1}, rate={2}", label, level, rate));
                            maxLevel = level > maxLevel ? level : maxLevel;
                        }

                        switch (maxLevel)
                        {
                            case 0:
                                Console.WriteLine("#图片机器检测结果:最高等级为\"正常\"\n");
                                break;
                            case 2:
                                Console.WriteLine("#图片机器检测结果:最高等级为\"确定\"\n");
                                break;
                            default:
                                break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine(String.Format("ERROR: code={0}, msg={1}", code, msg));
                }
            }
            else
            {
                Console.WriteLine("Request failed!");
            }

        }
    }
}
var utils=require("./utils");
//产品密钥ID,产品标识
var secretId="your_secret_id";
// 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
var secretKey="your_secret_key";
// 业务ID,易盾根据产品业务特点分配
var businessId="your_business_id";
// 易盾内容安全服务图片检测结果获取接口地址
var apiurl="https://api.aq.163.com/v4/image/callback/results";
//请求参数
var post_data = {
    // 1.设置公有有参数
    secretId:secretId,
    businessId:businessId,
    version:"v4.0",
    timestamp:new Date().getTime(),
    nonce:utils.noncer()
}
var signature=utils.genSignature(secretKey,post_data);
post_data.signature=signature;
//http请求结果
var responseCallback=function(responseData){
    var data = JSON.parse(responseData);
        var code=data.code;
        var msg=data.msg;
        if(code==200){
            var result=data.antispam;
            if(result.length==0){
                console.log("暂时没有图片人工复审结果需要获取,请稍后重试!");
            }else{
                    for(var i=0;i<result.length;i++){
                    var obj=result[i];
                    var name=obj.name;
                    var taskId=obj.taskId;
                    var labelsArray=obj.labels;
                    console.log("taskId="+taskId+",name="+name+",labels:");
                    var  maxLevel = -1;
                        // 产品需根据自身需求,自行解析处理,本示例只是简单判断分类级别
                    for(var k=0;k<labelsArray.length;k++){
                        var labelObj=labelsArray[k];
                        var label=labelObj.label;
                        var level=labelObj.level;
                        var rate=labelObj.rate;
                        console.log("lable:"+label+",level:"+level+",rate:"+rate);
                        maxLevel = level > maxLevel ? level : maxLevel;
                    }
                     switch (maxLevel) {
                        case 0:
                            console.log("#图片机器检测结果:最高等级为\"正常\"\n");
                            break;
                        case 2:
                            console.log("#图片机器检测结果:最高等级为\"确定\"\n");
                            break;
                        default:
                            break;
                            }
                }
            }
        }else{
             console.log('ERROR:code=' + code+',msg='+msg);
        }
}
utils.sendHttpRequest(apiurl,"POST",post_data,responseCallback);

响应示例

输出结果:

注:分类信息,100:色情,110:性感,200:广告,210:二维码,300:暴恐,400:违禁,500:涉政

{
	"code": 200,
	"msg": "ok",
	"antispam": [{
		"name": "1234",
		"taskId": "d1cd2e02f10249a6b62da9b4bf0e04ea",
		"action": 2,
		"labels": [{
			"label": 100,
			"level": 0,
			"rate": 1.0
		}, {
			"label": 110,
			"level": 0,
			"rate": 1.0
		}, {
			"label": 200,
			"level": 0,
			"rate": 1.0
		}, {
			"label": 210,
			"level": 0,
			"rate": 1.0
		}, {
			"label": 300,
			"level": 0,
			"rate": 1.0
		}, {
			"label": 400,
			"level": 0,
			"rate": 1.0
		}, {
			"label": 500,
			"level": 2,
			"rate": 1.0
		}]
	}]
}
Online Chat Tel:95163223