1.RestTemplate 工具类
package cn.microvideo.module.ycgz.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.microvideo.module.ycgz.commonconstant.CommonConstant;
import cn.microvideo.module.ycgz.exception.BizException;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class FileHttpUtils {
@Resource
private RestTemplate restTemplate;
public String getSendHeaderBody(String url, HttpHeaders headers) {
try {
HttpEntity<MultiValuedMap<String, Object>> httpEntity = new HttpEntity<>(headers);
ResponseEntity<String> getForEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
if (getForEntity.getStatusCodeValue() != HttpStatus.OK.value()) {
throw new BizException(CommonConstant.ERROR_500, getForEntity.toString());
}
return getForEntity.getBody();
} catch (Exception e) {
throw new BizException(CommonConstant.ERROR_500, e.getMessage());
}
}
public String getSendHeaderParamBody(String url, HttpHeaders headers, MultiValuedMap<String, Object> params) {
try {
HttpEntity<MultiValuedMap<String, Object>> httpEntity = new HttpEntity<>(params, headers);
ResponseEntity<String> getForEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
if (getForEntity.getStatusCodeValue() != HttpStatus.OK.value()) {
throw new BizException(CommonConstant.ERROR_500, getForEntity.toString());
}
return getForEntity.getBody();
} catch (Exception e) {
throw new BizException(CommonConstant.ERROR_500, e.getMessage());
}
}
public String getSendParamBody(String url, Map<String, Object> params) {
try {
url = formatUrl(url, params);
ResponseEntity<String><