评论

解决 ugc 内容检测报400015的问题

解决 ugc 内容检测报400015的问题

后端调用微信内容检测, 遇到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);
最后一次编辑于  08-10  
点赞 0
收藏
评论
登录 后发表内容