|
@@ -419,6 +419,74 @@ public class HttpUtils {
|
|
return strReturn;
|
|
return strReturn;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void main(String[] args){
|
|
|
|
+ String res = HttpUtils.getKuaishouShareUrl("http://yongzhou.s.gifshow.com/i/photo/lwx?userId=1400097524&photoId=5191805968879099278");
|
|
|
|
+ String path = res.split("\\?")[0];
|
|
|
|
+ String photoId = path.substring(path.lastIndexOf("/")+1,path.length());
|
|
|
|
+ path =path.substring(0,path.lastIndexOf("/"));
|
|
|
|
+ String uid = path.substring(path.lastIndexOf("/")+1,path.length());
|
|
|
|
+ System.out.println(uid);
|
|
|
|
+ System.out.println(photoId);
|
|
|
|
+ res = HttpUtils.postKuaishouVideoUrl("https://live.kuaishou.com/m_graphql",uid,photoId);
|
|
|
|
+ System.out.println(res);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String postKuaishouVideoUrl(String url,String uid,String photoId){
|
|
|
|
+ HttpClient httpClient = createSslClientDefault();
|
|
|
|
+ String strReturn = "";
|
|
|
|
+ String paramBody = "{\"operationName\":\"FeedQuery\",\"variables\":{\"principalId\":\""+uid+"\",\"photoId\":\""+photoId+"\"},\"query\":\"query FeedQuery($principalId: String, $photoId: String) {\\n feedById(principalId: $principalId, photoId: $photoId) {\\n currentWork {\\n timestamp\\n __typename\\n }\\n __typename\\n }\\n}\\n\"}";
|
|
|
|
+ try {
|
|
|
|
+ HttpPost httppost = new HttpPost(url);
|
|
|
|
+ httppost.setHeader("User-Agent", USER_AGENT);
|
|
|
|
+ httppost.addHeader("Content-Type", "application/json");
|
|
|
|
+// for (String key : headers.keySet()) {
|
|
|
|
+// httppost.setHeader(key, headers.get(key));
|
|
|
|
+// }
|
|
|
|
+ httppost.setEntity(new StringEntity(paramBody, Charset.forName("UTF-8")));
|
|
|
|
+ HttpEntity respentity;
|
|
|
|
+
|
|
|
|
+ HttpResponse response = httpClient.execute(httppost);
|
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
+
|
|
|
|
+ respentity = response.getEntity();
|
|
|
|
+ strReturn = EntityUtils.toString(respentity);
|
|
|
|
+ return strReturn;
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return strReturn;
|
|
|
|
+ }
|
|
|
|
+ public static String getKuaishouShareUrl(String url){
|
|
|
|
+ HttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
|
+ HttpResponse response = null;
|
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
|
+ httpGet.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build());
|
|
|
|
+ String result = null;
|
|
|
|
+ try {
|
|
|
|
+ httpGet.setHeader("User-Agent", USER_AGENT);
|
|
|
|
+ httpGet.setHeader("Accept-Encoding", "gzip, deflate, br");
|
|
|
|
+ httpGet.setHeader("Connection", "keep-alive");
|
|
|
|
+ httpGet.setHeader("Host", "yongzhou.s.gifshow.com");
|
|
|
|
+ httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
|
|
|
|
+ httpGet.setHeader("Upgrade-Insecure-Requests", "1");
|
|
|
|
+ httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
|
|
|
|
+ response = httpClient.execute(httpGet);
|
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
+ System.out.println(statusCode);
|
|
|
|
+ if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
|
|
|
|
+ String newUrl = response.getFirstHeader("Location").getValue();
|
|
|
|
+ System.out.println(newUrl);
|
|
|
|
+ return newUrl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
public static String httpGetRequest(String url) {
|
|
public static String httpGetRequest(String url) {
|
|
HttpClient httpClient = createSslClientDefault();
|
|
HttpClient httpClient = createSslClientDefault();
|
|
HttpResponse response = null;
|
|
HttpResponse response = null;
|
|
@@ -428,8 +496,10 @@ public class HttpUtils {
|
|
httpGet.setHeader("User-Agent", USER_AGENT);
|
|
httpGet.setHeader("User-Agent", USER_AGENT);
|
|
response = httpClient.execute(httpGet);
|
|
response = httpClient.execute(httpGet);
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
+ System.out.println(statusCode);
|
|
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
|
|
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
|
|
String newUrl = response.getFirstHeader("Location").getValue();
|
|
String newUrl = response.getFirstHeader("Location").getValue();
|
|
|
|
+ System.out.println(newUrl);
|
|
return httpGetRequest(newUrl);
|
|
return httpGetRequest(newUrl);
|
|
} else if (statusCode == HttpStatus.SC_OK) {
|
|
} else if (statusCode == HttpStatus.SC_OK) {
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
@@ -793,4 +863,147 @@ public class HttpUtils {
|
|
}
|
|
}
|
|
return strReturn;
|
|
return strReturn;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static JSONObject feishuGetRequest(String url, JSONObject params){
|
|
|
|
+ return feishuGetRequest(null,url,params);
|
|
|
|
+ }
|
|
|
|
+ public static JSONObject feishuPostRequest(String url,JSONObject params){
|
|
|
|
+ return feishuPostRequest(null,url,params);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String feishuGetRequestString(String url) {
|
|
|
|
+ // 构造请求
|
|
|
|
+ HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
+ @Override
|
|
|
|
+ public String getMethod() {
|
|
|
|
+ return "GET";
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ CloseableHttpClient client = null;
|
|
|
|
+ try {
|
|
|
|
+ client = HttpClientBuilder.create().build();
|
|
|
|
+ httpEntity.setURI(URI.create(url));
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
|
|
|
|
+ httpEntity.setConfig(requestConfig);
|
|
|
|
+ response = client.execute(httpEntity);
|
|
|
|
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
|
+ String line = "";
|
|
|
|
+ while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
+ result.append(line);
|
|
|
|
+ }
|
|
|
|
+ bufferedReader.close();
|
|
|
|
+ return result.toString();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (response != null) {
|
|
|
|
+ response.close();
|
|
|
|
+ }
|
|
|
|
+ if (client != null) {
|
|
|
|
+ client.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static JSONObject feishuGetRequest(String accessToken, String url, JSONObject params) {
|
|
|
|
+ System.out.println(url);
|
|
|
|
+ // 构造请求
|
|
|
|
+ HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
+ @Override
|
|
|
|
+ public String getMethod() {
|
|
|
|
+ return "GET";
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ if(accessToken != null){
|
|
|
|
+ httpEntity.setHeader("Authorization", accessToken);
|
|
|
|
+ }
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ CloseableHttpClient client = null;
|
|
|
|
+ try {
|
|
|
|
+ client = HttpClientBuilder.create().build();
|
|
|
|
+ httpEntity.setURI(URI.create(url));
|
|
|
|
+ if (params != null){
|
|
|
|
+ httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
|
|
|
|
+ }
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
|
|
|
|
+ httpEntity.setConfig(requestConfig);
|
|
|
|
+ response = client.execute(httpEntity);
|
|
|
|
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
|
+ String line = "";
|
|
|
|
+ while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
+ result.append(line);
|
|
|
|
+ }
|
|
|
|
+ bufferedReader.close();
|
|
|
|
+ return JSONObject.parseObject(result.toString());
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (response != null) {
|
|
|
|
+ response.close();
|
|
|
|
+ }
|
|
|
|
+ if (client != null) {
|
|
|
|
+ client.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static JSONObject feishuPostRequest(String accessToken, String url, JSONObject params) {
|
|
|
|
+ // 构造请求
|
|
|
|
+ HttpPost httpEntity = new HttpPost(url);
|
|
|
|
+ if(accessToken != null){
|
|
|
|
+ httpEntity.setHeader("Authorization", accessToken);
|
|
|
|
+ }
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ CloseableHttpClient client = null;
|
|
|
|
+ try {
|
|
|
|
+ client = HttpClientBuilder.create().build();
|
|
|
|
+ httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
|
|
|
|
+ httpEntity.setConfig(requestConfig);
|
|
|
|
+ response = client.execute(httpEntity);
|
|
|
|
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
|
+ String line = "";
|
|
|
|
+ while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
+ result.append(line);
|
|
|
|
+ }
|
|
|
|
+ bufferedReader.close();
|
|
|
|
+ return JSONObject.parseObject(result.toString());
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (response != null) {
|
|
|
|
+ response.close();
|
|
|
|
+ }
|
|
|
|
+ if (client != null) {
|
|
|
|
+ client.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|