Skip to content

Commit

Permalink
fix: 完成对无法发起三联请求修复 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
BingZi-233 committed Nov 30, 2023
1 parent 82efccf commit 78a1b90
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 79 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=online.bingiz.bilibili.video
version=1.0.9-1
version=1.0.10
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ import taboolib.module.nms.NMSMap
*/
object NetworkEngine {
private val client = OkHttpClient.Builder()
.addInterceptor(ReceivedCookiesInterceptor())
.addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion([email protected])"))
.build()
.addInterceptor(ReceivedCookiesInterceptor())
.addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion([email protected])"))
.build()

/**
* Bilibili API
* 哔哩哔哩API驱动
*/
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)
}

/**
Expand All @@ -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)
}

/**
Expand All @@ -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)
}

/**
Expand All @@ -90,8 +90,8 @@ object NetworkEngine {
fun generateBilibiliQRCodeUrl(player: Player) {
bilibiliPassportAPI.applyQRCodeGenerate().enqueue(object : Callback<BilibiliResult<QRCodeGenerateData>> {
override fun onResponse(
call: Call<BilibiliResult<QRCodeGenerateData>>,
response: Response<BilibiliResult<QRCodeGenerateData>>
call: Call<BilibiliResult<QRCodeGenerateData>>,
response: Response<BilibiliResult<QRCodeGenerateData>>
) {
if (response.isSuccessful) {
val body = response.body()
Expand All @@ -102,10 +102,10 @@ object NetworkEngine {
shiny()
lore.clear()
lore.addAll(
listOf(
"&7请使用Bilibili客户端扫描二维码",
"&7二维码有效期为3分钟",
).colored()
listOf(
"&7请使用Bilibili客户端扫描二维码",
"&7二维码有效期为3分钟",
).colored()
)
}
// 每隔1s检查一次玩家是否扫码
Expand All @@ -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")
}
Expand All @@ -151,8 +151,8 @@ object NetworkEngine {
}
} else {
player.infoAsLang(
"GenerateUseCookieFailure",
response.body()?.message ?: "Bilibili未提供任何错误信息"
"GenerateUseCookieFailure",
response.body()?.message ?: "Bilibili未提供任何错误信息"
)
}
} else {
Expand Down Expand Up @@ -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<BilibiliResult<TripleData>> {
override fun onResponse(
call: Call<BilibiliResult<TripleData>>,
response: Response<BilibiliResult<TripleData>>
) {
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<BilibiliResult<TripleData>> {
override fun onResponse(
call: Call<BilibiliResult<TripleData>>,
response: Response<BilibiliResult<TripleData>>
) {
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<BilibiliResult<TripleData>>, t: Throwable) {
player.infoAsLang("NetworkRequestFailure", t.message ?: "Bilibili未提供任何错误信息。")
}
})
override fun onFailure(call: Call<BilibiliResult<TripleData>>, t: Throwable) {
player.infoAsLang("NetworkRequestFailure", t.message ?: "Bilibili未提供任何错误信息。")
}
})
}
}

Expand Down

0 comments on commit 78a1b90

Please sign in to comment.