1 /**
2 * 定义调用外部接口实例
3 */
4 private static final RestTemplate INSTANCE = new RestTemplate();
5
6 public static RestTemplate getInstance() {
7 return HttpRequestService.INSTANCE;
8 }
9
10 /**
11 * @param uri uri
12 * @param param 请求参数
13 * @param responseType 返回值类型
14 * @param
15 * @return
16 */
17 publicT request(String uri, String param, Class responseType) {
18 // 设置请求头信息
19 HttpHeaders headers = new HttpHeaders();
20 MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
21 headers.setContentType(type);
22 headers.add("Accept-Charset", MediaType.APPLICATION_JSON.toString());
23 // 封装参数
24 HttpEntityobject = new HttpEntity<>(param, headers);
25 String url = YTX_URL + uri;
26 LOGGER.info("request url:{},appkey:{},ts:{},msgdgt:{}", url, appKey, ts, msgdgt);
27 ResponseEntityexchange = getInstance().exchange(url, HttpMethod.DELETE, object, responseType);
28 LOGGER.info("responseResult code:{},body:{}", exchange.getStatusCode(), exchange.getBody());
29 return exchange.getBody();
30 }