天意accessToken

This commit is contained in:
lushunming 2025-04-03 14:15:46 +08:00
parent 0b895730e8
commit e5447fc5a1
5 changed files with 11 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import com.google.gson.JsonObject;
import okhttp3.Cookie; import okhttp3.Cookie;
import okhttp3.CookieJar; import okhttp3.CookieJar;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
@ -34,6 +35,11 @@ public class SimpleCookieJar implements CookieJar {
public SimpleCookieJar() { public SimpleCookieJar() {
this.cache = Cache.objectFrom(Path.read(getCache())); this.cache = Cache.objectFrom(Path.read(getCache()));
String cookieStr = cache.getUser().getCookie();
if (StringUtils.isNoneBlank(cookieStr)) {
JsonObject cookieJson = Json.safeObject(cookieStr);
setGlobalCookie(cookieJson);
}
} }
@ -45,14 +51,14 @@ public class SimpleCookieJar implements CookieJar {
public void saveFromResponse(HttpUrl url, @NotNull List<Cookie> cookies) { public void saveFromResponse(HttpUrl url, @NotNull List<Cookie> cookies) {
SpiderDebug.log("SimpleCookieJar saveFromResponse: " + url.host() + ": " + Json.toJson(cookies)); SpiderDebug.log("SimpleCookieJar saveFromResponse: " + url.host() + ": " + Json.toJson(cookies));
// 创建可修改的 Cookie 列表副本 // 创建可修改的 Cookie 列表副本
List<Cookie> oldCookies = cookieStore.get(url.host())!=null?cookieStore.get(url.host()):new ArrayList<>(); List<Cookie> oldCookies = cookieStore.get(url.host()) != null ? cookieStore.get(url.host()) : new ArrayList<>();
List<Cookie> newCookies = new ArrayList<>(oldCookies); List<Cookie> newCookies = new ArrayList<>(oldCookies);
// 更新 Cookie // 更新 Cookie
for (Cookie newCookie : cookies) { for (Cookie newCookie : cookies) {
// 移除同名的旧 Cookie // 移除同名的旧 Cookie
for (Cookie oldCookie : newCookies) { for (Cookie oldCookie : newCookies) {
if(oldCookie.name().equals(newCookie.name())){ if (oldCookie.name().equals(newCookie.name())) {
oldCookies.remove(oldCookie); oldCookies.remove(oldCookie);
} }
} }
@ -100,7 +106,7 @@ public class SimpleCookieJar implements CookieJar {
boolean hostOnly = cookieobj.get("hostOnly").getAsBoolean(); boolean hostOnly = cookieobj.get("hostOnly").getAsBoolean();
if (hostOnly) { if (hostOnly) {
cookieBuilder.hostOnlyDomain(cookieobj.get("domain").getAsString()); cookieBuilder.hostOnlyDomain(cookieobj.get("domain").getAsString());
}else { } else {
cookieBuilder.domain(cookieobj.get("domain").getAsString()); cookieBuilder.domain(cookieobj.get("domain").getAsString());
} }

View File

@ -35,7 +35,6 @@ public class TianYiHandler {
private ScheduledExecutorService service; private ScheduledExecutorService service;
private AlertDialog dialog; private AlertDialog dialog;
private final Cache cache; private final Cache cache;
private final Cache ecache;
public File getCache() { public File getCache() {
return Path.tv("tianyi"); return Path.tv("tianyi");
@ -56,8 +55,6 @@ public class TianYiHandler {
cache = Cache.objectFrom(Path.read(getCache())); cache = Cache.objectFrom(Path.read(getCache()));
ecache = Cache.objectFrom(Path.read(geteCache()));
cookieJar = new SimpleCookieJar(); cookieJar = new SimpleCookieJar();
} }

Binary file not shown.

View File

@ -1 +1 @@
fabff6d0293436b616892579a9d1e3e3 1d71c8fceb2eb53953b31019774eeb86

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://raw.kkgithub.com/lushunming/AndroidCatVodSpider/tyCookieJar/jar/custom_spider.jar;md5;fabff6d0293436b616892579a9d1e3e3", "spider": "https://raw.kkgithub.com/lushunming/AndroidCatVodSpider/tyCookieJar/jar/custom_spider.jar;md5;1d71c8fceb2eb53953b31019774eeb86",
"lives": [ "lives": [
{ {
"name": "电视直播", "name": "电视直播",