收藏
回答

敏感图片检测 返回码41005 该咋整?跪求大佬指点 !

敏感图片检测,总是返回41005,根据官方文档的说法,41005 表示缺少多媒体数据,但是通过debug跟踪,图片文件的数据已经传了,急求个各位路过的大佬帮忙看看,是咋回事????

public boolean checkImgByInputStream(File file) throws Exception{
        //1 创建HttpClient请求对象
        CloseableHttpClient httpclient = HttpClients.createDefault();
        //2 创建Http POST请求
        HttpPost request = new HttpPost("https://api.weixin.qq.com/wxa/img_sec_check?access_token=" + accessToken);
        request.addHeader("Content-Type", "application/octet-stream;charset=UTF-8");
        //3 图片转换程流文件
        InputStream inputStream =  new FileInputStream(file);
        byte[] byt = new byte[inputStream.available()];
        inputStream.read(byt);
        //4 获取图片content类型,封装参数到请求中
        String type = URLConnection.guessContentTypeFromName(file.getName());
        request.setEntity(new ByteArrayEntity(byt, ContentType.create(type)));
        //5 创建接收HttpResponse响应对象,接收执行结果
        CloseableHttpResponse response = null;
        try {
            response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();
            String resultInfo = EntityUtils.toString(entity, "UTF-8");
            logger.info("--图片转换--result: " + resultInfo);
 
            //将结果转成json格式
            JSONObject jso =  JSONObject.parseObject(resultInfo);
            int errcode = (int)jso.get("errcode");
            if (errcode == 0) {
                return true;
            }else if (errcode == 87014) {
                logger.info("------>上传的图片违规");
                return false;
            }else {
                logger.info("------>检测失败");
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("----------------调用腾讯图片图片检测出错------------------");
        }finally {
            if (response != null) {
                 response.close();
            }
            httpclient.close();
        }
        return false;
    }

最后一次编辑于  09-25
回答关注问题邀请回答
收藏

1 个回答

问题标签