|
@@ -419,6 +419,74 @@ public class HttpUtils {
|
|
|
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) {
|
|
|
HttpClient httpClient = createSslClientDefault();
|
|
|
HttpResponse response = null;
|
|
@@ -428,8 +496,10 @@ public class HttpUtils {
|
|
|
httpGet.setHeader("User-Agent", USER_AGENT);
|
|
|
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 httpGetRequest(newUrl);
|
|
|
} else if (statusCode == HttpStatus.SC_OK) {
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|