CNLiveShortVideoViewModel.swift
3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// CNLiveShortVideoViewModel.swift
// metaCode
//
// Created by open on 2024/1/8.
//
import Foundation
import CNLiveRequestBastKit
typealias resultShortVideoBlock = (_ result: Any,_ respStatue :CNLiveMineResponseType) -> Void
class CNLiveShortVideoViewModel: NSObject {
/// 这是测试请求短视频数据
static func requstWithShortVideo(reultShortVideoBlock: @escaping resultShortVideoBlock) {
let param = NSMutableDictionary()
param.setValue("10511059", forKey: "creatorId")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "userId")
param.setValue("3", forKey: "type")
param.setValue("1", forKey: "page")
param.setValue("10", forKey: "pageSize")
let custom_param = NSMutableDictionary()
custom_param.setValue(APPId_wjj, forKey: "appId")
custom_param.setValue(APPKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSClassUrl+"/ugcApi/ugcVideoList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
if resp["data"] is NSNull {
reultShortVideoBlock(NSNull(), .failed)
} else {
let resp_dict = resp["data"] as! NSDictionary
let array = resp_dict["list"] as! NSArray
let tempArray = NSMutableArray()
let tempUrlArray = NSMutableArray()
var index = 0
for item in array {
let listModel = dictionaryToModel(item as! [String : Any], ShortVideoHomeTestModel.self,"") as! ShortVideoHomeTestModel
if (index > 2) {
listModel.isMoney = true
}
tempArray.add(listModel)
tempUrlArray.add(listModel.videoUrl! as String)
index += 1
}
reultShortVideoBlock([tempArray, tempUrlArray], .success)
}
} else {
showMessage(message: resp["errorMessage"] as! String)
reultShortVideoBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "请求失败")
reultShortVideoBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
reultShortVideoBlock(NSNull(),.noNetwork)
}
}
}
}
}