From 78a1b900055875a5b2dfeaa54374a655fcf6a4c2 Mon Sep 17 00:00:00 2001 From: BingZi-233 Date: Thu, 30 Nov 2023 21:24:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E6=88=90=E5=AF=B9=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8F=91=E8=B5=B7=E4=B8=89=E8=81=94=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../video/internal/engine/NetworkEngine.kt | 160 +++++++++--------- 2 files changed, 83 insertions(+), 79 deletions(-) diff --git a/gradle.properties b/gradle.properties index 06a1790..3c90fc1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=online.bingiz.bilibili.video -version=1.0.9-1 \ No newline at end of file +version=1.0.10 \ No newline at end of file diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt index 5b712d2..1dad5ab 100644 --- a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt +++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt @@ -39,9 +39,9 @@ import taboolib.module.nms.NMSMap */ object NetworkEngine { private val client = OkHttpClient.Builder() - .addInterceptor(ReceivedCookiesInterceptor()) - .addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion(lhby233@outlook.com)")) - .build() + .addInterceptor(ReceivedCookiesInterceptor()) + .addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion(lhby233@outlook.com)")) + .build() /** * Bilibili API @@ -49,11 +49,11 @@ object NetworkEngine { */ private val bilibiliAPI by lazy { Retrofit.Builder() - .baseUrl("https://api.bilibili.com/x/") - .addConverterFactory(GsonConverterFactory.create()) - .client(client) - .build() - .create(BilibiliApiDrive::class.java) + .baseUrl("https://api.bilibili.com/x/") + .addConverterFactory(GsonConverterFactory.create()) + .client(client) + .build() + .create(BilibiliApiDrive::class.java) } /** @@ -62,11 +62,11 @@ object NetworkEngine { */ private val bilibiliPassportAPI by lazy { Retrofit.Builder() - .baseUrl("https://passport.bilibili.com/x/") - .addConverterFactory(GsonConverterFactory.create()) - .client(client) - .build() - .create(BilibiliPassportDrive::class.java) + .baseUrl("https://passport.bilibili.com/x/") + .addConverterFactory(GsonConverterFactory.create()) + .client(client) + .build() + .create(BilibiliPassportDrive::class.java) } /** @@ -75,11 +75,11 @@ object NetworkEngine { */ private val bilibiliWebsiteAPI by lazy { Retrofit.Builder() - .baseUrl("https://www.bilibili.com/") - .addConverterFactory(GsonConverterFactory.create()) - .client(client) - .build() - .create(BilibiliPassportDrive::class.java) + .baseUrl("https://www.bilibili.com/") + .addConverterFactory(GsonConverterFactory.create()) + .client(client) + .build() + .create(BilibiliPassportDrive::class.java) } /** @@ -90,8 +90,8 @@ object NetworkEngine { fun generateBilibiliQRCodeUrl(player: Player) { bilibiliPassportAPI.applyQRCodeGenerate().enqueue(object : Callback> { override fun onResponse( - call: Call>, - response: Response> + call: Call>, + response: Response> ) { if (response.isSuccessful) { val body = response.body() @@ -102,10 +102,10 @@ object NetworkEngine { shiny() lore.clear() lore.addAll( - listOf( - "&7请使用Bilibili客户端扫描二维码", - "&7二维码有效期为3分钟", - ).colored() + listOf( + "&7请使用Bilibili客户端扫描二维码", + "&7二维码有效期为3分钟", + ).colored() ) } // 每隔1s检查一次玩家是否扫码 @@ -128,7 +128,7 @@ object NetworkEngine { cookieCache.put(player.uniqueId, it) player.getDataContainer()["mid"] = mid player.getDataContainer()["refresh_token"] = - result.data.refreshToken + result.data.refreshToken player.getDataContainer()["timestamp"] = result.data.timestamp player.infoAsLang("GenerateUseCookieSuccess") } @@ -151,8 +151,8 @@ object NetworkEngine { } } else { player.infoAsLang( - "GenerateUseCookieFailure", - response.body()?.message ?: "Bilibili未提供任何错误信息" + "GenerateUseCookieFailure", + response.body()?.message ?: "Bilibili未提供任何错误信息" ) } } else { @@ -181,70 +181,74 @@ object NetworkEngine { } } val csrf = cookieCache[player.uniqueId]?.first { it.startsWith("bili_jct") } - ?.replace("bili_jct=", "") - ?.split(";") - ?.get(0) + ?.replace("bili_jct=", "") + ?.split(";") + ?.get(0) val sessData = - (cookieCache[player.uniqueId]?.first { it.startsWith("SESSDATA") } + ",buvid3").replace(",", "%2C") + cookieCache[player.uniqueId]?.let { list -> + list.first { it.startsWith("SESSDATA") }.let { + it.substring(0, it.length).split(";")[0] + ",buvid3;" + } + } ?: return if (csrf != null) { bilibiliAPI.actionLikeTriple(bvid, csrf, sessData) - .enqueue(object : Callback> { - override fun onResponse( - call: Call>, - response: Response> - ) { - if (response.isSuccessful) { - val body = response.body() - if (body != null) { - when (body.code) { - 0 -> { - val tripleData = body.data - if (tripleData.coin && tripleData.fav && tripleData.like) { - player.getDataContainer()[bvid] = true - bvCache.put(player.uniqueId to bvid, true) - TripleSendRewardsEvent(player, bvid).call() - } else { - player.infoAsLang( - "GetTripleStatusFailure", - tripleData.like, - tripleData.coin, - tripleData.multiply, - tripleData.fav - ) - } - } - - -101 -> { - player.infoAsLang("GetTripleStatusCookieInvalid") - } - - 10003 -> { - player.infoAsLang("GetTripleStatusTargetFailed") - } - - else -> { + .enqueue(object : Callback> { + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.isSuccessful) { + val body = response.body() + if (body != null) { + when (body.code) { + 0 -> { + val tripleData = body.data + if (tripleData.coin && tripleData.fav && tripleData.like) { + player.getDataContainer()[bvid] = true + bvCache.put(player.uniqueId to bvid, true) + TripleSendRewardsEvent(player, bvid).call() + } else { player.infoAsLang( - "GetTripleStatusError", - response.body()?.message ?: "Bilibili未提供任何错误信息" + "GetTripleStatusFailure", + tripleData.like, + tripleData.coin, + tripleData.multiply, + tripleData.fav ) } } - } else { - player.infoAsLang( - "GetTripleStatusRefuse", + + -101 -> { + player.infoAsLang("GetTripleStatusCookieInvalid") + } + + 10003 -> { + player.infoAsLang("GetTripleStatusTargetFailed") + } + + else -> { + player.infoAsLang( + "GetTripleStatusError", response.body()?.message ?: "Bilibili未提供任何错误信息" - ) + ) + } } } else { - warning("请求失败") - warning("失败原因:${response.code()}") + player.infoAsLang( + "GetTripleStatusRefuse", + response.body()?.message ?: "Bilibili未提供任何错误信息" + ) } + } else { + warning("请求失败") + warning("失败原因:${response.code()}") } + } - override fun onFailure(call: Call>, t: Throwable) { - player.infoAsLang("NetworkRequestFailure", t.message ?: "Bilibili未提供任何错误信息。") - } - }) + override fun onFailure(call: Call>, t: Throwable) { + player.infoAsLang("NetworkRequestFailure", t.message ?: "Bilibili未提供任何错误信息。") + } + }) } }