Giter Site home page Giter Site logo

jellybrick / koyo Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 197 KB

Koyo: Unofficial HoyoLab & Genshin Impact API written in Kotlin

License: Apache License 2.0

Kotlin 100.00%
genshin genshin-api genshin-impact hoyolab hoyolab-api jvm kotlin kotlin-multiplatform

koyo's Introduction

koyo's People

Contributors

jellybrick avatar renovate[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

koyo's Issues

[Currently not implementable] generate gacha Authkey from HoyoLab sToken

@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.

characters: Unexpected JSON token at offset 7

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 7: Expected start of the object '{', but had ':' instead at path: $.data

JSON input

{"data":null,"message":"invalid request","retcode":-10001}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

gradle
gradle.properties
settings.gradle.kts
lib/build.gradle.kts
  • org.jetbrains.kotlin.jvm 1.9.10
  • org.jetbrains.kotlin.plugin.serialization 1.9.10
  • com.squareup.okhttp3:okhttp 5.0.0-alpha.11
  • org.jetbrains.kotlinx:kotlinx-datetime 0.4.0
  • org.jetbrains.kotlinx:kotlinx-serialization-json 1.6.0
  • com.soywiz.korlibs.krypto:krypto-jvm 4.0.10
  • com.benasher44:uuid 0.8.1
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.