From 6e99db4add5175f13ec7b7192c469752eb179ecc Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Thu, 22 Oct 2020 20:49:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?js:=E6=B7=BB=E5=8A=A0java.getCookie(baseUrl?= =?UTF-8?q?)=E8=AF=BB=E5=8F=96=E7=99=BB=E5=BD=95cookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/JsExtensions.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 7ba245bcd..ff7357ad4 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -4,6 +4,7 @@ import android.util.Base64 import androidx.annotation.Keep import io.legado.app.constant.AppConst.dateFormat import io.legado.app.help.http.SSLHelper +import io.legado.app.help.http.CookieStore import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* import org.jsoup.Connection @@ -119,6 +120,13 @@ interface JsExtensions { .execute() } + /** + *js实现读取cookie + */ + fun getCookie(tag: String): String { + return CookieStore.getCookie(tag) + } + /** * js实现解码,不能删 */ From e27211ff8094b32eb6e04fad22583311dd4cb938 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Thu, 22 Oct 2020 22:12:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=AD=A3=E6=96=87=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=EF=BC=9A=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 2 +- .../java/io/legado/app/help/http/HttpHelper.kt | 15 --------------- .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 12 ------------ 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 537737c3f..59359fbc7 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -101,7 +101,7 @@ object BookHelp { downloadImages.add(src) val analyzeUrl = AnalyzeUrl(src) try { - analyzeUrl.getImageBytes(book.origin)?.let { + analyzeUrl.getResponseBytes(book.origin)?.let { FileUtils.createFileIfNotExist( downloadDir, cacheFolderName, diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 3728f4819..a226b46d6 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -48,21 +48,6 @@ object HttpHelper { return null } - fun getBytes( - url: String, - queryMap: Map, - headers: Map - ): ByteArray? { - NetworkUtils.getBaseUrl(url)?.let { baseUrl -> - return getByteRetrofit(baseUrl) - .create(HttpGetApi::class.java) - .getMapByte(url, queryMap, headers) - .execute() - .body() - } - return null - } - suspend fun simpleGetAsync(url: String, encode: String? = null): String? { NetworkUtils.getBaseUrl(url)?.let { baseUrl -> val response = getApiService(baseUrl, encode) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index b4401bd39..a4729341e 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -352,18 +352,6 @@ class AnalyzeUrl( return Res(NetworkUtils.getUrl(res), res.body()) } - fun getImageBytes(tag: String): ByteArray? { - val cookie = CookieStore.getCookie(tag) - if (cookie.isNotEmpty()) { - headerMap["Cookie"] += cookie - } - return if (fieldMap.isEmpty()) { - HttpHelper.getBytes(url, mapOf(), headerMap) - } else { - HttpHelper.getBytes(url, fieldMap, headerMap) - } - } - suspend fun getResponseBytes(tag: String? = null): ByteArray? { if (tag != null) { val cookie = CookieStore.getCookie(tag) From e2ba01806107fbe8523e34b760ad0dfad78ddcfa Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Thu, 22 Oct 2020 23:47:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9A=84cookie=E8=A2=AB=E4=B8=8D=E4=BC=9A=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9A=84cookie=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index a4729341e..160c0debf 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -281,7 +281,7 @@ class AnalyzeUrl( fun getResponse(tag: String): Call { val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] = cookie + headerMap["Cookie"] += ";${cookie}" } return when { method == RequestMethod.POST -> { @@ -324,7 +324,7 @@ class AnalyzeUrl( } val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] = cookie + headerMap["Cookie"] += ";${cookie}" } val res = when { method == RequestMethod.POST -> { @@ -356,7 +356,7 @@ class AnalyzeUrl( if (tag != null) { val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] = cookie + headerMap["Cookie"] += ";${cookie}" } } val response = when {