JavaServer集成图谱鉴黄

2017-03-17  本文已影响0人  冰凝雪国
(适用于ydm-java接口与后台,如有误入,但愿也能给您带来帮助)
引子:

起源于社交,后宫应用,当时候业主考量周密,让增添这么一个功能,并推荐使用 图谱科技 的鉴黄。说白了就是在视频聊天时,截取两者的画面,传给接口,接口将图片地址告诉图谱,图谱给反馈,色情、性感、正常;并给出认定的百分比以及是否需要复审的状态。

碎碎念:
接口处理的代码:
/**
     * 保存鉴黄表信息
     */
    public String saveComplaint(Integer video_order,String img,String privateKey,HttpServletRequest request){
        //查询双方
        BalanceOfPayments balanceOfPayments  = balanceOfPaymentsMapper.queryConsumeById(video_order);
        //保存
        Complaint complaint = new Complaint();
        //请求图谱
        ArrayList<String> imgs = new ArrayList<String>();
        imgs.add(TUPUIMGPATH + img);
        String[] tags = {String.valueOf(video_order)};
        //返回值
        JSONObject obj = TuPuApi.tuPuApi(imgs, tags, privateKey);
        //验证是否请求成功
        Integer code = (Integer) obj.get("code");
        if(0 == code){
            log.info("成功接收到图谱的反馈,调用鉴黄成功");
            JSONObject objImg = (JSONObject) obj.get("54bcfc6c329af61034f7c2fc");
            List<JSONObject> fileList =  (List<JSONObject>) objImg.get("fileList");
            Double rate = (Double) fileList.get(0).get("rate");
            Integer label = (Integer) fileList.get(0).get("label");
            String name = (String) fileList.get(0).get("name");
            log.info(name);
            //fileList.get(0).get("tag");
            Boolean flag = (Boolean) fileList.get(0).get("review");
            Integer review = 2;
            if(flag){
                review = 1;
            }

            
            complaint.setVideo_order(video_order);//视频聊天订单号
            complaint.setBuy_id(balanceOfPayments.getBuyPersion().getId());//拨打人
            complaint.setSell_id(balanceOfPayments.getSellPersion().getId());//接听者
            complaint.setCreate_date(new Date());//鉴黄申请时间
            complaint.setReason("视频聊天自动鉴黄");//鉴黄备注
            complaint.setScreenshot(img);//鉴黄投诉图片
            complaint.setState(3);//图谱审核
            complaint.setType(0);//视频截图自动投诉

            complaint.setLabel(label);//(鉴黄)分类: 0:色情; 1:性感; 2:正常; 
            complaint.setReview(review);//(鉴黄)是否需要人工复审该图片  1需要  2不需要
            complaint.setRate(new BigDecimal(rate));//(鉴黄)图像被识别为某个分类的概率值


        }else{
            log.error("鉴黄反馈出错,具体原因为:" + obj.get("message"));
            return "passbuterror";
        }

        int count = complaintMapper.add_complaint(complaint);

        if(count != 1){
            log.error("保存鉴黄信息出错,视频订单id为:" + String.valueOf(video_order));
            return "passbuterror";
        }

        if(complaint.getLabel() == 2 && complaint.getReview() == 2){
            //删除鉴黄图片
            String var = PathUtil.GetAppName(request).replace("/", "\\");
            String project = PathUtil.GetAppRealPath(request);
            String path = project.replace(var+"\\", "").trim();
            FileUtil.delFile(path + img.replace("/", "\\"));
            return "pass";
        }else if(complaint.getLabel() != 2 && complaint.getReview() == 2){
            return "yellow";
        }else{
            return "maybe";
        }
    }

图谱提供的Api:

/**
     * 请求图谱
     * @param fileList   url的集合
     * @param tags       图片的附属信息
     * @param privateKey    私钥的路径
     * @return
     */
    public static JSONObject tuPuApi(ArrayList<String> fileList,String[] tags,String privateKey){
        
        Api api = new Api(SECRETID, privateKey);
        
        JSONObject result = api.doApiTest(ConfigUtil.UPLOAD_TYPE.UPLOAD_URI_TYPE, fileList,tags);
        
        return result;
    }
备注:
上一篇 下一篇

猜你喜欢

热点阅读