@Slf4j
public class RestTmpBaseServiceImpl {
@Autowired
public RestTemplate restTemplate;
public HttpHeaders buildHeader(){
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization","Bearer "+"token");
return headers;
}
public HttpEntity<Map<String,Object>> buildHttpRequest(Map<String, Object> body){
HttpEntity<Map<String,Object>> request = new HttpEntity<>(body, buildHeader());
return request;
}
public ResponseEntity<Map> buildPostForMapEntity(String url,Map<String,Object> body){
try{
HttpEntity<Map<String,Object>> request = buildHttpRequest(body);
log.info("请求地址:"+url);
log.info(("请求参数:"+ JSONObject.toJSONString(body)));
ResponseEntity<Map> response = restTemplate.postForEntity(url, request, Map.class);
log.info(("请求返回值:"+ JSONObject.toJSONString(response.getBody())));
return response;
}catch (Exception e){
e.printStackTrace();
log.error(("请求异常"+e.getMessage()));
return null;
}
}
12-30
1384
11-19