mirror of
https://github.com/czp3009/bilibili-api.git
synced 2025-02-19 20:50:28 +08:00
OAuth2 info
This commit is contained in:
parent
1209a96e5a
commit
bfa7a55c45
@ -2,12 +2,10 @@ package com.hiczp.bilibili.api.passport
|
||||
|
||||
import com.hiczp.bilibili.api.passport.model.GetKeyResponse
|
||||
import com.hiczp.bilibili.api.passport.model.LoginResponse
|
||||
import com.hiczp.bilibili.api.passport.model.OAuth2Info
|
||||
import com.hiczp.bilibili.api.retrofit.CommonResponse
|
||||
import kotlinx.coroutines.Deferred
|
||||
import retrofit2.http.Field
|
||||
import retrofit2.http.FieldMap
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.*
|
||||
|
||||
/**
|
||||
* 用户鉴权相关的接口
|
||||
@ -55,4 +53,24 @@ interface PassportAPI {
|
||||
@FieldMap cookieMap: Map<String, String>,
|
||||
@Field("access_token") accessToken: String
|
||||
): Deferred<CommonResponse>
|
||||
|
||||
/**
|
||||
* 获取 OAuth2 信息
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
@GET("/api/v2/oauth2/info")
|
||||
fun info(
|
||||
@Query("DedeUserID") dedeUserId: String,
|
||||
@Query("DedeUserID__ckMd5") ckMd5: String,
|
||||
@Query("SESSDATA") sessData: String,
|
||||
@Query("access_token") accessToken: String,
|
||||
@Query("bili_jct") biliJct: String,
|
||||
@Query("sid") sid: String
|
||||
): Deferred<OAuth2Info>
|
||||
|
||||
@GET("/api/v2/oauth2/info")
|
||||
fun info(
|
||||
@QueryMap cookieMap: Map<String, String>,
|
||||
@Query("access_token") accessToken: String
|
||||
): Deferred<OAuth2Info>
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.hiczp.bilibili.api.passport.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class OAuth2Info(
|
||||
@SerializedName("code")
|
||||
var code: Int, // 0
|
||||
@SerializedName("data")
|
||||
var `data`: Data,
|
||||
@SerializedName("ts")
|
||||
var ts: Long // 1551865482
|
||||
) {
|
||||
data class Data(
|
||||
@SerializedName("access_token")
|
||||
var accessToken: String, // 813b20ea7f229795eba7bd31608e3621
|
||||
@SerializedName("expires_in")
|
||||
var expiresIn: Long, // 1797151
|
||||
@SerializedName("mid")
|
||||
var mid: Long // 20293030
|
||||
)
|
||||
}
|
@ -5,9 +5,23 @@ import org.junit.jupiter.api.Test
|
||||
|
||||
class UserInfoTest {
|
||||
@Test
|
||||
fun info() {
|
||||
fun appInfo() {
|
||||
runBlocking {
|
||||
bilibiliClient.appAPI.myInfo().await()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun oauthInfo() {
|
||||
runBlocking {
|
||||
with(bilibiliClient) {
|
||||
passportAPI.info(
|
||||
loginResponse!!.data.cookieInfo.cookies.associate {
|
||||
it.name to it.value
|
||||
},
|
||||
token!!
|
||||
).await()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user