Skip to content

Commit

Permalink
去除video-link-android中无用的类库以及删除kotlin-android-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
neilyhe committed Feb 18, 2025
1 parent 2e99aa0 commit a772502
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 128 deletions.
6 changes: 1 addition & 5 deletions sdk/video-link-android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.kezong.fat-aar'
Expand Down Expand Up @@ -42,17 +41,14 @@ android {
dependencies {
// api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
embed (name:'android_gvoice-release',ext:'aar')
implementation 'com.google.code.gson:gson:2.12.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.alibaba:fastjson:2.0.31'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//kotlin协程
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'
// api('com.tencent.iot.thirdparty.android:xp2p-sdk:latest.integration') {
// changing = true
// }
// api 'com.tencent.iot.thirdparty.android:xp2p-sdk:2.4.23'
api 'com.tencent.iot.thirdparty.android:xp2p-sdk:2.4.53'
api 'com.tencent.iot.thirdparty.android:media-server:1.0.7'
api 'io.github.sundoggynew:iot-soundtouch:1.0.0'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package com.tencent.iot.video.link.service

import android.util.Log
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.tencent.iot.video.link.util.JsonManager
import com.tencent.iot.video.link.callback.VideoCallback
import com.tencent.iot.video.link.consts.VideoRequestCode
import com.tencent.iot.video.link.http.HttpCallBack
import com.tencent.iot.video.link.http.VideoHttpUtil
import com.tencent.iot.video.link.util.JsonManager
import org.json.JSONObject
import java.lang.Long
import java.nio.charset.Charset
import java.security.InvalidKeyException
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import java.util.TimeZone
import java.util.TreeMap
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import kotlin.collections.HashMap
import kotlin.Any
import kotlin.Byte
import kotlin.ByteArray
import kotlin.CharArray
import kotlin.Int
import kotlin.String
import kotlin.experimental.and
import kotlin.let

/**
* 接口请求文件
Expand Down Expand Up @@ -48,10 +55,21 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.EXPLORER_SERVICE + VideoHttpUtil.REST_HOST_URL, param, headerParams, callback, VideoRequestCode.video_describe_devices)
basePost(
VideoHttpUtil.EXPLORER_SERVICE + VideoHttpUtil.REST_HOST_URL,
param,
headerParams,
callback,
VideoRequestCode.video_describe_devices
)
}

fun getSnapshotUrl(productId: String, devName: String, thumbnail: String, callback: VideoCallback) {
fun getSnapshotUrl(
productId: String,
devName: String,
thumbnail: String,
callback: VideoCallback
) {
var headerParams = videoCommonHeaderParams("DescribeCloudStorageThumbnail", "2020-12-15")
val param = TreeMap<String, Any>()
param["ProductId"] = productId
Expand All @@ -61,8 +79,10 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_snapshot)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_snapshot
)
}

fun getVideoUrl(videoUrl: String, expireTime: kotlin.Long, callback: VideoCallback) {
Expand All @@ -74,11 +94,18 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_video_url)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_video_url
)
}

fun getMJPEGVideoUrl(productId: String, devName: String, startTime: kotlin.Long, callback: VideoCallback) {
fun getMJPEGVideoUrl(
productId: String,
devName: String,
startTime: kotlin.Long,
callback: VideoCallback
) {
var headerParams = videoCommonHeaderParams("DescribeCloudStorageStreamData", "2021-11-25")
val param = TreeMap<String, Any>()
param["ProductId"] = productId
Expand All @@ -88,11 +115,19 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_video_url)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_video_url
)
}

fun getIPCRecordData(productId: String, devName: String, startDate: Date, endDate: Date, callback: VideoCallback) {
fun getIPCRecordData(
productId: String,
devName: String,
startDate: Date,
endDate: Date,
callback: VideoCallback
) {
var headerParams = videoCommonHeaderParams("DescribeCloudStorageEvents", "2020-12-15")
val param = TreeMap<String, Any>()
param["ProductId"] = productId
Expand All @@ -104,8 +139,10 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_record_date)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_record_date
)
}

fun getIPCCurrentDayRecordData(productId: String, devName: String, callback: VideoCallback) {
Expand All @@ -128,8 +165,10 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_date)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_date
)
}

fun getIPCTimeData(
Expand All @@ -144,8 +183,10 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_date_time)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_date_time
)
}

fun getProductInfo(productId: String, callback: VideoCallback) {
Expand All @@ -156,11 +197,13 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_product)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_product
)
}

fun getDeviceXp2pInfo(productId: String,deviceName:String, callback: VideoCallback) {
fun getDeviceXp2pInfo(productId: String, deviceName: String, callback: VideoCallback) {
var headerParams = videoCommonHeaderParams("DescribeP2PInfo", "2021-11-25")
val param = TreeMap<String, Any>()
param["ProductId"] = productId
Expand All @@ -170,8 +213,10 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_product)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_product
)
}


Expand All @@ -184,8 +229,10 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_url)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param, headerParams, callback, VideoRequestCode.video_describe_url
)
}

/**
Expand All @@ -203,7 +250,13 @@ open class VideoBaseService(secretId: String, secretKey: String) {
if (authorization != null) {
headerParams["Authorization"] = authorization
}
basePost(VideoHttpUtil.VIDEO_SERVICE+VideoHttpUtil.REST_HOST_URL, param, headerParams, callback, VideoRequestCode.video_describe_devices)
basePost(
VideoHttpUtil.VIDEO_SERVICE + VideoHttpUtil.REST_HOST_URL,
param,
headerParams,
callback,
VideoRequestCode.video_describe_devices
)
}

/**
Expand Down Expand Up @@ -256,15 +309,17 @@ open class VideoBaseService(secretId: String, secretKey: String) {
val httpRequestMethod = "POST"
val canonicalUri = "/"
val canonicalQueryString = ""
val canonicalHeadersBuilder = "content-type:application/json; charset=utf-8\nhost:${service}${VideoHttpUtil.REST_HOST_URL}\n"
val canonicalHeadersBuilder =
"content-type:application/json; charset=utf-8\nhost:${service}${VideoHttpUtil.REST_HOST_URL}\n"
val signedHeadersBuilder = "content-type;host"
val canonicalHeaders = canonicalHeadersBuilder
val signedHeaders = signedHeadersBuilder.toLowerCase()

// 将Extra参数加到待签名字符串中,否则会签名失败
var payload: String? = JsonManager.toJson(param)
val hashedRequestPayload: String? = payload?.let { sha256Hex(it) }
val canonicalRequest = "${httpRequestMethod}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${hashedRequestPayload}"
val canonicalRequest =
"${httpRequestMethod}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${hashedRequestPayload}"
println(canonicalRequest)

// ************* 步骤 2:拼接待签名字符串 *************
Expand All @@ -281,14 +336,14 @@ open class VideoBaseService(secretId: String, secretKey: String) {

// ************* 步骤 3:计算签名 ************* SecretKey
val secretDate: ByteArray = hmac256(
("TC3" + secretKey).toByteArray(UTF8),
date
)
("TC3" + secretKey).toByteArray(UTF8),
date
)
val secretService: ByteArray = hmac256(secretDate, service)
val secretSigning: ByteArray = hmac256(
secretService,
"tc3_request"
)
secretService,
"tc3_request"
)
val byteArray: ByteArray = hmac256(secretSigning, stringToSign)
val signature: String? = encodeHexString(byteArray)

Expand Down Expand Up @@ -345,14 +400,20 @@ open class VideoBaseService(secretId: String, secretKey: String) {
/**
* base请求
*/
fun basePost(url: String, param: TreeMap<String, Any>, headerParams: Map<String, Any>, callback: VideoCallback, reqCode: Int) {
fun basePost(
url: String,
param: TreeMap<String, Any>,
headerParams: Map<String, Any>,
callback: VideoCallback,
reqCode: Int
) {
VideoHttpUtil.post(url, param, headerParams, object :
HttpCallBack {
override fun onSuccess(response: String) {
Log.d("响应${headerParams["X-TC-Action"]}", response)
val jsonObject = JSON.parse(response) as JSONObject
val jsonResponset = jsonObject.getJSONObject("Response") as JSONObject
if (!jsonResponset.containsKey("ERROR")) {
val jsonObject = JSONObject(response)
val jsonResponset = jsonObject.getJSONObject("Response")
if (!jsonResponset.has("ERROR")) {
callback.success(response, reqCode)
} else {
callback.fail("error", reqCode)
Expand All @@ -364,5 +425,4 @@ open class VideoBaseService(secretId: String, secretKey: String) {
}
})
}

}
Loading

0 comments on commit a772502

Please sign in to comment.