请求接口更换-1

This commit is contained in:
renhaoting 2025-12-04 16:29:15 +08:00
parent 6831cfa898
commit dc65bd0562
7 changed files with 64 additions and 8 deletions

View File

@ -10,7 +10,9 @@ object VidiConst {
* 描述网络常量
*
*/
const val URL_YOUTUBE_API = "https://www.googleapis.com"
const val URL_YOUTUBE_API_OLD = "https://www.googleapis.com"
const val URL_YOUTUBE_API = "http://192.168.110.141:8888"

View File

@ -44,7 +44,7 @@ interface YoutubeApi {
): ResYoutubePlayList
@GET("/youtube/v3/videos")
suspend fun getVideoList(
suspend fun getVideoList_old(
@Query("part") part: String= URLEncoder.encode("snippet", "UTF-8"),
@Query("key") key: String= VidiConst.YOUTUBE_API_KEY,
@Query("videoDuration") videoDuration: String= "short",
@ -56,10 +56,9 @@ interface YoutubeApi {
): ResYoutubePlayList
/*
https://www.googleapis.com/youtube/v3/videos?part=id&chart=mostPopular&regionCode=BR&maxResults=10&key=AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY
https://www.googleapis.com/youtube/v3/videos?part=snippet,statistics&chart=mostPopular&regionCode=BR&maxResults=10&key=AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY
*/
@GET("/videos")
suspend fun getVideoList(
@Query("video") video: String? = URLEncoder.encode("", "UTF-8"),
): ResYoutubePlayList
}

View File

@ -2,6 +2,7 @@ package com.gamedog.vididin.core.network.di
import android.util.Log
import com.gamedog.vididin.request.RequestUtil
import okhttp3.Headers
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
@ -24,6 +25,7 @@ class GlobalInterceptor : Interceptor {
val emptyBody = "{}".toRequestBody("application/json;charset=utf-8".toMediaType())
val requestBody = if (bodyStr.isNotBlank()) request.body else emptyBody
val timeSec = RequestUtil.getTimestampSec()
val headersBuilder = Headers.Builder()
/*
@ -38,6 +40,11 @@ class GlobalInterceptor : Interceptor {
.add("Content-Type", "application/json")
.add("Accept", "application/json")
.add("Accept-Charset", "utf-8")
// server real defined
.add("ApplicationId", RequestUtil.Request_APPId)
.add("Timestamp", timeSec.toString())
.add("Sign", RequestUtil.getRequestSign(timeSec))
val headers = headersBuilder.build()

View File

@ -17,6 +17,6 @@ class DefaultYoutubeDatasource @Inject constructor(retrofit: Retrofit) : Youtube
override suspend fun getChannels(
) = shopApi.getChannelList()
override suspend fun getVideoList(pageToken: String?) = shopApi.getVideoList(pageToken = pageToken)
override suspend fun getVideoList(lastVideoId: String?) = shopApi.getVideoList(video = lastVideoId)
}

View File

@ -0,0 +1,22 @@
package com.gamedog.vididin.request
import com.ama.core.architecture.util.MD5Util
class RequestUtil private constructor(){
companion object {
const val Request_APPId = "video1"
const val Request_Sceret = "secret1"
fun getTimestampSec(): Long {
return System.currentTimeMillis()/1000
}
fun getRequestSign(timeSec: Long): String {
val signOrigin = "$Request_APPId-${timeSec}-$Request_Sceret"
return MD5Util.md5(signOrigin)?:""
}
}
}

View File

@ -2,6 +2,7 @@
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">www.googleapis.com</domain>
<domain includeSubdomains="true">192.168.110.141</domain>
</domain-config>

View File

@ -0,0 +1,25 @@
package com.ama.core.architecture.util
import java.security.MessageDigest
object MD5Util {
fun md5(input: String): String? {
return try {
val messageDigest = MessageDigest.getInstance("MD5")
val digestBytes = messageDigest.digest(input.toByteArray(Charsets.UTF_8))
val hexString = StringBuilder()
for (b in digestBytes) {
val hex = Integer.toHexString(0xFF and b.toInt())
if (hex.length == 1) {
hexString.append('0')
}
hexString.append(hex)
}
hexString.toString()
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}