收藏
回答

你好是否有在小程序java调用图片风险检测的例子?

是否有在小程序java调用图片风险检测的例子

回答关注问题邀请回答
收藏

2 个回答

  • 社区运营专员-wetingtu
    社区运营专员-wetingtu
    2021-04-13

    你好,可以参考下这个https://developers.weixin.qq.com/community/develop/article/doc/00008ecf79c44895b379cbd145b013

    2021-04-13
    有用 1
    回复
  • 此何人哉
    此何人哉
    2021-04-14
    @PostMapping("/imgSecCheck2")
    @ApiOperation(value = "图片内容判断", notes = "")
    public CommonResponse<OpenIdVO> imgSecCheck2(
            @ApiParam(name = "file", value = "file", required = true) @RequestParam("file") MultipartFile file,
            @ApiParam(name = "access_token", value = "access_token", required = true) @RequestParam String access_token
    ) throws IOException {
        String url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=" + access_token;
        log.info("检验图片安全入参:{}", access_token);
        byte[] bytes = file.getBytes();
    
        HttpHeaders headers2 = new HttpHeaders();
        headers2.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
        ResponseEntity<String> responseEntity = restTemplateHttps.postForEntity(url, new HttpEntity<>(bytes, headers2), String.class);
    
        log.info("检验图片安全出参:{}", responseEntity);
        HttpStatus statusCode = responseEntity.getStatusCode();
        CommonResponse<OpenIdVO> resp = new CommonResponse<>();
        if (statusCode.value() == 200) {
            String bodyString = responseEntity.getBody();
            JSONObject body = JSONObject.parseObject(bodyString);
            Integer errcode = body.getInteger("errcode");
            String errmsg = body.getString("errmsg");
            if (errcode == 0) {
                resp.setMsg(errmsg);
            } else {
                resp.error(errcode, errmsg);
            }
        } else {
            resp.error(RespErrorCode.SERVICE_ERROR, "图片内容判断失败");
        }
        return resp;
    }
    

    解决了就是涉黄图片不好找

    2021-04-14
    有用
    回复
登录 后发表内容
问题标签