CNLiveMineViewModel.swift 27.5 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
//
//  CNLiveMineViewModel.swift
//  metaCode
//
//  Created by open on 2023/6/14.
//

import Foundation
import CNLiveRequestBastKit
import HandyJSON
import AFNetworking

enum CNLiveMineRequestType {
    case icon
    case nickName
    case gender
    case email
    case location
    case birthday
    case other
}
enum CNLiveMineResponseType {
    case success
    case failed
    case noNetwork
    case unkonw
}
enum CNLiveMineGetWriteType {
    case nodate //未填写
    case havedate //已填写
}
typealias resultBlock = (_ type: CNLiveMineRequestType,_ result: Bool) -> Void
typealias resultNewsBlock = (_ result: Any,_ respStatue :CNLiveMineResponseType) -> Void
class CNLiveMineViewModel: NSObject {
    
    /// 提交更新用户单项数据
    /// - Parameters:
    ///   - type: nickName-昵称,gender-性别,email-邮箱, location-联系方式,birthday-生日yyyy-MM-dd
    ///   - value: 对应的信息,性别,m:男、f:女、n:未知
    static func requestUpdateUserInfoAction(type: CNLiveMineRequestType,value: String, resultBlock: @escaping resultBlock) {
        
        let param = NSMutableDictionary.init()
        if type == .nickName {
            param.setValue("nickName", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        if type == .gender {
            param.setValue("gender", forKey: "type")
            
            param.setValue(value, forKey: "value")
        }
        if type == .email {
            param.setValue("email", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        if type == .location {
            param.setValue("location", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        if type == .birthday {
            param.setValue("birthday", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
        param.setValue(UserInfoManager.shared.userInfo.token, forKey: "token")
        print("给后台的数据是=>\(param)")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .POST, urlString: "/open/api2/user/updateUserById", param: param as! [String : Any], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = resp["errorCode"]
                if (errorCode as! String == "0") {
                    showMessage(message: "更改成功")
                    resultBlock(type,true)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(type,false)
                }
            } else {
                showMessage(message: "修改信息失败")
                resultBlock(type,false)
            }
        }
    }
    
    
    /// 上传并修改头像
    /// - Parameters:
    ///   - image: 头像
    ///   - resultBlock: 返回
    static func requestUploadIconAction(_ image: UIImage,resultBlock: @escaping resultBlock) {
             
        CNLiveMineViewModel.requestAccessTokenAction() {  type, result in
            if result {
                let param = NSMutableDictionary.init()
                param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
                param.setValue(UserInfoManager.shared.userInfo.token, forKey: "token")
                param.setValue(UserInfoManager.shared.userInfo.access_token, forKey: "access_token")
                showLoading(message: "修改头像中...")
                CNLiveNetworking.setAllowRequestDefaultArgument(true)
                CNLiveNetworking.setupShowDataResult(false)
                CNLiveNetworking.setupShowResult(true)
                CNLiveNetworking.uploadNetwork(withURLString: "/open/api2/user/updateUserFaceById", param: param as? [AnyHashable : Any]) { formData in
                    let imageData = image.imageWithZip()
                    formData?.appendPart(withFileData: imageData as Data, name: "face", fileName: ".jpg", mimeType: "image/jpg")
                } progressBlock: { progress in
                    print("已上传==>\(progress!.fractionCompleted*100)")
                } completionBlock: { task, result, error in
                    hiddenLoading()
                    if (error == nil) {
                        let resp = result as! NSDictionary
                        let errorCode = resp["errorCode"]
                        if (errorCode as! String == "0") {
                            showMessage(message: "头像更改成功")
                            let data = resp["data"] as! Dictionary<String, Any>
                            let userInfo = UserInfoManager.shared.userInfo
                            userInfo.faceUrl = data["faceUrl"] as! String
                            userInfo.bigFaceUrl = data["bigFaceUrl"] as! String
                            UserInfoManager.cacheUserInfo(userInfo: userInfo)
                            resultBlock(.icon,true)
                        } else {
                            showMessage(message: resp["errorMessage"] as! String)
                            resultBlock(.icon,false)
                        }
                    } else {
                        showMessage(message: "头像更改失败")
                        resultBlock(.icon,false)
                    }
                }
            } else {
                resultBlock(.icon,false)
            }
        }
    }
    
    /// 获取access_token
    /// - Parameter resultBlock: 结果返回
    static func requestAccessTokenAction(resultBlock: @escaping resultBlock) {
        //当前时间大于最大允许时间则表明当前access_token已经过期需要重新请求
        let param = NSMutableDictionary.init()
        param.setValue(APPId, forKey: "appId")
        param.setValue(APPSecret, forKey: "secret")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(false)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .POST, urlString: "/open/api2/token", param: (param as! [AnyHashable : Any]), cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? 0)"
                if (errorCode == "0") {
                    let data = resp["data"] as! Dictionary<String, Any>
                    let userInfo = UserInfoManager.shared.userInfo
                    userInfo.access_token = data["access_token"] as! String
                    let expires_in = data["expires_in"] as! NSNumber
                    userInfo.expires_in = "\(expires_in.intValue+CNLiveMineViewModel.timeStamp)"
                    UserInfoManager.cacheUserInfo(userInfo: userInfo)
                    resultBlock(.other,true)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(.other,false)
                }
            } else {
                showMessage(message: "修改头像失败")
                resultBlock(.other,false)
            }
        }
    }
    
    /// 上传反馈意见接口
    /// - Parameter resultBlock: 成功回调
    static func requestFeedBack(text: String,contactWay: String,images: NSMutableArray,resultBlock: @escaping resultBlock) {
        if (text.count == 0) {
            showMessage(message: "反馈内容不能为空")
            return
        }
        images.remove("")
        let imageUrl = NSMutableString()
        if images.count > 0 {
            images.forEach { image_url in
                imageUrl.append(image_url as! String)
                imageUrl.append(",")
            }
            imageUrl.deleteCharacters(in: NSRange(location: imageUrl.length - 1, length: 1))
        }
        let param = NSMutableDictionary()
        param.setValue(imageUrl, forKey: "images")
        param.setValue(text, forKey: "text")
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue(contactWay, forKey: "contactWay")
        param.setValue(UserInfoManager.shared.userInfo.nickName, forKey: "contactName")
        param.setValue("", forKey: "category")
        param.setValue("ios", forKey: "plat")
        param.setValue(Bundle.main.infoDictionary?["CFBundleVersion"] as! String, forKey: "version")
        param.setValue(UIDevice.current.identifierForVendor?.uuidString.replacingOccurrences(of: "-", with: "") ?? "", forKey: "deviceId")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseMCUrl+"/commonApi/collectFeedback", 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(.other,true)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(.other,false)
                }
            } else {
                showMessage(message: "提交失败")
                resultBlock(.other,false)
            }
        }
    }
    
    /// 获取系统消息
    /// - Parameter resultBlock: 结果返回
    static func requestMessage(resultBlock: @escaping resultNewsBlock) {
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/newsApi/getNews", param: ["sid":UserInfoManager.shared.userInfo.uid], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let newsModel = dictionaryToModel(resp as! [String : Any], NewsModel.self,"data") as! NewsModel
                    resultBlock(newsModel,.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)
                }
            }
        }
    }
    
    /// 获取身份信息列表数据
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 返回
    static func requestAuthStandList(page: NSInteger, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue("10458139", forKey: "sid")//10458139 UserInfoManager.shared.userInfo.uid
        param.setValue("10", forKey: "pageSize")
        param.setValue("\(page)", forKey: "page")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/allList", 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 listModel = dictionaryToModel(resp as! [String : Any], StandListBaseModel.self,"data") as! StandListBaseModel
                    
                    if CNLiveSaveStandDB.shared.searchAllObject().count > 0 {
                        //第一页
                        if page == 1 {
                            let have_id_auths = CNLiveSaveAuthDB.shared.searchAllObjectId()
                            let have_auths = NSMutableArray()
                            let no_auths = NSMutableArray()
                            for item in listModel.list {
                                //这里需要及时去刷新认证状态  如果没有及时刷新这里回出现已经认证的状态不会进行排序
                                item.auth && have_id_auths.contains("\(item.id)")  ? have_auths.add(item) : no_auths.add(item)
                            }
                            let tempArray = NSMutableArray()
                            for item in have_auths {
                                let standModel = item as! StandListModel
                                let old_index = have_auths.index(of: standModel)
                                let new_index = have_id_auths.firstIndex(of: "\(standModel.id)")
                                if old_index != new_index {
                                    swap(&have_auths[new_index!], &have_auths[old_index])
                                }
                            }
                            tempArray.addObjects(from: have_auths as! [Any])
                            tempArray.addObjects(from: no_auths as! [Any])
                            listModel.list = tempArray as! [StandListModel]
                            CNLiveSaveStandDB.shared.deleteAllObjects()
                            CNLiveSaveStandDB.shared.insertObjects(objects: listModel.list)
                        }else{
                            
                        }
                    }else{
                        CNLiveSaveStandDB.shared.insertObjects(objects: listModel.list)
                    }

                    
                    resultBlock(listModel,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if page > 1 {
                    if CNLiveNetworking.isNetworking() {
                        showMessage(message: "获取失败")
                        resultBlock(NSNull(),.failed)
                    } else {
                        showMessage(message: "似乎与网络断开链接")
                        resultBlock(NSNull(),.noNetwork)
                    }
                }
            }
        }
    }
    
    /// 获取已认证身份列表
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 数据返回
    static func requestsGETAuthInfoList(page: NSInteger, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue("1", forKey: "type") //0正在审核  1已认证  -1审核失败
        param.setValue("\(page)", forKey: "page")
        param.setValue("10", forKey: "pageSize")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/myList", 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 listModel = dictionaryToModel(resp as! [String : Any], MineAuthListBaseModel.self,"data") as! MineAuthListBaseModel
                    if page == 1 {
                        let have_id_auths = CNLiveSaveAuthDB.shared.searchAllObjectId()
                        if have_id_auths.count > 0 {
                            let tempArray_have = NSMutableArray()
                            let tempArray_no = NSMutableArray()
                            for item in listModel.list {
                                if (have_id_auths.contains("\(item.identityId)")) {
                                    tempArray_have.add(item)
                                }else{
                                    tempArray_no.add(item)
                                }
                            }
                            let tempArray = NSMutableArray()
                            tempArray.adding(tempArray_have)
                            tempArray.adding(tempArray_no)
                            listModel.list = tempArray as! [MineAuthListModel]
                            CNLiveSaveAuthDB.shared.deleteAllObjects()
                            CNLiveSaveAuthDB.shared.insertObjects(objects: listModel.list)
                        }else{
                            //本地没值  不进行处理
                        }
                    } else {
                        //多条数据
                        
                    }
                    resultBlock(listModel,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if page > 1 {
                    if CNLiveNetworking.isNetworking() {
                        showMessage(message: "获取失败")
                        resultBlock(NSNull(),.failed)
                    } else {
                        showMessage(message: "似乎与网络断开链接")
                        resultBlock(NSNull(),.noNetwork)
                    }
                }
            }
        }
    }
    
    /// 上传用户认证信息接口
    /// - Parameters:
    ///   - infos: 认证信息数据
    ///   - resultBlock: 返回
    static func requestsPOSTAuthInfo(identityId: String,infos: NSArray, resultBlock: @escaping resultNewsBlock) {
        
        let values = NSMutableDictionary()
        values.addEntries(from: ["sid":UserInfoManager.shared.userInfo.uid])
        values.addEntries(from: ["identityId":identityId])
        let temp_array = NSMutableArray()
        for info in infos {
            let value = (info as! MineStandInfoModel).value ?? ""
            let key = (info as! MineStandInfoModel).name ?? ""
            let authInfoId = (info as! MineStandInfoModel).authInfoId
            let inputType = (info as! MineStandInfoModel).inputType
            let nonEmpty = (info as! MineStandInfoModel).nonEmpty
            if value.count == 0 && nonEmpty {
                if inputType == 3 {
                    showMessage(message: "请选择\(key)")
                    return
                } else {
                    showMessage(message: "请填写\(key)")
                    return
                }
            }
            temp_array.add(["authInfoId":authInfoId,"msg":value] as [String : Any])
        }
        values.addEntries(from: ["authInfo":temp_array])
        do {
            let request = URLRequest.init(url: URL.init(string: APPBaseMCUrl+"/identityApi/saveUserMsg")!) as! NSMutableURLRequest
            request.httpMethod = "POST"
            request.timeoutInterval = 10
            request.setValue("application/json", forHTTPHeaderField: "Content-Type")
            let data = try JSONSerialization.data(withJSONObject: values, options: .prettyPrinted)
            request.httpBody = data
            showLoading(message: "")
            CNLiveNetworking.setAllowRequestDefaultArgument(false)
            CNLiveNetworking.setupShowDataResult(false)
            CNLiveNetworking.setBuildCustomUrlRequest(request as URLRequest) { 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 {
                        showMessage(message: resp["errorMessage"] as! String)
                        resultBlock(NSNull(),.failed)
                    }
                } else {
                    if CNLiveNetworking.isNetworking() {
                        showMessage(message: "上传失败")
                        resultBlock(NSNull(),.failed)
                    } else {
                        showMessage(message: "似乎与网络断开链接")
                        resultBlock(NSNull(),.noNetwork)
                    }
                }
            }
        } catch {
            showMessage(message: "上传失败")
            resultBlock(NSNull(),.failed)
        }
    }
    
    /// 获取身份信息数据
    /// - Parameters:
    ///   - identityId: 身份id
    ///   - resultBlock: 返回
    static func requestsStandInfo(identityId: String, type: CNLiveMineGetWriteType, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue("10458139", forKey: "sid")//UserInfoManager.shared.userInfo.uid //10458139
        param.setValue(identityId, forKey: "identityId")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/getIdentity", 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 newsModel = dictionaryToModel(resp as! [String : Any], MineStandInfoBaseModel.self,"data") as! MineStandInfoBaseModel
                    if type == .nodate {
                        let tempArray = NSMutableArray()
                        for authinfo in newsModel.authInfos {
                            if authinfo.input {
                                tempArray.add(authinfo)
                            }
                        }
                        resultBlock(tempArray,.success)
                    }else {
                        resultBlock(newsModel.authInfos,.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)
                }                
            }
        }
    }
    
    /// 获取最新app版本
    /// - Parameter resultBlock: 结果回调
    static func requestSystemNews(resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue("2", forKey: "appType")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/commonApi/getVersion", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let userInfoModel = dictionaryToModel(resp as! [String : Any], UpdateInfoModel.self,"data") as! UpdateInfoModel
                    let ver1 = "\(userInfoModel.version.split(separator: "_").last ?? "0")"
                    let ver2 = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
                    print("获取的新版本号=>\(ver1),原来的版本号=>\(ver2)")
                    if CNLiveMineViewModel.compare(v1: ver1, v2: ver2) {
                        resultBlock(userInfoModel,.success)
                    } else {
                       print("没有新版本")
                    }
                } else {
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    resultBlock(NSNull(),.failed)
                } else {
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取身份列表
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 返回
    static func requestIdenList(page: Int,resultBlock: @escaping resultNewsBlock) {
        showLoading(message: "")
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue("\(page)", forKey: "page")
        param.setValue("10", forKey: "pageSize")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/list", 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 userInfoModel = dictionaryToModel(resp as! [String : Any], UpdateInfoModel.self,"data") as! UpdateInfoModel
                    resultBlock(userInfoModel,.success)
                    
                } else {
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    resultBlock(NSNull(),.failed)
                } else {
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取十位时间戳
    static var timeStamp: Int {
        let timeInterval: TimeInterval = NSDate().timeIntervalSince1970
        let timeStamp = Int(timeInterval)
        return timeStamp
    }
    
    /// 比较版本大小,返回是否需要更新
    /// - Parameters:
    ///   - v1: 版本1-新版本
    ///   - v2: 版本2-当前版本
    /// - Returns: true:v1>v2  false: v1<=v2
    static fileprivate func compare(v1: String, v2: String) -> Bool {
        
        if v1.isEmpty && v2.isEmpty || v1.isEmpty {
            return false
        }
        
        if v2.isEmpty {
            return true
        }
        
        let array1 = v1.components(separatedBy: ".")
        let array2 = v2.components(separatedBy: ".")
        let mineCount = array1.count > array2.count ? (array2.count - 1) : (array1.count - 1)
        
        var value1: Int = 0
        var value2: Int = 0
        
        for i in 0...mineCount {
            
            if !(array1[i]).isPurnInt() || !(array2[i]).isPurnInt() {
                return false
            }
            value1 = Int(array1[i])!
            value2 = Int(array2[i])!
            
            //v1版本字段大于v2版本字段
            if value1 > value2 {
                return true
            } else if (value1 < value2) {
                return false
            }
            //v1版本==v2版本字段 继续循环
        }
        if array1.count > array2.count {
            return true
        } else if (array1.count <= array2.count) {
            return false
        }
        return false
    }
    
}