token-v2
This commit is contained in:
parent
558fe7e4e7
commit
0b62742350
|
@ -14,6 +14,7 @@ import com.lizongying.mytv.api.FAuthService
|
||||||
import com.lizongying.mytv.api.Info
|
import com.lizongying.mytv.api.Info
|
||||||
import com.lizongying.mytv.api.LiveInfo
|
import com.lizongying.mytv.api.LiveInfo
|
||||||
import com.lizongying.mytv.api.LiveInfoRequest
|
import com.lizongying.mytv.api.LiveInfoRequest
|
||||||
|
import com.lizongying.mytv.api.Token
|
||||||
import com.lizongying.mytv.api.YSP
|
import com.lizongying.mytv.api.YSP
|
||||||
import com.lizongying.mytv.api.YSPApiService
|
import com.lizongying.mytv.api.YSPApiService
|
||||||
import com.lizongying.mytv.api.YSPBtraceService
|
import com.lizongying.mytv.api.YSPBtraceService
|
||||||
|
@ -28,6 +29,7 @@ import retrofit2.Response
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
import javax.crypto.spec.IvParameterSpec
|
import javax.crypto.spec.IvParameterSpec
|
||||||
import javax.crypto.spec.SecretKeySpec
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
|
@ -435,24 +437,53 @@ class Request {
|
||||||
inner class TokenRunnable : Runnable {
|
inner class TokenRunnable : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
fetchToken()
|
fetchToken()
|
||||||
handler.postDelayed(this, 600000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchToken() {
|
fun fetchToken() {
|
||||||
yspTokenService.getInfo(token)
|
yspTokenService.getToken(token)
|
||||||
.enqueue(object : Callback<Info> {
|
.enqueue(object : Callback<Token> {
|
||||||
override fun onResponse(call: Call<Info>, response: Response<Info>) {
|
override fun onResponse(call: Call<Token>, response: Response<Token>) {
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
token = response.body()?.data?.token!!
|
val t = response.body()?.t
|
||||||
Log.i(TAG, "info success $token")
|
val e = response.body()?.e
|
||||||
|
if (!t.isNullOrEmpty()) {
|
||||||
|
token = t
|
||||||
|
Log.e(TAG, "token success $token")
|
||||||
|
if (e != null) {
|
||||||
|
handler.postDelayed(
|
||||||
|
tokenRunnable,
|
||||||
|
max(600000, (e - 1500) * 1000).toLong()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "e empty")
|
||||||
|
handler.postDelayed(
|
||||||
|
tokenRunnable,
|
||||||
|
600000
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "token empty")
|
||||||
|
handler.postDelayed(
|
||||||
|
tokenRunnable,
|
||||||
|
600000
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "token status error")
|
Log.e(TAG, "token status error")
|
||||||
|
handler.postDelayed(
|
||||||
|
tokenRunnable,
|
||||||
|
600000
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(call: Call<Info>, t: Throwable) {
|
override fun onFailure(call: Call<Token>, t: Throwable) {
|
||||||
Log.e(TAG, "token request error $t")
|
Log.e(TAG, "token request error $t")
|
||||||
|
handler.postDelayed(
|
||||||
|
tokenRunnable,
|
||||||
|
600000
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@ data class Info(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class Token(
|
||||||
|
val e: Int?,
|
||||||
|
val t: String?,
|
||||||
|
)
|
||||||
|
|
||||||
data class Release(
|
data class Release(
|
||||||
val code: Int?,
|
val code: Int?,
|
||||||
val msg: String?,
|
val msg: String?,
|
||||||
|
|
|
@ -10,4 +10,9 @@ interface YSPTokenService {
|
||||||
fun getInfo(
|
fun getInfo(
|
||||||
@Query("token") token: String = "",
|
@Query("token") token: String = "",
|
||||||
): Call<Info>
|
): Call<Info>
|
||||||
|
|
||||||
|
@GET("my-tv/v2/token")
|
||||||
|
fun getToken(
|
||||||
|
@Query("token") token: String = "",
|
||||||
|
): Call<Token>
|
||||||
}
|
}
|
Loading…
Reference in New Issue