天意cookie

This commit is contained in:
lushunming 2025-03-26 13:59:11 +08:00
parent 5967ea8b8c
commit d3023a6578
9 changed files with 65 additions and 46 deletions

View File

@ -37,55 +37,66 @@ 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");
} }
public File geteCache() {
return Path.tv("tianyie");
}
private String indexUrl = ""; private String indexUrl = "";
private String reqId; private String reqId;
private String lt; private String lt;
private Map<String, String> cookieMap; private Map<String, String> cookieMap;
private Map<String, String> ecookieMap;
private String cookie; private String cookie;
private String ecookie;
public TianYiHandler() { public TianYiHandler() {
cookie = "";
cookieMap = new HashMap<>(); cookieMap = new HashMap<>();
ecookieMap = new HashMap<>();
cache = Cache.objectFrom(Path.read(getCache())); cache = Cache.objectFrom(Path.read(getCache()));
ecache = Cache.objectFrom(Path.read(geteCache()));
cookie = cache.getUser().getCookie();
ecookie = ecache.getUser().getCookie();
} }
public void refreshCookie(String cookie) throws IOException { public void refreshCookie() throws IOException {
getCookieMap(List.of(cookie.split(";")));
this.cookie = mapToCookie(cookieMap);
String url = "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fweb%2Fredirect.html&defaultSaveName=3&defaultSaeNameCheck=uncheck&browserId=dff95dced0b03d9d972d920f03ddd05e";
String url = "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fweb%2Fredirect.html";
String index = OkHttp.getLocation(url, Map.of("Cookie", this.cookie)); String index = OkHttp.getLocation(url, Map.of("Cookie", this.cookie));
SpiderDebug.log("index" + index); SpiderDebug.log("index" + index);
SpiderDebug.log("index red: " + index); SpiderDebug.log("index red: " + index);
Map<String, List<String>> resHeaderMap = OkHttp.getLocationHeader(index, Map.of("Cookie", this.cookie)); Map<String, List<String>> resHeaderMap = OkHttp.getLocationHeader(index, Map.of("Cookie", this.ecookie));
getCookieMap(resHeaderMap.get("Set-Cookie")); getCookieMap(resHeaderMap.get("Set-Cookie"));
this.cookie = mapToCookie(cookieMap); this.cookie = mapToCookie(cookieMap);
indexUrl = resHeaderMap.get("Location").get(0); indexUrl = resHeaderMap.get("Location").get(0);
SpiderDebug.log("indexUrl red: " + indexUrl); SpiderDebug.log("indexUrl red: " + indexUrl);
Map<String, List<String>> resHeaderMap2 = OkHttp.getLocationHeader(indexUrl, Map.of("Cookie", this.cookie)); OkResult okResult = OkHttp.get(indexUrl, new HashMap<>(), Map.of("Cookie", this.cookie));
/* SpiderDebug.log("refreshCookie header" + Json.toJson(okResult.getResp())); SpiderDebug.log("refreshCookie header" + Json.toJson(okResult.getResp()));
if (okResult.getResp().containsKey("set-cookie")) { if (okResult.getResp().containsKey("set-cookie")) {
List<String> cookieList = getCookieList(okResult.getResp().get("set-cookie")); getCookieMap(okResult.getResp().get("set-cookie"));
cache.setTianyiUser(User.objectFrom(StringUtils.join(cookieList, ";"))); this.cookie = mapToCookie(cookieMap);
SpiderDebug.log("获取cookie成功" + StringUtils.join(cookieList, ";")); cache.setTianyiUser(User.objectFrom(cookie));
SpiderDebug.log("获取cookie成功" + cookie);
}*/ }
} }
public byte[] startScan() throws Exception { public byte[] startScan() throws Exception {
OkResult okResult1 = OkHttp.get("https://ux.21cn.com/api/htmlReportRest/getJs.js?pid=25577E0DEEDF48ADBD4459911F5825E4", new HashMap<>(), new HashMap<>()); /* OkResult okResult1 = OkHttp.get("https://ux.21cn.com/api/htmlReportRest/getJs.js?pid=25577E0DEEDF48ADBD4459911F5825E4", new HashMap<>(), new HashMap<>());
getCookieMap(okResult1.getResp().get("Set-Cookie")); getCookieMap(okResult1.getResp().get("Set-Cookie"));
this.cookie = mapToCookie(cookieMap); 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"); 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 = 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", "")); 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); SpiderDebug.log("index red: " + index);
@ -137,9 +148,9 @@ public class TianYiHandler {
okResult = OkHttp.post(this.API_URL + url, params, headers); okResult = OkHttp.post(this.API_URL + url, params, headers);
} }
if (okResult.getResp().get("Set-Cookie") != null) { if (okResult.getResp().get("Set-Cookie") != null) {
getCookieMap(okResult.getResp().get("Set-Cookie")); geteCookieMap(okResult.getResp().get("Set-Cookie"));
this.cookie = mapToCookie(cookieMap); this.ecookie = mapToCookie(ecookieMap);
SpiderDebug.log("cookie: " + this.cookie); SpiderDebug.log("cookie: " + this.ecookie);
} }
if (okResult.getCode() != 200 && leftRetry > 0) { if (okResult.getCode() != 200 && leftRetry > 0) {
@ -220,6 +231,21 @@ public class TianYiHandler {
} }
private void geteCookieMap(List<String> cookie) {
for (String s : cookie) {
String[] split = s.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) : "";
ecookieMap.put(key, value);
}
}
}
// 新增方法Map转Cookie字符串 // 新增方法Map转Cookie字符串
private String mapToCookie(Map<String, String> map) { private String mapToCookie(Map<String, String> map) {
if (map == null || map.isEmpty()) return ""; if (map == null || map.isEmpty()) return "";
@ -293,9 +319,9 @@ public class TianYiHandler {
SpiderDebug.log("扫码成功------" + obj.get("redirectUrl").getAsString()); SpiderDebug.log("扫码成功------" + obj.get("redirectUrl").getAsString());
String redirectUrl = obj.get("redirectUrl").getAsString(); String redirectUrl = obj.get("redirectUrl").getAsString();
Map<String, Object> result = new HashMap<>();
fetchUserInfo(redirectUrl, secondCookie, result);
fetchUserInfo(redirectUrl, secondCookie);
} else { } else {
@ -306,9 +332,9 @@ public class TianYiHandler {
return null; return null;
} }
private void fetchUserInfo(String redirectUrl, String secondCookie, Map<String, Object> result) throws IOException { private void fetchUserInfo(String redirectUrl, String secondCookie) throws IOException {
Map<String, String> params = new HashMap<>();
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("Cookie", secondCookie); headers.put("Cookie", secondCookie);
Map<String, List<String>> okResult = OkHttp.getLocationHeader(redirectUrl, headers); Map<String, List<String>> okResult = OkHttp.getLocationHeader(redirectUrl, headers);
@ -316,10 +342,12 @@ public class TianYiHandler {
if (okResult.containsKey("set-cookie")) { if (okResult.containsKey("set-cookie")) {
getCookieMap(okResult.get("Set-Cookie")); getCookieMap(okResult.get("Set-Cookie"));
this.cookie = mapToCookie(cookieMap); this.cookie = mapToCookie(cookieMap);
SpiderDebug.log("cookie: " + this.cookie);
cache.setTianyiUser(User.objectFrom(cookie)); cache.setTianyiUser(User.objectFrom(cookie));
ecache.setTianyieUser(User.objectFrom(ecookie));
SpiderDebug.log("获取cookie成功" + cookie); SpiderDebug.log("获取cookie成功" + cookie);
SpiderDebug.log("获取ecookie成功" + ecookie);
//停止检验线程关闭弹窗 //停止检验线程关闭弹窗
stopService(); stopService();
} }

View File

@ -293,7 +293,9 @@ public class TianyiApi {
OkResult result = OkHttp.get("https://cloud.189.cn/api/portal/getUserSizeInfo.action", new HashMap<>(), getHeaders()); OkResult result = OkHttp.get("https://cloud.189.cn/api/portal/getUserSizeInfo.action", new HashMap<>(), getHeaders());
JsonObject res = Json.safeObject(result.getBody()); JsonObject res = Json.safeObject(result.getBody());
if (res.isEmpty() || (Objects.nonNull(res.get("errorCode")) && res.get("errorCode").getAsString().equals("InvalidSessionKey"))) { if (res.isEmpty() || (Objects.nonNull(res.get("errorCode")) && res.get("errorCode").getAsString().equals("InvalidSessionKey"))) {
tianYiHandler.startScan(); // tianYiHandler.startScan();
//tianYiHandler.refreshCookie(cookie);
tianYiHandler.refreshCookie();
} }
return ""; return "";

View File

@ -1,8 +1,6 @@
package com.github.catvod.bean.tianyi; package com.github.catvod.bean.tianyi;
import com.github.catvod.api.TianYiHandler; import com.github.catvod.api.TianYiHandler;
import com.github.catvod.api.UCApi;
import com.github.catvod.api.UCTokenHandler;
import com.github.catvod.crawler.SpiderDebug; import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.spider.Init; import com.github.catvod.spider.Init;
import com.github.catvod.utils.Path; import com.github.catvod.utils.Path;
@ -25,15 +23,6 @@ public class Cache {
return user == null ? new User("") : user; return user == null ? new User("") : user;
} }
public void setUser(User user) {
this.user = user;
this.save();
}
public void setTokenUser(User user) {
this.user = user;
this.saveToken();
}
public void setTianyiUser(User user) { public void setTianyiUser(User user) {
this.user = user; this.user = user;
@ -44,19 +33,19 @@ public class Cache {
Init.execute(() -> Path.write(new TianYiHandler().getCache(), toString())); Init.execute(() -> Path.write(new TianYiHandler().getCache(), toString()));
} }
public void saveToken() { public void saveTianyieUser() {
Init.execute(() -> Path.write(new UCTokenHandler().getCache(), toString())); Init.execute(() -> Path.write(new TianYiHandler().geteCache(), toString()));
} }
public void save() {
Init.execute(() -> Path.write(UCApi.get().getCache(), toString()));
}
@Override @Override
public String toString() { public String toString() {
return new Gson().toJson(this); return new Gson().toJson(this);
} }
public void setTianyieUser(User user) {
this.user = user;
this.saveTianyieUser();
}
} }

Binary file not shown.

View File

@ -1 +1 @@
e2f5426d4b70b9f4229e832857bffc6d 1b690cca68945fba17d5d80572d3dc44

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;e2f5426d4b70b9f4229e832857bffc6d", "spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;1b690cca68945fba17d5d80572d3dc44",
"lives": [ "lives": [
{ {
"name": "电视直播", "name": "电视直播",

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;e2f5426d4b70b9f4229e832857bffc6d", "spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;1b690cca68945fba17d5d80572d3dc44",
"lives": [ "lives": [
{ {
"name": "直播ipv6", "name": "直播ipv6",

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;e2f5426d4b70b9f4229e832857bffc6d", "spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;1b690cca68945fba17d5d80572d3dc44",
"lives": [ "lives": [
{ {
"name": "直播ipv6", "name": "直播ipv6",

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;e2f5426d4b70b9f4229e832857bffc6d", "spider": "https://androidcatvodspider.netlify.app/jar/custom_spider.jar;md5;1b690cca68945fba17d5d80572d3dc44",
"lives": [ "lives": [
{ {
"name": "直播", "name": "直播",