java docking seven cattle background content audit (yellow, sensitive, violent fear)

Keywords: Programming JSON network encoding

Introduction to the content audit of qiniu

Find intelligent multimedia in the console of qiniu

Next, find the intelligent content audit, and you can see some audit data, mainly including: Yellow River identification, violent terrorism, sensitive people

In addition, see the API interface description: The view address is: https://developer.qiniu.com/dora/api/4252/image-review It is mainly divided into two parts: new pictures and old pictures. For the specific interface content, please click the above address to see it. There is no detailed introduction here.

2. Actively submit to qinniu for review

As the name implies, submit the existing image to qiniu for review. Here is the implementation code. My example only shows the way to transfer the image url, which can also be transferred to base64 for review

Here is the description: Picture resources. Two resource expressions are supported:

  1. URL address of network picture, supporting http and https;
  2. For base64 encoding string, prefix data: application / octet stream; base64, for example, data: application / octet stream; base64, XXX

Here is a code demonstration:

public static JSONObject checkImage(String imageUrl) {
        //Splicing of basic parameters
        String url = "http://ai.qiniuapi.com/v3/image/censor";
        String host = "ai.qiniuapi.com";
        String body = "{ \"data\": { \"uri\": \""+imageUrl+"\" }, \"params\": { \"scenes\": [ \"pulp\", \"terror\", \"politician\" ] } }";
        String contentType = "application/json";
        String method = "POST";
        Auth auth = Auth.create(accessKey, secretKey);
        String qiniuToken = "Qiniu " + auth.signRequestV2(url, method, body.getBytes(), contentType);
        log.info("url={},body={},qiniuToken={}",url,body,qiniuToken);
        //Head part
        StringMap header = new StringMap();
        header.put("Host",host);
        header.put("Authorization",qiniuToken);
        header.put("Content-Type", contentType);
        Configuration c = new Configuration(Region.huadong());
        Client client = new Client(c);
        try {
            Response response = client.post(url, body.getBytes(), header, contentType);
            log.info("response result={}",response.bodyString());
            JSONObject checkResult = JSON.parseObject(response.bodyString());
            return checkResult;
        } catch (QiniuException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Map<String,Object> handleImageResult(String attach){
        JSONObject attachObj = JSON.parseObject(attach);
        String imageUrl = attachObj.getString("url");
        if (StringUtils.isNotBlank(imageUrl)){
            JSONObject checkResult = QiNiuYunUtil.checkImage(imageUrl);
            if (checkResult.getIntValue("code")==200){
                JSONObject imgResult = checkResult.getJSONObject("result");
                JSONObject scenes = imgResult.getJSONObject("scenes");
                //Pornographic check
                JSONObject pulp = scenes.getJSONObject("pulp");
                if (ObjectUtils.isNotEmpty(pulp.get("details"))) {
                    JSONObject detail = pulp.getJSONArray("details").getJSONObject(0);
                    if(detail.getString("label").equals("pulp")){
                        return ImmutableMap.of("errCode",1,"errMsg","Pornographic elements in pictures","responseCode",2001);
                    }
                }
                //Pictures of violence and fear
                JSONObject terror = scenes.getJSONObject("terror");
                if(!StringUtils.equals(terror.getString("suggestion"),"pass")){
                    return ImmutableMap.of("errCode",1,"errMsg","There are elements of violence and fear in the picture","responseCode",2001);
                }
                //Image sensitive character recognition
                JSONObject politician = scenes.getJSONObject("politician");
                if(!StringUtils.equals(politician.getString("suggestion"),"pass")){
                    return ImmutableMap.of("errCode",1,"errMsg","Photo sensitive elements","responseCode",2001);
                }
            }
        }
        return ImmutableMap.of("errCode",0,"errMsg","adopt","responseCode",2000);
    }

3. Incremental audit seven cattle for audit

A better way of understanding is to: When we upload a picture to qiniu, qiniu will automatically review it for us. If the picture is illegal, qiniu will automatically ban it. If it is deemed that it needs to be reviewed, for example, some sexy pictures, it is not sure whether your website can put them. The merchant needs to handle the review results by itself. Seven cattle approach is that every picture audit notice to audit.

Seven cattle incremental audit is applicable to the scene of real-time triggering content audit for resources uploaded to seven cattle object storage. After the seven cattle incremental audit is enabled, it can help you audit the newly uploaded resources in seconds, and support the automatic blocking of illegal resources in time to ensure business security.

Applicable demand scenarios: You have new resources uploaded to qiniu object store You need to trigger content review in real time after uploading resources The resource you need to audit has no prefix requirement or belongs to the specified prefix You need to automatically ban the illegal resources or you have the manpower to review the audit results after the audit is completed

Here is the address for how to open incremental audit: https://developer.qiniu.com/censor/manual/5922/incremental-audit#3

For the introduction of incremental interface callback, please refer to the following address:

https://developer.qiniu.com/censor/manual/5920/incremental-audit-callback

Let me show you my way of receiving the notice of seven cows:

Interface layer:

/**
	 * Seven cattle picture review callback
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/checkFileCallBack.do")
	@NoneAuth
	@LogConfig(actionName = "Seven cattle picture review callback")
	public ResponseVo checkFileCallBack(@RequestBody JSONObject param){
		try{
			log.info("checkFileCallBack param={}",param.toJSONString());
            this.commonService.checkFileCallBack(param);
			return ResponseVo.buildSuccessResponse();
		}catch (Exception e){
			log.error("checkFileCallBack e={}",e);
			return ResponseVo.buildFaildResponse();
		}
	}

Service level:

/**
     * Handling audit results
     * @param param
     */
    @Override
    public void checkFileCallBack(JSONObject param) {
        //Picture address
        String inputKey = param.getString("inputKey");
        //space
        String inputBucket = param.getString("inputBucket");
        //Get audit items
        JSONObject item = (JSONObject) param.getJSONArray("items").get(0);
        //Is it disabled directly
        boolean disable = item.getJSONObject("result").getBoolean("disable");
        boolean qiniuCheckFlag = false;
        if (disable){
            // Mo you is officially disabled or deleted
            qiniuCheckFlag = true;
        }else{
            //Check the audit result, whether it needs to be rechecked
            JSONObject checkResult = item.getJSONObject("result").getJSONObject("result");
            //Processing result
            int resultCode = checkResult.getIntValue("code");
            if (resultCode== HttpStatus.SC_OK){
                JSONObject scenesResult = checkResult.getJSONObject("scenes");
                //Chi Huang
                JSONObject pulpResult = scenesResult.getJSONObject("pulp");
                String suggestion = pulpResult.getString("suggestion");
                //Indicates that the system confirms that the audit content is in violation of regulations, and it is recommended that you delete it.
                if (StringUtils.equals(suggestion,"block")){
                    // Mo you is officially disabled or deleted
                    qiniuCheckFlag = true;
                }
                //Pictures of violence and fear
                JSONObject terrorResult = scenesResult.getJSONObject("terror");
                //Indicates that the system confirms that the audit content is in violation of regulations, and it is recommended that you delete it.
                suggestion = terrorResult.getString("suggestion");
                if (StringUtils.equals(suggestion,"block")){
                    // Mo you is officially disabled or deleted
                    qiniuCheckFlag = true;
                    //It means that the system cannot confirm whether the audit content is against the regulations. It is recommended that you conduct manual review.
                }
                //Image sensitive character recognition
                JSONObject politician = scenesResult.getJSONObject("politician");
                suggestion = politician.getString("suggestion");
                if (StringUtils.equals(suggestion,"block")){
                    // Mo you is officially disabled or deleted
                    qiniuCheckFlag = true;
                }
                //Advertisement recognition
                JSONObject ads = scenesResult.getJSONObject("ads");
                if (null!=ads){
                    suggestion = ads.getString("suggestion");
                    if (StringUtils.equals(suggestion,"block")){
                        // Mo you is officially disabled or deleted
                        qiniuCheckFlag = true;
                        //It indicates that the system is unable to confirm whether the audit content is in violation of regulations. It is recommended that you conduct manual review.
                    }
                }
            }else{
                String msg = checkResult.getString("msg");
                log.info("checkFileCallBack code={} msg={}",resultCode,msg);
            }
        }

        if (qiniuCheckFlag) {
            //Update documentation
            this.attachFilesService.qiniuCheckFile(inputKey,param.toJSONString());
        }
    }

Posted by tolli on Thu, 16 Apr 2020 02:10:23 -0700