SopUtil.java
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package cn.com.glsx.entmicro.util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class SopUtil {
private static String GENERATE_SHORT_URL_HTTP;
@Value("${sop.cdp.customer.shortUrl}")
public void setGenerateShortUrlApi(String api) {
GENERATE_SHORT_URL_HTTP = api;
}
private static final HttpHeaders headers = GetHeaders();
private static final RestTemplate restTemplate = new RestTemplate();
public static HttpHeaders GetHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return headers;
}
public static String GenerateShortUrl(String url, boolean isThroughAuth){
Map<String, Object> map = new HashMap<>();
map.put("url",url);
map.put("isThroughAuth",isThroughAuth);
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(map, headers);
String shortUrl = restTemplate.postForObject(GENERATE_SHORT_URL_HTTP, requestEntity, String.class);
log.info("sop GenerateShortUrl shortUrl:{}",shortUrl);
return shortUrl;
}
public static String GenerateShortUrl(List<String> urlList){
Map<String, Object> map = new HashMap<>();
map.put("urlList",urlList);
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(map, headers);
String shortUrl = restTemplate.postForObject(GENERATE_SHORT_URL_HTTP + "/batch", requestEntity, String.class);
log.info("sop GenerateShortUrl shortUrl:{}",shortUrl);
return shortUrl;
}
}