我们小程序的用户图片都是直接上传到腾讯云的,还需要调用img_sec_check进行安全检测吗?
发布于 5 年前 作者 bxue 3672 次浏览 来自 官方Issues

如果还是要检测,img_seq_check接口该怎么调用?不知道怎么设置media字段,可以给个样例吗?

2 回复
    public String execute(CloseableHttpClient httpclient, String url, InputStream imgstream) throws IOException {
 
        HttpPost httpost = new HttpPost(url);
 
        HttpEntity entry = MultipartEntityBuilder
                .create()
                .addBinaryBody("media",imgstream)
                .setMode(HttpMultipartMode.RFC6532)
                .build();
        httpost.setEntity(entry);
 
        try (CloseableHttpResponse response = httpclient.execute(httpost)) {
            String responseContent = resputf8handle.handleResponse(response);
            //如果请求发生错误,抛出异常
            ObjectMapper mapper = new ObjectMapper();
            JsonNode node = mapper.readTree(responseContent);
            if (node.get("errcode") != null && !(node.get("errcode").asInt() == 0)) {
                //WxError error = WxError.fromJson(responseContent);
                //throw new Exception(responseContent);
            }
            return responseContent;
        }
    }
}

把网络图片读到InputStream并缩放到1000x1000以下尺寸,然后用上面代码Post,得到下面错误:

RetryExec.java:97) I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.weixin.qq.com:443: Connection reset by peer: socket write error

还缺什么吗?

Java代码片段

回到顶部