CNLiveHomePageViewModel.swift
33 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
//
// CNLiveHomePageViewModel.swift
// metaCode
//
// Created by zx on 2024/1/8.
//
import Foundation
import CNLiveRequestBastKit
import CNLiveBusinessTools
class CNLiveHomePageViewModel:NSObject,URLSessionTaskDelegate{
static let shared = CNLiveHomePageViewModel()
///id获取播放地址url
func getVodVideoURL(contentId:String,resultBlock: @escaping downSlideResultBlock){
self.getVodVideoURL(contentId: contentId, rate: 2, resultBlock: resultBlock)
}
///id获取播放地址url, rate
func getVodVideoURL(contentId:String,rate:Int,resultBlock: @escaping downSlideResultBlock){
// 获取当前时间戳(自1970年以来的秒数)
let timeInterval = Date().timeIntervalSince1970
// 将时间戳转换为字符串
// let timeString = String(format: "%ld", Int64(timeInterval))
// 或者更简洁地使用String的初始化方法
let timeString = "\(Int64(timeInterval))"
let bundleIdentifier = Bundle.main.bundleIdentifier
let uuid = CNLiveBusinessTools.getUidForStat(Date())
let shortVersion = "2.3.8"//Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
let param = NSMutableDictionary()
param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
param.setValue(contentId, forKey: "vId")
param.setValue(timeString, forKey: "timestamp")
param.setValue("0", forKey: "isHLS")
param.setValue("i", forKey: "plat")
param.setValue("v", forKey: "playType")
param.setValue(bundleIdentifier, forKey: "platform_id")
param.setValue("", forKey: "channelName")
param.setValue("", forKey: "tag")
param.setValue("", forKey: "from")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
// param.setValue(uuid, forKey: "uid")
param.setValue(shortVersion, forKey: "ver")
param.setValue("1", forKey: "appType")
param.setValue("i", forKey: "clientPlat")
param.setValue(shortVersion, forKey: "version")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "loginSid")
param.setValue("release", forKey: "app_channel_id")
param.setValue("\(rate)", forKey: "rate")
param.setValue("release", forKey: "app_channel_id")
param.setValue("0", forKey: "retry")
let signStr = CNLiveBusinessTools.signvalue(param as! [AnyHashable : Any])
let string1 = "\(signStr)&key=\(CNLiveMCEnvironmentManager.shared.appKey)"
let signString1 = CNLiveBusinessTools.sha1(string1).uppercased()
let liveUrl = APPLoginHost+"/open/api2/vod_ips/vodplayByAPP"
let videourl = "\(liveUrl)?\(signStr)&sign=\(signString1)"
print("111111URL:\(videourl)")
// 创建一个可变URL请求
let urlRequest = NSMutableURLRequest(url: URL(string: videourl)!)
urlRequest.httpMethod = "GET"
urlRequest.timeoutInterval = 30
let config = URLSessionConfiguration.default
config.requestCachePolicy = .reloadIgnoringLocalCacheData
let urlSession = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue.current)
let task = urlSession.dataTask(with: urlRequest as URLRequest) { data, response, error in
if let urlResponse = response as? HTTPURLResponse, urlResponse.statusCode == 301 || urlResponse.statusCode == 302 {
// do something ...
print("重定向地址 == \(urlResponse.allHeaderFields["Location"] as? String ?? "无重定向地址")")
resultBlock(urlResponse.allHeaderFields["Location"] as? String ?? "",.success)
}
}
task.resume()
}
func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
print("\(response.statusCode)") // 302
print("\(response.allHeaderFields["Location"] as? String ?? "无重定向地址")") // 重定向地址URL
// 根据业务需求决定是否使用新的请求继续任务
// completionHandler(request) // 使用新的请求继续任务
// completionHandler(nil) // 不使用新的请求,取消重定向
// 在这个例子中,我们简单地取消重定向(即不使用新的请求)
completionHandler(nil)
}
//点播详情 album.albumId为""是点播 ,否则专辑
static func requestGetVodPlayApi( contentId:String,sid:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(contentId, forKey: "contentId")
param.setValue(sid, forKey: "sid")
param.setValue("", forKey: "channelName")
param.setValue("1", forKey: "model")
param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
param.setValue("1", forKey: "type")
param.setValue("", forKey: "app_channel_id")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
//https://cmsapi.cnlive.com/playApi/play?contentId=1350760&sid=&channelName=&model=1&appId=769_li40lrkt53&type=1&app_channel_id=
CNLiveNetworking.requestNetwork(with: .GET, urlString: "https://cmsapi.cnlive.com/playApi/play", 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 let dataDic = resp["data"] as? Dictionary<String, Any>{
let dataMdl = newDictionaryToModel(dataDic , CNLiveVodPlayModel.self)
resultBlock(dataMdl,.success)
}else
{
resultBlock(NSNull(),.failed)
}
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取专辑信息接口
/// - Parameters:
/// - aid: 专辑名称
/// - resultBlock: 返回
static func requstWithVodAlbumMsgVideo(aid: String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("mc_app", forKey: "app_channel_id")
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getAlbumMsg", param: param as! [String : Any], 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 {
resultBlock(NSNull(), .failed)
} else {
let listModel = dictionaryToModel(resp["data"] as! [String : Any], CNLiveVodAlbumMsgModel.self,"") as! CNLiveVodAlbumMsgModel
resultBlock(listModel, .success)
}
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "请求失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
}
//专辑列表
static func requstWithVodAlbumVideoList(aid: String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("mc_app", forKey: "app_channel_id")
param.setValue("1", forKey: "page")
param.setValue("200", forKey: "pageSize")
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/albumVideoList", param: param as! [String : Any], 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 {
resultBlock(NSNull(), .failed)
} else {
let listModel = dictionaryToModel(resp["data"] as! [String : Any], CNLiveVodAlbumListBaseModel.self,"") as! CNLiveVodAlbumListBaseModel
resultBlock(listModel, .success)
}
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "请求失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
}
/// 忽必烈 获取首页原生页面顶部频道数据
static func requestGetHomePageTopConfigList( resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue("3310", forKey: "siteStyleId")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
// http://cms.cnlive.com/api/contentApi/otherChannelList?siteStyleId=3310
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/otherChannelList", 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") {
let dataArr = resp["data"] as! Array<Any>
var resArr = []
if dataArr.count > 0{
//有在追短剧
for dataDic in dataArr {
let dataMdl = newDictionaryToModel(dataDic as! [String : Any], CNLiveHomePageHuBiLieModel.self)
resArr.append(dataMdl)
}
}else{
//没有在追短剧
}
resultBlock(resArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
//电商分类
static func requestGetHomePageShopCategoryApi(shop_id:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(shop_id, forKey: "shop_id")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj_b, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj_b, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjShopUrl+"/Api/Index3/sellerCategory", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
if let errCode = resp["code"] as? String{
if errCode == "200" || errCode == "0"{
let dataDic = resp["data"] as! NSDictionary
let shopCategoryModel = newDictionaryToModel(dataDic as! [String : Any], CNLiveHomeShopCategoryModel.self)
resultBlock(shopCategoryModel,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
resultBlock(NSNull(),.failed)
}
}
static func requestGetHomePageFollow( sid:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue("yszg", forKey: "channelName")
// param.setValue("1342671", forKey: "sid")
param.setValue(sid, forKey: "sid")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
// http://cms.cnlive.com/api/recordApi/getRecords?sid=10506285&channelName=yszg
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/recordApi/getRecords", 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") {
let dataDic = resp["data"] as! Dictionary<String, Any>
var resArr = dataDic["list"] as! Array<Any>
if resArr.count > 0{
//有在追
let followDic = resArr.first as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(followDic as! [String : Any], CNLiveHomeFollowModel.self)
resultBlock(dataMdl,.success)
}else{
//没有在追短剧
resultBlock(NSNull(),.failed)
}
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
static func requestGetMinePlayHistory( sid:String,page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue("yszg", forKey: "channelName")
param.setValue("\(page)", forKey: "page")
// param.setValue("1342671", forKey: "sid")
param.setValue(sid, forKey: "sid")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
// http://cms.cnlive.com/api/recordApi/getRecords?sid=10506285&channelName=yszg
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/recordApi/getRecords", 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 {
resultBlock(NSNull(), .failed)
} else {
let listModel = dictionaryToModel(resp["data"] as! [String : Any], CNLiveHomeFollowListBaseModel.self,"") as! CNLiveHomeFollowListBaseModel
resultBlock(listModel, .success)
}
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "请求失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
}
//收藏列表:contentApi/getCollectionList 参数:sid、source=yszg、page、pageSize
static func getCollectionListApi(sid:String,page:String,pageSize:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(sid, forKey: "sid")
param.setValue("yszg", forKey: "source")
param.setValue(page, forKey: "page")
param.setValue(pageSize, forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getCollectionList", 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 {
resultBlock(NSNull(), .failed)
} else {
let listModel = dictionaryToModel(resp["data"] as! [String : Any], CNLiveCollectionListBaseModel.self,"") as! CNLiveCollectionListBaseModel
resultBlock(listModel, .success)
}
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
}else{
resultBlock(NSNull(),.failed)
}
}
}
/// 获取首页原生页面数据
static func requestGetHomePageConfigList( resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/commonApi/homePageConfigList", 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") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic, CNLiveHomePageModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 短剧主页-专辑收藏(追剧)
static func postAlbumCollect(aid:String,type:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(type)", forKey: "type")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseCMSUrl+"/contentApi/albumCollect", 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") {
resultBlock(NSNull(),.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页我的专辑收藏数据
static func requestGetHomePageMyAlbum(page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(page)", forKey: "page")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/myAlbum", 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") {
let dataArr = resp["data"] as! Array<Any>
var resArr = []
if dataArr.count > 0{
//有在追短剧
for dataDic in dataArr {
let dataMdl = newDictionaryToModel(dataDic as! [String : Any], CNLiveAlbumMsgModel.self)
resArr.append(dataMdl)
}
}else{
//没有在追短剧
}
resultBlock(resArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-全部专辑列表,区块内容分页
static func getBlockContents(blockId:String,page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(blockId, forKey: "blockId")
param.setValue("\(page)", forKey: "page")
// param.setValue("10", forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getBlockContents", 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") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic , CNLiveAlbumBaseModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-专辑详情简介
static func getAlbumMsg(aid:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getAlbumMsg", 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") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic, CNLiveAlbumMsgModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-专辑视频列表详情
static func getAlbumList(aid:String, page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue("mc_app", forKey: "app_channel_id")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(page)", forKey: "page")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/ugcApi/albumList", 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") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic , CNLiveAlbumListBaseModel.self)
resultBlock(dataMdl,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 积分支付
static func orderVideoByPoint(prdId:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue(APPId, forKey: "sp_id")
param.setValue(prdId, forKey: "prdId")
param.setValue("apple", forKey: "frmId")
param.setValue(CNLiveHomePageViewModel.getRandomOrderId(), forKey: "srvOrderId")
CNLiveNetworking.setupShowResult(true)
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .POST, urlString: "\(CNLiveMCEnvironmentManager.shared.img_token_url)/pom/orderVideoByPoint", 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") {
//兑换成功
resultBlock(NSNull(),.success)
}else if (errorCode == "4002") {
//积分不足
resultBlock("积分不足",.failed)
}else
{
resultBlock("兑换失败,请稍候再试!",.failed)
}
}
}
}
//内购
static func generateTradeNumber() -> String {
// 生成3个0-9的随机数
let randomDigits = (0..<3).map { _ in String(Int.random(in: 0...9)) }.joined()
// 日期格式化(yyMMdd)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyMMdd"
let dateString = dateFormatter.string(from: Date())
// 处理时间戳(精确到毫秒)
let timestamp = String(format: "%.0f", Date().timeIntervalSince1970 * 1000)
// 截取时间戳后8位,并处理异常情况
let timeString: String = {
guard timestamp.count >= 8 else {
return String(timestamp.suffix(timestamp.count))
}
return String(timestamp.suffix(8))
}()
// 组合交易号
return "003apple\(dateString)\(timeString)\(randomDigits)"
}
static func getRandomOrderId() -> String {
// appId+渠道+年月日+毫秒数后10位+2位数的随机数
var randomOrderId = ""
//年月日
let formatter = DateFormatter()
formatter.dateFormat = "yyyyMMdd"
let currentDate = Date()
let currentDateString = formatter.string(from: currentDate)
//取毫秒时间戳
let timestamp13 = String(format: "%ld",self.getNow13Timestamp())//timeStamp)
//拼接
randomOrderId = String(format: "%@%@%@%d", APPId_wjj, currentDateString, timestamp13, Int.random(in: 0..<10))
return randomOrderId
}
static func getNow13Timestamp() -> Int {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
formatter.timeZone = TimeZone(identifier: "Asia/Beijing")
let dateNow = Date()
let timeStamp = Int(dateNow.timeIntervalSince1970)
return timeStamp*1000
}
}