|
@@ -11,7 +11,6 @@ import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.HttpStatus;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
-import org.apache.http.client.ClientProtocolException;
|
|
|
import org.apache.http.client.CookieStore;
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
import org.apache.http.client.config.CookieSpecs;
|
|
@@ -54,7 +53,7 @@ import java.util.*;
|
|
|
@Slf4j
|
|
|
public class HttpUtils {
|
|
|
|
|
|
- public static JSONObject bytedanceGetRequest(String accessToken, String url, Map<String, Object> params) {
|
|
|
+ public static JSONObject bytedanceGetRequest(String accessToken, String url, JSONObject params) {
|
|
|
// 构造请求
|
|
|
HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
@Override
|
|
@@ -68,11 +67,11 @@ public class HttpUtils {
|
|
|
try {
|
|
|
client = HttpClientBuilder.create().build();
|
|
|
httpEntity.setURI(URI.create(url));
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(params), ContentType.APPLICATION_JSON));
|
|
|
+ httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
|
|
|
response = client.execute(httpEntity);
|
|
|
if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
String line = "";
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
result.append(line);
|
|
@@ -80,16 +79,16 @@ public class HttpUtils {
|
|
|
bufferedReader.close();
|
|
|
return JSONObject.parseObject(result.toString());
|
|
|
}
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
} finally {
|
|
|
try {
|
|
|
if (response != null) {
|
|
|
response.close();
|
|
|
}
|
|
|
- client.close();
|
|
|
+ if (client != null) {
|
|
|
+ client.close();
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -109,25 +108,24 @@ public class HttpUtils {
|
|
|
response = client.execute(httpEntity);
|
|
|
if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
String line = "";
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
result.append(line);
|
|
|
}
|
|
|
bufferedReader.close();
|
|
|
- System.out.println(JSONObject.parseObject(result.toString()));
|
|
|
return JSONObject.parseObject(result.toString());
|
|
|
}
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
try {
|
|
|
if (response != null) {
|
|
|
response.close();
|
|
|
}
|
|
|
- client.close();
|
|
|
+ if (client != null) {
|
|
|
+ client.close();
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -135,7 +133,7 @@ public class HttpUtils {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public static CookieStore cookieStore = new BasicCookieStore();
|
|
|
+ public static CookieStore COOKIESTORE = new BasicCookieStore();
|
|
|
/**
|
|
|
* setProxy(new HttpHost("106.125.239.179", 4245))
|
|
|
*/
|
|
@@ -153,7 +151,7 @@ public class HttpUtils {
|
|
|
}).build();
|
|
|
RequestConfig globalConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000).setCookieSpec(CookieSpecs.STANDARD).build();
|
|
|
SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext);
|
|
|
- return HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultRequestConfig(globalConfig).setConnectionReuseStrategy((response, context) -> false).setSSLSocketFactory(sslFactory).build();
|
|
|
+ return HttpClients.custom().setDefaultCookieStore(COOKIESTORE).setDefaultRequestConfig(globalConfig).setConnectionReuseStrategy((response, context) -> false).setSSLSocketFactory(sslFactory).build();
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理Https证书异常", e);
|
|
|
}
|
|
@@ -166,19 +164,11 @@ public class HttpUtils {
|
|
|
try {
|
|
|
HttpPost httppost = new HttpPost(url);
|
|
|
httppost.setHeader("User-Agent", USER_AGENT);
|
|
|
-
|
|
|
- List<Cookie> list = cookieStore.getCookies();
|
|
|
- for (Cookie ck : list) {
|
|
|
- System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
- }
|
|
|
- System.out.println("-------------------------------------");
|
|
|
for (String key : headers.keySet()) {
|
|
|
httppost.setHeader(key, headers.get(key));
|
|
|
}
|
|
|
List<NameValuePair> paramList = new ArrayList<NameValuePair>();
|
|
|
for (String key : param.keySet()) {
|
|
|
- System.out.println(key + "=" + String.valueOf(param.get(key)));
|
|
|
- System.out.println("-------------------------------------");
|
|
|
BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(param.get(key)));
|
|
|
paramList.add(basicNameValuePair);
|
|
|
}
|
|
@@ -187,8 +177,6 @@ public class HttpUtils {
|
|
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramList);
|
|
|
// 第一步:通过setEntity 将我们的entity对象传递过去
|
|
|
httppost.setEntity(formEntity);
|
|
|
-
|
|
|
-// httppost.setHeader("Content-Type", "application/json");
|
|
|
httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
|
|
|
HttpEntity respentity;
|
|
|
|
|
@@ -210,21 +198,15 @@ public class HttpUtils {
|
|
|
}
|
|
|
|
|
|
public static String httpPostRequest(String url, Map<String, Object> param, Map<String, String> headers) {
|
|
|
-// HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
String strReturn = "";
|
|
|
try {
|
|
|
HttpPost httppost = new HttpPost(url);
|
|
|
httppost.setHeader("User-Agent", USER_AGENT);
|
|
|
httppost.addHeader("Content-Type", "application/json");
|
|
|
- List<Cookie> list = cookieStore.getCookies();
|
|
|
-// for (Cookie ck : list) {
|
|
|
-// System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
-// }
|
|
|
for (String key : headers.keySet()) {
|
|
|
httppost.setHeader(key, headers.get(key));
|
|
|
}
|
|
|
- //httppost.setHeader("Content-Type", "application/json");
|
|
|
httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
|
|
|
HttpEntity respentity;
|
|
|
|
|
@@ -247,21 +229,19 @@ public class HttpUtils {
|
|
|
|
|
|
|
|
|
public static String httpPostRequestTest(String url, String body, Map<String, String> headers) {
|
|
|
-// HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
String strReturn = "";
|
|
|
try {
|
|
|
HttpPost httppost = new HttpPost(url);
|
|
|
httppost.setHeader("User-Agent", USER_AGENT);
|
|
|
httppost.addHeader("Content-Type", "application/json");
|
|
|
- List<Cookie> list = cookieStore.getCookies();
|
|
|
+ List<Cookie> list = COOKIESTORE.getCookies();
|
|
|
for (Cookie ck : list) {
|
|
|
System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
}
|
|
|
for (String key : headers.keySet()) {
|
|
|
httppost.setHeader(key, headers.get(key));
|
|
|
}
|
|
|
- //httppost.setHeader("Content-Type", "application/json");
|
|
|
httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
|
|
|
HttpEntity respentity;
|
|
|
|
|
@@ -314,21 +294,15 @@ public class HttpUtils {
|
|
|
|
|
|
|
|
|
public static String httpPostRequest(String url, JSONObject params, Map<String, String> headers) {
|
|
|
-// HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
String strReturn = "";
|
|
|
try {
|
|
|
HttpPost httppost = new HttpPost(url);
|
|
|
httppost.setHeader("User-Agent", USER_AGENT);
|
|
|
httppost.addHeader("Content-Type", "application/json");
|
|
|
- List<Cookie> list = cookieStore.getCookies();
|
|
|
-// for (Cookie ck : list) {
|
|
|
-// System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
-// }
|
|
|
for (String key : headers.keySet()) {
|
|
|
httppost.setHeader(key, headers.get(key));
|
|
|
}
|
|
|
- //httppost.setHeader("Content-Type", "application/json");
|
|
|
httppost.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
|
|
|
HttpEntity respentity;
|
|
|
|
|
@@ -353,19 +327,10 @@ public class HttpUtils {
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
HttpResponse response = null;
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
-// httpPost.setHeader("Content-Type", "application/json");
|
|
|
String result = null;
|
|
|
try {
|
|
|
httpGet.setHeader("User-Agent", USER_AGENT);
|
|
|
- List<Cookie> list2 = cookieStore.getCookies();
|
|
|
-// for (Cookie ck : list2) {
|
|
|
-// System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
-// }
|
|
|
response = httpClient.execute(httpGet);
|
|
|
- List<Cookie> list = cookieStore.getCookies();
|
|
|
-// for (Cookie ck : list) {
|
|
|
-// System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
-// }
|
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
|
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
|
|
|
String newUrl = response.getFirstHeader("Location").getValue();
|
|
@@ -387,7 +352,6 @@ public class HttpUtils {
|
|
|
}
|
|
|
|
|
|
public static String httpRequest(String url, String strParams) throws Exception {
|
|
|
-// HttpClient httpclient = HttpClientBuilder.create().build();
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
String strReturn = "";
|
|
|
try {
|
|
@@ -397,8 +361,6 @@ public class HttpUtils {
|
|
|
httppost.setEntity(new StringEntity(strParams, Charset.forName("UTF-8")));
|
|
|
HttpEntity respentity;
|
|
|
HttpResponse response = httpClient.execute(httppost);
|
|
|
- int code = response.getStatusLine().getStatusCode();
|
|
|
-
|
|
|
respentity = response.getEntity();
|
|
|
strReturn = EntityUtils.toString(respentity);
|
|
|
} catch (Exception e) {
|
|
@@ -409,7 +371,6 @@ public class HttpUtils {
|
|
|
}
|
|
|
|
|
|
public static String httpRequest(String url, CookieStore cookies, Map<String, String> parameterMap) throws Exception {
|
|
|
-// HttpClient httpclient = getHttpclient();
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
String strReturn = "";
|
|
|
try {
|
|
@@ -430,7 +391,7 @@ public class HttpUtils {
|
|
|
}
|
|
|
|
|
|
public static List<NameValuePair> getParam(Map parameterMap) {
|
|
|
- List<NameValuePair> param = new ArrayList<NameValuePair>();
|
|
|
+ List<NameValuePair> param = new ArrayList<>();
|
|
|
Iterator it = parameterMap.entrySet().iterator();
|
|
|
while (it.hasNext()) {
|
|
|
Map.Entry parmEntry = (Map.Entry) it.next();
|
|
@@ -451,13 +412,7 @@ public class HttpUtils {
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
HttpResponse response = null;
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
- List<Cookie> list = cookieStore.getCookies();
|
|
|
-// cookieStore.clear();
|
|
|
-// for (Cookie ck : list) {
|
|
|
-//
|
|
|
-// System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
-// }
|
|
|
-// System.out.println("-------------------------------------");
|
|
|
+ List<Cookie> list = COOKIESTORE.getCookies();
|
|
|
httpPost.setHeader("Content-Type", "application/json");
|
|
|
String result = null;
|
|
|
|
|
@@ -472,10 +427,6 @@ public class HttpUtils {
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
builder.append(line);
|
|
|
}
|
|
|
-// for (Cookie ck : list) {
|
|
|
-//
|
|
|
-// System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
|
|
|
-// }
|
|
|
result = builder.toString();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -483,11 +434,11 @@ public class HttpUtils {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public static Map<String, Integer> kuaishouNumberMap;
|
|
|
+ public static Map<String, Integer> KUAISHOUNUMBERMAP;
|
|
|
|
|
|
public static Integer getKuaishouNumber(String key) {
|
|
|
- if (kuaishouNumberMap == null) {
|
|
|
- kuaishouNumberMap = new HashMap<>();
|
|
|
+ if (KUAISHOUNUMBERMAP == null) {
|
|
|
+ KUAISHOUNUMBERMAP = new HashMap<>();
|
|
|
// kuaishouNumberMap.put("32.0#-6.0#526.0#729.0",0);//735
|
|
|
// kuaishouNumberMap.put("98.0#13.0#363.0#726.0",1);//713
|
|
|
// kuaishouNumberMap.put("32.0#13.0#527.0#732.0",2);//719
|
|
@@ -498,18 +449,18 @@ public class HttpUtils {
|
|
|
// kuaishouNumberMap.put("38.0#13.0#536.0#717.0",7);//704
|
|
|
// kuaishouNumberMap.put("33.0#-7.0#525.0#731.0",8);//738
|
|
|
// kuaishouNumberMap.put("37.0#-7.0#521.0#730.0",9);//737
|
|
|
- kuaishouNumberMap.put("494.0#735.0", 0);
|
|
|
- kuaishouNumberMap.put("265.0#713.0", 1);
|
|
|
- kuaishouNumberMap.put("495.0#719.0", 2);
|
|
|
- kuaishouNumberMap.put("500.0#736.0", 3);
|
|
|
- kuaishouNumberMap.put("510.0#718.0", 4);
|
|
|
- kuaishouNumberMap.put("493.0#722.0", 5);
|
|
|
- kuaishouNumberMap.put("491.0#737.0", 6);
|
|
|
- kuaishouNumberMap.put("498.0#704.0", 7);
|
|
|
- kuaishouNumberMap.put("492.0#738.0", 8);
|
|
|
- kuaishouNumberMap.put("484.0#737.0", 9);
|
|
|
+ KUAISHOUNUMBERMAP.put("494.0#735.0", 0);
|
|
|
+ KUAISHOUNUMBERMAP.put("265.0#713.0", 1);
|
|
|
+ KUAISHOUNUMBERMAP.put("495.0#719.0", 2);
|
|
|
+ KUAISHOUNUMBERMAP.put("500.0#736.0", 3);
|
|
|
+ KUAISHOUNUMBERMAP.put("510.0#718.0", 4);
|
|
|
+ KUAISHOUNUMBERMAP.put("493.0#722.0", 5);
|
|
|
+ KUAISHOUNUMBERMAP.put("491.0#737.0", 6);
|
|
|
+ KUAISHOUNUMBERMAP.put("498.0#704.0", 7);
|
|
|
+ KUAISHOUNUMBERMAP.put("492.0#738.0", 8);
|
|
|
+ KUAISHOUNUMBERMAP.put("484.0#737.0", 9);
|
|
|
}
|
|
|
- return kuaishouNumberMap.get(key);
|
|
|
+ return KUAISHOUNUMBERMAP.get(key);
|
|
|
}
|
|
|
|
|
|
public static void kuaishouTtf(String ttfName) {
|
|
@@ -521,44 +472,30 @@ public class HttpUtils {
|
|
|
|
|
|
TTFParser ttfParser = new TTFParser();
|
|
|
TrueTypeFont ttf = ttfParser.parse(urlconn.getInputStream());
|
|
|
-// System.out.println(new Gson().toJson(ttf.getGlyph().getGlyphs()));
|
|
|
GlyphData[] datas = ttf.getGlyph().getGlyphs();
|
|
|
CmapSubtable[] tables = ttf.getCmap().getCmaps();
|
|
|
- Gson gson = new Gson();
|
|
|
-// System.out.println(gson.toJson(tables));
|
|
|
CmapSubtable table = tables[0];
|
|
|
- Map<String, Integer> numberMap = new HashMap<String, Integer>();
|
|
|
- Map<String, String> fontMap = new HashMap<String, String>();
|
|
|
+ Map<String, String> fontMap = new HashMap<>();
|
|
|
for (int i = 0; i <= 13; i++) {
|
|
|
GlyphData data = datas[i];
|
|
|
if (data != null) {
|
|
|
-// System.out.println("getBoundingBox" + data.getBoundingBox());
|
|
|
float fx = data.getBoundingBox().getLowerLeftX();
|
|
|
float fy = data.getBoundingBox().getLowerLeftY();
|
|
|
float rx = data.getBoundingBox().getUpperRightX();
|
|
|
float ry = data.getBoundingBox().getUpperRightY();
|
|
|
Integer num = getKuaishouNumber(String.valueOf(rx - fx) + "#" + String.valueOf(ry - fy));
|
|
|
-// if (num != null) {
|
|
|
-// System.out.println(num);
|
|
|
-// }
|
|
|
fontMap.put(String.valueOf((char) table.getCharCodes(i).get(0).intValue()), String.valueOf(num));
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-// System.out.println(new Gson().toJson(fontMap));
|
|
|
fontsMap.put(ttfName, fontMap);
|
|
|
for (GlyphData data : datas) {
|
|
|
if (data != null) {
|
|
|
-// System.out.println("getBoundingBox" + data.getBoundingBox());
|
|
|
float fx = data.getBoundingBox().getLowerLeftX();
|
|
|
float fy = data.getBoundingBox().getLowerLeftY();
|
|
|
float rx = data.getBoundingBox().getUpperRightX();
|
|
|
float ry = data.getBoundingBox().getUpperRightY();
|
|
|
- Integer num = getKuaishouNumber(String.valueOf(fx) + "#" + String.valueOf(fy) + "#" + String.valueOf(rx) + "#" + String.valueOf(ry));
|
|
|
-// System.out.println(num);
|
|
|
}
|
|
|
}
|
|
|
-// System.out.println(new Gson().toJson(numberMap));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -646,7 +583,6 @@ public class HttpUtils {
|
|
|
public static String httpGet(String url, Map<String, Object> paramsMap, Map<String, String> headers) {
|
|
|
String result = null;
|
|
|
try {
|
|
|
- // CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
//创建参数列表
|
|
|
HttpClient httpclient = getHttpclient();
|
|
|
StringBuilder postBody = null;
|
|
@@ -687,6 +623,4 @@ public class HttpUtils {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|