敏感图片检测 返回码41005 该咋整?跪求大佬指点 !
发布于 5 年前 作者 zhengjing 12092 次浏览 来自 官方Issues

敏感图片检测,总是返回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;
    }
1 回复

你好,可以社区搜索一下解决方案看是否能解决,例如参考这个帖子看看:https://developers.weixin.qq.com/community/develop/article/doc/0002c4823287f03853390375b5b013

回到顶部