java恶意小程序_小程序java实现校验一张图片是否含有违法违规内容security.imgSecCheck...

官方文档位置:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html

java 代码实现/**     *  恶意图片过滤     * @param multipartFile     * @return     */    public static Boolean checkPic(MultipartFile multipartFile, String accessToken) {        try {            CloseableHttpClient httpclient = HttpClients.createDefault();            CloseableHttpResponse response = null;            HttpPost request = new HttpPost("https://api.weixin.qq.com/wxa/img_sec_check?access_token=" + accessToken);            request.addHeader("Content-Type", "application/octet-stream");            InputStream inputStream = multipartFile.getInputStream();            byte[] byt = new byte[inputStream.available()];            inputStream.read(byt);            request.setEntity(new ByteArrayEntity(byt, ContentType.create("image/jpg")));            response = httpclient.execute(request);            HttpEntity httpEntity = response.getEntity();            String result = EntityUtils.toString(httpEntity, "UTF-8");// 转成string            JSONObject jso = JSONObject.parseObject(result);            System.out.println(jso + "-------------验证效果");            Object errcode = jso.get("errcode");            int errCode = (int) errcode;            if (errCode == 0) {                return true;            } else if (errCode == 87014) {                System.out.println("图片内容违规-----------");                return false;            }            return true;        } catch (Exception e) {            e.printStackTrace();            System.out.println("----------------调用腾讯内容过滤系统出错------------------");            return true;        }    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值