解决 ugc 内容检测报400015的问题
发布于 4 年前 作者 xujun 3758 次浏览 来自 分享

后端调用微信内容检测, 遇到400015错误,翻了下论坛没有答案
后面自己解决了, 直接上代码

           HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);

            HttpURLConnection urlConnection = (HttpURLConnection) new URL(imageUrl).openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            String contentLength = urlConnection.getHeaderField(HttpHeaders.CONTENT_LENGTH);

            String finalImageUrl = imageUrl;
            InputStreamResource resource = new InputStreamResource(inputStream) {
                @Override
                public long contentLength() throws IOException {
                    return Long.parseLong(contentLength);
                }

                @Override
                public String getFilename() {
                    return EncryptTool.md5(finalImageUrl);
                }
            };
            MultiValueMap form = new LinkedMultiValueMap<>();
            form.add("media", resource);

            HttpEntity<multivaluemap> params = new HttpEntity<>(form, headers);
            UGCCheckDto result = restTemplate.postForObject("https://api.weixin.qq.com/wxa/img_sec_check?access_token=" + tokenService.getAccessToken(), params, UGCCheckDto.class);
</multivaluemap
回到顶部