@Override
public JSONObject updloadTemporaryPicture(MultipartFile file, String fileName, String type) {
RestTemplate restTemplate = new RestTemplate();
WxParam wxParam = null;
String url = "";
url = url.replace("{ACCESS_TOKEN}",token).replace("TYPE",type);
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = MediaType.parseMediaType("multipart/form-data");
headers.setContentType(mediaType);
MultiValueMap<String,Object> param = new LinkedMultiValueMap<>();
File file1 = new File(file.getOriginalFilename());
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),file1);
} catch (IOException e) {
e.printStackTrace();
}
FileSystemResource resource = new FileSystemResource(file1);
param.add("file",resource);
HttpEntity<MultiValueMap<String,Object>> formEntity = new HttpEntity<>(param, headers);
ResponseEntity<String> data = restTemplate.postForEntity(url, formEntity, String.class);
JSONObject jsonObject = JSONObject.parseObject(data.getBody());
if (file1.exists()){
file1.delete();
}
LogUtil.info(getClass(),"上传企业微信临时文件updloadTemporaryPictureFile返回信息:" + jsonObject);
return jsonObject;
}
你好,你可以参考:上传临时素材中文文件名乱码?
https://developers.weixin.qq.com/community/develop/doc/00020acd6483801e8f2b85a2256c00