Merge branch 'tianyiCommon' into mine
# Conflicts: # app/src/main/java/com/github/catvod/api/SimpleCookieJar.java
This commit is contained in:
commit
1401bbf07f
|
|
@ -6,12 +6,10 @@ import com.github.catvod.bean.tianyi.User;
|
|||
import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.utils.Json;
|
||||
import com.github.catvod.utils.Path;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -19,19 +17,17 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.CookieJar;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class SimpleCookieJar implements CookieJar {
|
||||
private Map<String, List<Cookie>> cookieStore = new HashMap<>();
|
||||
public class SimpleCookieJar {
|
||||
private Map<String, Map<String, String>> cookieStore = new HashMap<>();
|
||||
private final Cache cache;
|
||||
|
||||
public Map<String, List<Cookie>> getCookieStore() {
|
||||
public Map<String, Map<String, String>> getCookieStore() {
|
||||
return cookieStore;
|
||||
}
|
||||
|
||||
public void setCookieStore(Map<String, List<Cookie>> cookieStore) {
|
||||
public void setCookieStore(Map<String, Map<String, String>> cookieStore) {
|
||||
this.cookieStore = cookieStore;
|
||||
}
|
||||
|
||||
|
|
@ -49,85 +45,68 @@ public class SimpleCookieJar implements CookieJar {
|
|||
return Path.tv("tianyi");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFromResponse(HttpUrl url, @NotNull List<Cookie> cookies) {
|
||||
SpiderDebug.log(" ====saveFromResponse url: " + url.host() + ": " + Json.toJson(cookies));
|
||||
SpiderDebug.log(" ====saveFromResponse cookie: " + Json.toJson(cookies));
|
||||
|
||||
public void saveFromResponse(String url, List<String> cookies) {
|
||||
HttpUrl httpUrl = HttpUrl.parse(url);
|
||||
SpiderDebug.log(" saveFromResponse url: " + url);
|
||||
SpiderDebug.log(" saveFromResponse cookie : " + Json.toJson(cookies));
|
||||
// 创建可修改的 Cookie 列表副本
|
||||
List<Cookie> oldCookies = cookieStore.get(url.host()) != null ? cookieStore.get(url.host()) : new ArrayList<>();
|
||||
List<Cookie> newCookies = new ArrayList<>(oldCookies);
|
||||
Map<String, String> oldCookies = cookieStore.get(httpUrl.host()) != null ? cookieStore.get(httpUrl.host()) : new HashMap<>();
|
||||
|
||||
// 更新 Cookie
|
||||
for (Cookie newCookie : cookies) {
|
||||
// 移除同名的旧 Cookie
|
||||
for (Cookie oldCookie : newCookies) {
|
||||
if (oldCookie.name().equals(newCookie.name())) {
|
||||
oldCookies.remove(oldCookie);
|
||||
}
|
||||
for (String newCookie : cookies) {
|
||||
String[] split = newCookie.split(";");
|
||||
String cookieItem = split[0].trim();
|
||||
int equalsIndex = cookieItem.indexOf('=');
|
||||
if (equalsIndex > 0) {
|
||||
String key = cookieItem.substring(0, equalsIndex);
|
||||
String value = equalsIndex < cookieItem.length() - 1 ? cookieItem.substring(equalsIndex + 1) : "";
|
||||
oldCookies.put(key, value);
|
||||
}
|
||||
}
|
||||
oldCookies.addAll(cookies);
|
||||
|
||||
cookieStore.put(url.host(), oldCookies);
|
||||
|
||||
cookieStore.put(httpUrl.host(), oldCookies);
|
||||
cache.setTianyiUser(User.objectFrom(Json.toJson(cookieStore)));
|
||||
SpiderDebug.log(" cookieStore now : " + Json.toJson(cookieStore));
|
||||
SpiderDebug.log(" cookieStore now: " + Json.toJson(cookieStore));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<Cookie> loadForRequest(HttpUrl url) {
|
||||
|
||||
|
||||
var cookies = cookieStore.get(url.host());
|
||||
SpiderDebug.log(" ===loadForRequest url : " + url);
|
||||
SpiderDebug.log(" ===loadForRequest cookie: " + Json.toJson(cookies));
|
||||
return cookies != null ? cookies : new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setGlobalCookie(JsonObject jsonObject) {
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
JsonArray value = entry.getValue().getAsJsonArray();
|
||||
for (JsonElement element : value) {
|
||||
JsonObject cookieobj = element.getAsJsonObject();
|
||||
Cookie.Builder cookieBuilder = new Cookie.Builder().name(cookieobj.get("name").getAsString()).value(cookieobj.get("value").getAsString())
|
||||
|
||||
.expiresAt(cookieobj.get("expiresAt").getAsLong()).path(cookieobj.get("path").getAsString());
|
||||
|
||||
boolean secure = cookieobj.get("secure").getAsBoolean();
|
||||
if (secure) {
|
||||
cookieBuilder.secure();
|
||||
}
|
||||
|
||||
boolean httpOnly = cookieobj.get("httpOnly").getAsBoolean();
|
||||
if (httpOnly) {
|
||||
cookieBuilder.httpOnly();
|
||||
}
|
||||
boolean persistent = cookieobj.get("persistent").getAsBoolean();
|
||||
/* if (persistent) {
|
||||
cookieBuilder.persistent();
|
||||
}*/
|
||||
boolean hostOnly = cookieobj.get("hostOnly").getAsBoolean();
|
||||
if (hostOnly) {
|
||||
cookieBuilder.hostOnlyDomain(cookieobj.get("domain").getAsString());
|
||||
} else {
|
||||
cookieBuilder.domain(cookieobj.get("domain").getAsString());
|
||||
|
||||
}
|
||||
Cookie cookies = cookieBuilder.build();
|
||||
|
||||
|
||||
// 设置全局Cookie
|
||||
List<Cookie> cookiesForHost = cookieStore.get(key) == null ? new ArrayList<>() : cookieStore.get(key);
|
||||
cookiesForHost.add(cookies);
|
||||
cookieStore.put(key, cookiesForHost);
|
||||
JsonObject value = entry.getValue().getAsJsonObject();
|
||||
Map<String, String> cookiesForHost = new HashMap<>();
|
||||
for (String k : value.keySet()) {
|
||||
String cookieobj = value.get(k).getAsString();
|
||||
cookiesForHost.put(k, cookieobj);
|
||||
}
|
||||
cookieStore.put(key, cookiesForHost);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Map<String, List<Cookie>> getCookie() {
|
||||
return cookieStore;
|
||||
/**
|
||||
* 根据请求URl获取cookie
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public String loadForRequest(String url) {
|
||||
HttpUrl httpUrl = HttpUrl.parse(url);
|
||||
Map<String, String> cookieMap = cookieStore.get(httpUrl.host());
|
||||
List<String> cookieList = new ArrayList<>();
|
||||
if (cookieMap != null && cookieMap.size() > 0) {
|
||||
for (String s : cookieMap.keySet()) {
|
||||
cookieList.add(s + "=" + cookieMap.get(s));
|
||||
}
|
||||
}
|
||||
String cookie = StringUtils.join(cookieList, ";");
|
||||
SpiderDebug.log(" loadForRequest url:" + url);
|
||||
SpiderDebug.log(" loadForRequest cookie:" + cookie);
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,29 +7,41 @@ import android.graphics.drawable.ColorDrawable;
|
|||
import android.view.Gravity;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.github.catvod.bean.tianyi.Cache;
|
||||
import com.github.catvod.bean.tianyi.User;
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.net.OkHttpWithCookie;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.net.OkResult;
|
||||
import com.github.catvod.spider.Init;
|
||||
import com.github.catvod.utils.*;
|
||||
import com.github.catvod.utils.Json;
|
||||
import com.github.catvod.utils.Notify;
|
||||
import com.github.catvod.utils.Path;
|
||||
import com.github.catvod.utils.QRCode;
|
||||
import com.github.catvod.utils.ResUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class TianYiHandler {
|
||||
|
||||
public static final String API_URL = "https://open.e.189.cn";
|
||||
|
|
@ -52,11 +64,15 @@ public class TianYiHandler {
|
|||
|
||||
private SimpleCookieJar cookieJar;
|
||||
|
||||
public SimpleCookieJar getCookieJar() {
|
||||
return cookieJar;
|
||||
}
|
||||
|
||||
public TianYiHandler() {
|
||||
|
||||
|
||||
cache = Cache.objectFrom(Path.read(getCache()));
|
||||
cookieJar = new SimpleCookieJar();
|
||||
cache = Cache.objectFrom(Path.read(getCache()));
|
||||
|
||||
}
|
||||
|
||||
public void cleanCookie() {
|
||||
|
|
@ -64,52 +80,55 @@ public class TianYiHandler {
|
|||
cache.setTianyiUser(new User(""));
|
||||
}
|
||||
|
||||
public SimpleCookieJar getCookieJar() {
|
||||
return cookieJar;
|
||||
}
|
||||
|
||||
public void setCookie(JsonObject cookie) {
|
||||
cookieJar.setGlobalCookie(cookie);
|
||||
private Map<String, String> getHeader(String url) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
|
||||
headers.put("Cookie", cookieJar.loadForRequest(url));
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void refreshCookie() throws IOException {
|
||||
|
||||
|
||||
String url = "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fweb%2Fredirect.html&defaultSaveName=3&defaultSaveNameCheck=uncheck&browserId=16322f24d9405fb83331c3f6ce971b53";
|
||||
String index = OkHttpWithCookie.getLocation(url, Map.of("Cookie", ""), cookieJar);
|
||||
SpiderDebug.log("index:" + index);
|
||||
SpiderDebug.log("index red: " + index);
|
||||
Map<String, List<String>> resHeaderMap = OkHttpWithCookie.getLocationHeader(index, Map.of("Cookie", ""), cookieJar);
|
||||
|
||||
String index = OkHttp.getLocation(url, getHeader(url));
|
||||
SpiderDebug.log("unifyAccountLogin:" + index);
|
||||
|
||||
Map<String, List<String>> resHeaderMap = OkHttp.getLocationHeader(index, getHeader(index));
|
||||
saveCookie(resHeaderMap.get("Set-Cookie"), index);
|
||||
indexUrl = resHeaderMap.get("Location").get(0);
|
||||
SpiderDebug.log("indexUrl red: " + indexUrl);
|
||||
OkResult okResult = OkHttpWithCookie.get(indexUrl, new HashMap<>(), Map.of("Cookie", ""), cookieJar);
|
||||
SpiderDebug.log("callbackUnify: " + indexUrl);
|
||||
|
||||
SpiderDebug.log("refreshCookie header:" + Json.toJson(okResult.getResp()));
|
||||
Map<String, List<String>> callbackUnify = OkHttp.getLocationHeader(indexUrl, getHeader(indexUrl));
|
||||
saveCookie(callbackUnify.get("Set-Cookie"), indexUrl);
|
||||
SpiderDebug.log("refreshCookie header:" + Json.toJson(callbackUnify));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存cookie
|
||||
*
|
||||
* @param cookie
|
||||
* @param url
|
||||
*/
|
||||
private void saveCookie(List<String> cookie, String url) {
|
||||
if (cookie != null && cookie.size() > 0) {
|
||||
cookieJar.saveFromResponse(url, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] startScan() throws Exception {
|
||||
|
||||
|
||||
/* OkResult okResult1 = OkHttp.get("https://ux.21cn.com/api/htmlReportRest/getJs.js?pid=25577E0DEEDF48ADBD4459911F5825E4", new HashMap<>(), new HashMap<>());
|
||||
|
||||
getCookieMap(okResult1.getResp().get("Set-Cookie"));
|
||||
this.cookie = mapToCookie(cookieMap);*/
|
||||
SpiderDebug.log("index ori: " + "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fweb%2Fredirect.html&defaultSaveName=3&defaultSaveNameCheck=uncheck&browserId=dff95dced0b03d9d972d920f03ddd05e");
|
||||
String index = OkHttpWithCookie.getLocation("https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https://cloud.189.cn/web/redirect.html&defaultSaveName=3&defaultSaveNameCheck=uncheck&browserId=8d38da4344fba4699d13d6e6854319d7", Map.of("Cookie", ""), cookieJar);
|
||||
String index = OkHttp.getLocation("https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https://cloud.189.cn/web/redirect.html&defaultSaveName=3&defaultSaveNameCheck=uncheck&browserId=8d38da4344fba4699d13d6e6854319d7", Map.of("Cookie", ""));
|
||||
SpiderDebug.log("index red: " + index);
|
||||
Map<String, List<String>> resHeaderMap = OkHttpWithCookie.getLocationHeader(index, new HashMap<>(), cookieJar);
|
||||
Map<String, List<String>> resHeaderMap = OkHttp.getLocationHeader(index, getHeader(index));
|
||||
|
||||
saveCookie(resHeaderMap.get("Set-Cookie"), index);
|
||||
|
||||
indexUrl = resHeaderMap.get("Location").get(0);
|
||||
SpiderDebug.log("indexUrl red: " + indexUrl);
|
||||
|
||||
|
||||
/* getCookieMap(resHeaderMap.get("Set-Cookie"));
|
||||
this.cookie = mapToCookie(cookieMap);
|
||||
SpiderDebug.log("secondCookie: " + cookie);*/
|
||||
|
||||
HttpUrl httpParams = HttpUrl.parse(indexUrl);
|
||||
reqId = httpParams.queryParameter("reqId");
|
||||
lt = httpParams.queryParameter("lt");
|
||||
|
|
@ -144,15 +163,13 @@ public class TianYiHandler {
|
|||
|
||||
OkResult okResult;
|
||||
if ("GET".equals(method)) {
|
||||
okResult = OkHttpWithCookie.get(this.API_URL + url, params, headers, cookieJar);
|
||||
okResult = OkHttp.get(this.API_URL + url, params, headers);
|
||||
} else {
|
||||
okResult = OkHttpWithCookie.post(this.API_URL + url, params, headers, cookieJar);
|
||||
okResult = OkHttp.post(this.API_URL + url, params, headers);
|
||||
}
|
||||
if (okResult.getResp().get("Set-Cookie") != null) {
|
||||
saveCookie(okResult.getResp().get("Set-Cookie"), this.API_URL);
|
||||
}
|
||||
/* if (okResult.getResp().get("Set-Cookie") != null) {
|
||||
geteCookieMap(okResult.getResp().get("Set-Cookie"));
|
||||
this.ecookie = mapToCookie(ecookieMap);
|
||||
SpiderDebug.log("cookie: " + this.ecookie);
|
||||
}*/
|
||||
|
||||
if (okResult.getCode() != 200 && leftRetry > 0) {
|
||||
SpiderDebug.log("请求" + url + " failed;");
|
||||
|
|
@ -171,14 +188,14 @@ public class TianYiHandler {
|
|||
*/
|
||||
|
||||
private @NotNull Result appConf() throws Exception {
|
||||
Map<String, String> tHeaders = new HashMap<>();
|
||||
Map<String, String> tHeaders = getHeader(API_URL);
|
||||
tHeaders.put("Content-Type", "application/x-www-form-urlencoded");
|
||||
tHeaders.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/76.0");
|
||||
tHeaders.put("Referer", indexUrl);
|
||||
tHeaders.put("origin", API_URL);
|
||||
tHeaders.put("Lt", lt);
|
||||
tHeaders.put("Reqid", reqId);
|
||||
//tHeaders.put("Cookie", secondCookie);
|
||||
|
||||
Map<String, String> param = new HashMap<>();
|
||||
|
||||
param.put("version", "2.0");
|
||||
|
|
@ -195,6 +212,10 @@ public class TianYiHandler {
|
|||
return new Result(paramId, returnUrl);
|
||||
}
|
||||
|
||||
public void setCookie(JsonObject obj) {
|
||||
cookieJar.setGlobalCookie(obj);
|
||||
}
|
||||
|
||||
private static class Result {
|
||||
public final String paramId;
|
||||
public final String returnUrl;
|
||||
|
|
@ -206,17 +227,6 @@ public class TianYiHandler {
|
|||
}
|
||||
|
||||
|
||||
private static @NotNull List<String> getCookieList(List<String> cookie) {
|
||||
List<String> cookieList = new ArrayList<>();
|
||||
for (String s : cookie) {
|
||||
String[] split = s.split(";");
|
||||
String cookie1 = split[0];
|
||||
cookieList.add(cookie1);
|
||||
}
|
||||
return cookieList;
|
||||
}
|
||||
|
||||
|
||||
public JsonObject getUUID() throws InterruptedException {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("appId", "cloud");
|
||||
|
|
@ -245,7 +255,7 @@ public class TianYiHandler {
|
|||
HttpUrl url = HttpUrl.parse(API_URL + "/api/logbox/oauth2/image.do?uuid=" + uuid + "&REQID=" + reqId).newBuilder().build();
|
||||
|
||||
Request request = new Request.Builder().url(url).headers(Headers.of(headers)).build();
|
||||
Response response = OkHttpWithCookie.newCall(request, cookieJar);
|
||||
Response response = OkHttp.newCall(request);
|
||||
if (response.code() == 200) {
|
||||
return response.body().bytes();
|
||||
}
|
||||
|
|
@ -296,9 +306,8 @@ public class TianYiHandler {
|
|||
private void fetchUserInfo(String redirectUrl) throws IOException {
|
||||
|
||||
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
|
||||
Map<String, List<String>> okResult = OkHttpWithCookie.getLocationHeader(redirectUrl, headers, cookieJar);
|
||||
Map<String, List<String>> okResult = OkHttp.getLocationHeader(redirectUrl, getHeader(redirectUrl));
|
||||
saveCookie(okResult.get("Set-Cookie"), redirectUrl);
|
||||
SpiderDebug.log("扫码返回数据:" + Json.toJson(okResult));
|
||||
if (okResult.containsKey("set-cookie")) {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,13 @@ import com.github.catvod.bean.Vod;
|
|||
import com.github.catvod.bean.tianyi.Item;
|
||||
import com.github.catvod.bean.tianyi.ShareData;
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.net.OkHttpWithCookie;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.net.OkResult;
|
||||
import com.github.catvod.spider.Init;
|
||||
import com.github.catvod.utils.*;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import okhttp3.Cookie;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -53,7 +52,7 @@ public class TianyiApi {
|
|||
JsonObject obj = Json.safeObject(token);
|
||||
//初始化CookieJar
|
||||
if (Objects.nonNull(obj)) {
|
||||
tianYiHandler.setCookie(obj);
|
||||
//TODO tianYiHandler.setCookie(obj);
|
||||
}
|
||||
}
|
||||
if (cookieJar.getCookieStore().size() == 0) {
|
||||
|
|
@ -145,9 +144,9 @@ public class TianyiApi {
|
|||
header.remove("Content-Type");
|
||||
List<String> cookies = new ArrayList<>();
|
||||
for (String s : tianYiHandler.getCookieJar().getCookieStore().keySet()) {
|
||||
for (Cookie cookie : tianYiHandler.getCookieJar().getCookieStore().get(s)) {
|
||||
/*TODO for (Cookie cookie : tianYiHandler.getCookieJar().getCookieStore().get(s)) {
|
||||
cookies.add(cookie.name() + "=" + cookie.value());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
header.put("Cookie", TextUtils.join(";", cookies));
|
||||
return Result.get().url(ProxyVideo.buildCommonProxyUrl(playUrl, header)).octet().header(header).string();
|
||||
|
|
@ -170,9 +169,9 @@ public class TianyiApi {
|
|||
|
||||
OkResult okResult;
|
||||
if ("GET".equals(method)) {
|
||||
okResult = OkHttpWithCookie.get(this.apiUrl + url, params, getHeaders(), cookieJar);
|
||||
okResult = OkHttp.get(this.apiUrl + url, params, getHeaders());
|
||||
} else {
|
||||
okResult = OkHttpWithCookie.post(this.apiUrl + url, Json.toJson(data), getHeaders(), cookieJar);
|
||||
okResult = OkHttp.post(this.apiUrl + url, Json.toJson(data), getHeaders());
|
||||
}
|
||||
/* if (okResult.getResp().get("Set-Cookie") != null) {
|
||||
Matcher matcher = Pattern.compile("__puus=([^;]+)").matcher(StringUtils.join(okResult.getResp().get("Set-Cookie"), ";;;"));
|
||||
|
|
@ -235,13 +234,13 @@ public class TianyiApi {
|
|||
|
||||
|
||||
private String getUserBriefInfo() throws Exception {
|
||||
OkResult result = OkHttpWithCookie.get("https://cloud.189.cn/api/portal/v2/getUserBriefInfo.action", new HashMap<>(), getHeaders(), cookieJar);
|
||||
OkResult result = OkHttp.get("https://cloud.189.cn/api/portal/v2/getUserBriefInfo.action", new HashMap<>(), getHeaders());
|
||||
JsonObject obj = Json.safeObject(result.getBody());
|
||||
return obj.get("sessionKey") == null ? "" : obj.get("sessionKey").getAsString();
|
||||
}
|
||||
|
||||
private String getUserSizeInfo() throws Exception {
|
||||
OkResult result = OkHttpWithCookie.get("https://cloud.189.cn/api/portal/getUserSizeInfo.action", new HashMap<>(), getHeaders(), cookieJar);
|
||||
OkResult result = OkHttp.get("https://cloud.189.cn/api/portal/getUserSizeInfo.action", new HashMap<>(), getHeaders());
|
||||
JsonObject res = Json.safeObject(result.getBody());
|
||||
if (StringUtils.isAllBlank(result.getBody()) || (Objects.nonNull(res.get("errorCode")) && res.get("errorCode").getAsString().equals("InvalidSessionKey"))) {
|
||||
// tianYiHandler.startScan();
|
||||
|
|
@ -373,7 +372,7 @@ public class TianyiApi {
|
|||
private String getDownload(String shareId, String fileId) throws Exception {
|
||||
Map<String, String> headers = getHeaders();
|
||||
//headers.remove("sessionKey");
|
||||
OkResult result = OkHttpWithCookie.get("https://cloud.189.cn/api/portal/getNewVlcVideoPlayUrl.action?shareId=" + shareId + "&dt=1&fileId=" + fileId + "&type=4&key=noCache", new HashMap<>(), headers, cookieJar);
|
||||
OkResult result = OkHttp.get("https://cloud.189.cn/api/portal/getNewVlcVideoPlayUrl.action?shareId=" + shareId + "&dt=1&fileId=" + fileId + "&type=4&key=noCache", new HashMap<>(), headers);
|
||||
JsonObject res = Json.safeObject(result.getBody());
|
||||
if (Objects.nonNull(res.get("res_code")) && res.get("res_code").getAsInt() == 0) {
|
||||
|
||||
|
|
@ -385,7 +384,7 @@ public class TianyiApi {
|
|||
}
|
||||
} else if (res.get("errorCode") != null && res.get("errorCode").getAsString().equals("InvalidSessionKey")) {
|
||||
//刷新cookie
|
||||
SpiderDebug.log("cookie 过期,刷新cookie。。。。");
|
||||
SpiderDebug.log("天意cookie 过期,刷新cookie。。。。");
|
||||
tianYiHandler.refreshCookie();
|
||||
//重试下载
|
||||
SpiderDebug.log("重试下载。。。。");
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class TianYiHandlerTest {
|
|||
@Test
|
||||
public void refreshCookie() throws Exception {
|
||||
|
||||
JsonObject obj = Json.safeObject("{\"open.e.189.cn\":[{\"name\":\"SSON\",\"value\":\"dc466c8192e3109eaea837c1d136c1fd065253ce1c7d3a66ca1520d7d6d6307b10a1fe65c7becac73b95f24a6e681e654ec4f47c39533ebcc48bb78d6d6e63d1bbf3334e6e97eaa7092d34f87bf1209ee35f344871bc5a329eac34ae948d399d4a6b3b28a929c4f353ade0981657e9e0f09ce27cc1c15d8322c6e45a8ebb21eb431509f1dd7dc3a7856b32b0991d654d5ced73dd20b764ca8737600cbe699c37ccf59b3c610893fc42bdc08b477c5d394e290c14d175d1ca0ee9fa61a1a8dcac7007e9219fd0ae6ccd5dc760524213f85b6b8c6166af01a31336dab797d9118010b81a5a3c26e08e\",\"expiresAt\":253402300799999,\"domain\":\"e.189.cn\",\"path\":\"/\",\"secure\":true,\"httpOnly\":true,\"persistent\":true,\"hostOnly\":false},{\"name\":\"GUID\",\"value\":\"525d8874e53e46a7ba3ed8907e9fef1f\",\"expiresAt\":1775176321000,\"domain\":\"e.189.cn\",\"path\":\"/\",\"secure\":false,\"httpOnly\":false,\"persistent\":true,\"hostOnly\":false},{\"name\":\"pageOp\",\"value\":\"336b9ddc820212fa6c9b5a0cfd7bf5b3\",\"expiresAt\":253402300799999,\"domain\":\"e.189.cn\",\"path\":\"/\",\"secure\":false,\"httpOnly\":false,\"persistent\":false,\"hostOnly\":false},{\"name\":\"OPENINFO\",\"value\":\"33c28688ef52ce9e3a9ef87388047efbde5e3e2e4c7ef6ef267632468c7dfaf294ff59fa59d34801\",\"expiresAt\":253402300799999,\"domain\":\"e.189.cn\",\"path\":\"/\",\"secure\":false,\"httpOnly\":true,\"persistent\":false,\"hostOnly\":false},{\"name\":\"GRAYNUMBER\",\"value\":\"319DE3F68C8730862F3BEF66F3D635B7\",\"expiresAt\":1775177653000,\"domain\":\"e.189.cn\",\"path\":\"/\",\"secure\":false,\"httpOnly\":false,\"persistent\":true,\"hostOnly\":false}],\"cloud.189.cn\":[{\"name\":\"JSESSIONID\",\"value\":\"431787526C43DF21B6373E914FE597EC\",\"expiresAt\":253402300799999,\"domain\":\"cloud.189.cn\",\"path\":\"/\",\"secure\":false,\"httpOnly\":true,\"persistent\":false,\"hostOnly\":true},{\"name\":\"COOKIE_LOGIN_USER\",\"value\":\"0C7407F59A6E5896EB6B777056E160DB020BAE67B121B5930CCD4777073744055308F7E8CD03F2FC2399E4823F60ECDD74120CEE4C529017\",\"expiresAt\":253402300799999,\"domain\":\"cloud.189.cn\",\"path\":\"/\",\"secure\":false,\"httpOnly\":true,\"persistent\":false,\"hostOnly\":false}]}");
|
||||
JsonObject obj = Json.safeObject("{\"open.e.189.cn\":{\"OPENINFO\":\"33c28688ef52ce9e3a9ef87388047efbde5e3e2e4c7ef6ef267632468c7dfaf294ff59fa59d34801\",\"pageOp\":\"f73420158c5c010491f1faa4fc91870e\",\"LT\":\"a8900fc0ecae0c59\",\"GUID\":\"b959026ffdf84080ae8567afd9ea4c32\",\"SSON\":\"dc466c8192e3109eaea837c1d136c1fd065253ce1c7d3a66ca1520d7d6d6307b10a1fe65c7becac73b95f24a6e681e654ec4f47c39533ebcc48bb78d6d6e63d1bbf3334e6e97eaa7092d34f87bf1209e256cd4822db68da051a0aeb532d94408c8e50486347fc713813dafc5776a7cfa665ddf96837151232745aa2957fb441d8a79ca7d86f46452060794e6f4b5873ab99ed476629aed2c7b36a44613c92f925dcfd221fce142cd1ecaab667236df697ece293e3ca24030918e5b357bc193118772278748606ade7262bf25ae7527d3c8a059bd48fc08b53b182e61e543a7e9bd1562b50bf80438\"},\"cloud.189.cn\":{\"JSESSIONID\":\"12088774C4B78E632EB944ECA2E6705F\",\"COOKIE_LOGIN_USER\":\"24DA4CBA27A8388982710C2F3D55EFAA84AEE67E9B3EF1B7AC1C565BEEF24C562052CB9B5EAC85E733C10C2704225133CD625407C352ED5D\"}}");
|
||||
tianYiHandler.setCookie(obj);
|
||||
tianYiHandler.refreshCookie();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue