Selaa lähdekoodia

增加视频地址判断解密

Harry 1 vuosi sitten
vanhempi
commit
33312c5e04

+ 4 - 3
BFStuckPointKit.podspec

@@ -8,7 +8,7 @@
 
 Pod::Spec.new do |s|
   s.name             = 'BFStuckPointKit'
-  s.version          = '0.1.4'
+  s.version          = '0.1.5'
   s.summary          = '卡点视频库'
   s.swift_version    = '5.0'
   s.description      = <<-DESC
@@ -36,10 +36,11 @@ TODO: Add long description of the pod here.
   s.dependency 'BFMediaKit'
   s.dependency 'BFAnalyzeKit'
   s.dependency 'BFUploadKit'
-  s.dependency 'WechatOpenSDK-Swift'      ,'1.8.7.1'  # 微信组件
+  s.dependency 'WechatOpenSDK-Swift'      ,'1.8.7.1'   # 微信组件
   s.dependency 'MJRefresh'                ,'~> 3.0'    # 刷新组件
   s.dependency 'LMJHorizontalScrollText'  ,'2.0.2'
   s.dependency 'TXLiteAVSDK_Player'       ,'9.3.10765' # 腾讯播放器组件
-  s.dependency 'Bugly'                    ,'2.5.90'   #crash log 收集
+  s.dependency 'Bugly'                    ,'2.5.90'    # crash log 收集
+  s.dependency 'CryptoSwift'              ,'~> 1.5.1'     # 加密库
 
 end

+ 52 - 2
BFStuckPointKit/Classes/BFUtils/PQSingletoVideoPlayer.swift

@@ -11,6 +11,7 @@ import BFAnalyzeKit
 import BFCommonKit
 import BFUploadKit
 import UIKit
+import CryptoSwift
 
 public class PQSingletoVideoPlayer: NSObject {
     public static let shared = PQSingletoVideoPlayer()
@@ -139,10 +140,59 @@ public class PQSingletoVideoPlayer: NSObject {
     /// 开始播放
     public func startPlayr() {
         BFLog(message: "开始播放 \(playVideoData?.videoPath ?? "")")
-        if isValidURL(url: playVideoData?.videoPath) {
-            player.startPlay(playVideoData?.videoPath)
+        // 2023-08-28 增加加密地址,修改逻辑
+//        if isValidURL(url: playVideoData?.videoPath) {
+//            player.startPlay(playVideoData?.videoPath)
+//        }
+        if let realPath = getRealVideoPath(url: playVideoData?.videoPath) {
+            player.startPlay(realPath)
         }
     }
+    
+    public func getRealVideoPath(url: String?) -> String?{
+        var tmpUrl = url
+        if tmpUrl == nil || (tmpUrl?.count ?? 0) <= 4 {
+            return nil
+        }
+        
+        if !(tmpUrl!.hasPrefix("http")) && !(tmpUrl!.hasPrefix("https")) {
+            do {
+                let encrytoData = Data(base64Encoded: tmpUrl!, options: .ignoreUnknownCharacters) ?? Data()
+                let key: String = "pqv2jo0lon2vid2t"
+                let decryptedString = try aes128Decrypt(data: encrytoData, key: key)
+                print("Decrypted String: \(decryptedString)")
+                return decryptedString
+            }catch {
+                print("Decryption error: \(error)")
+
+            }
+        }
+        return url
+    }
+    
+    func aes128Decrypt(data: Data, key: String) throws -> String {
+        let keyData = Array(key.utf8)
+
+        do {
+            let aes = try AES(key: keyData, blockMode: ECB(), padding: .pkcs7)
+            let decrypted = try aes.decrypt(data.bytes)
+            let decryptedData = Data(decrypted)
+            
+            if let decryptedString = String(data: decryptedData, encoding: .utf8) {
+                return decryptedString
+            } else {
+                throw CryptoError.decryptionFailed
+            }
+        } catch {
+            throw CryptoError.decryptionFailed
+        }
+    }
+
+    enum CryptoError: Error {
+        case decryptionFailed
+    }
+
+    
 
     /// 暂停播放
     public func pausePlayer() {

+ 1 - 0
BFStuckPointKit/Classes/Controller/PQStuckPointEditerController.swift

@@ -16,6 +16,7 @@ import ObjectMapper
 import Photos
 import RealmSwift
 import UIKit
+import LMJHorizontalScrollText
 
 class PQStuckPointEditerController: BFBaseViewController {
     // 是否导出视频成功