JellyBrick/Koyo

[Currently not implementable] generate gacha Authkey from HoyoLab sToken

Opened this issue · 1 comments

@OptIn(ExperimentalSerializationApi::class)
fun authKey(): HoyoLabAuthKey {
TODO(
"Currently, oversea account (HoyoLab Account) is not support generate gacha Authkey from HoyoLab sToken. " +
"Check this issue https://github.com/DGP-Studio/Snap.Hutao/issues/638 " +
"I don't think it's technically impossible, but I haven't verified that it works. " +
"https://github.com/ctrlcvs/xiaoyao-cvs-plugin/blob/master/model/mys/mihoyoApi.js"
)
val loginByCookieResult = okHttpClient.newCall(
Request.Builder()
.addHeader("User-Agent", Headers.Web.USER_AGENT)
.addHeader("Cookie", RequestUtil.generateCookieFromCookieObject(cookie))
.url(
Routes.LOGIN_BY_COOKIE.toHttpUrl()
.newBuilder()
.addQueryParameter("t", Clock.System.now().epochSeconds.toString())
.build(),
)
.get()
.build(),
).execute().use {
jsonParser.decodeFromStream<HoyoLabWebResponse<HoyoLabLoginByCookie>>(it.body.byteStream()).data
}
val accountInfo =
loginByCookieResult.accountInfo ?: throw HoyoLabException("Invalid data received ($loginByCookieResult)")
val loginToken = okHttpClient.newCall(
Request.Builder()
.addHeader("User-Agent", Headers.Web.USER_AGENT)
.addHeader("Cookie", RequestUtil.generateCookieFromCookieObject(cookie))
.url(
Routes.AUTH_MULTI_TOKEN.toHttpUrl()
.newBuilder()
.addQueryParameter("login_ticket", accountInfo.webLoginToken)
.addQueryParameter("token_types", "3")
.addQueryParameter("uid", accountInfo.accountId.toString())
.build(),
)
.get()
.build(),
).execute().use {
jsonParser.decodeFromStream<HoyoLabResponse<HoyoLabMultiTokenByLoginTicket>>(it.body.byteStream()).data
}
cookie.stuid = accountInfo.accountId
val account = gamesList(Games.GENSHIN_IMPACT_GLOBAL).list.first { it.gameUid == uid }
val ds = StringUtil.generateDS("jEpJb9rRARU2rXDA9qYbZ3selxkuct9a")
val requestBuilder = RequestUtil.getDefaultAndroidRequestBuilder()
.addHeader("DS", ds)
.addHeader(
"Cookie",
RequestUtil.generateCookieFromCookieObject(cookie) + "; " + loginToken.list.joinToString("; ") { ticketToken ->
"${ticketToken.name}=${ticketToken.token}"
},
)
.url(Routes.GENSHIN_AUTHKEY)
.post(
jsonParser.encodeToString(
HoyoLabAuthKeyRequest(
"webview_gacha",
account.gameBiz,
account.gameUid,
account.region,
),
).toRequestBody("application/json".toMediaType()),
)
val genshinAuthKeyResponse = okHttpClient.newCall(requestBuilder.build()).execute().use { response ->
jsonParser.decodeFromStream<HoyoLabResponse<HoyoLabAuthKey?>>(response.body.byteStream())
}
return if (genshinAuthKeyResponse.message == "OK") {
genshinAuthKeyResponse.data
} else {
null
} ?: throw HoyoLabException("Invalid data received ($genshinAuthKeyResponse)")
}

Currently, oversea account (HoyoLab Account) is not support generate gacha Authkey from HoyoLab sToken.
Check this issue DGP-Studio/Snap.Hutao#638
I don't think it's technically impossible, but I haven't verified that this (https://github.com/ctrlcvs/xiaoyao-cvs-plugin/blob/master/model/mys/mihoyoApi.js) works.

Only CN mihoyobbs account can use stoken to generate gi authkey, it's the only exception in all mihoyo's games.