Commit 33809b499547c9aab0b2a3d5640ce64ca36a92c0

Authored by 张旭
1 parent 85d03d84

修复一键登录偶尔失败的问题 ,网络库的appid偶尔变的问题

metaCode/Classes/Main/LoginPage/Controller/CNLiveLoginViewController.swift
@@ -708,21 +708,32 @@ extension CNLiveLoginViewController { @@ -708,21 +708,32 @@ extension CNLiveLoginViewController {
708 TXCommonHandler.sharedInstance().cancelLoginVC(animated: true) {} 708 TXCommonHandler.sharedInstance().cancelLoginVC(animated: true) {}
709 CNLiveLoginViewModel.oneClickLogin(accessToken: token, frmld: "apple") { result, status in 709 CNLiveLoginViewModel.oneClickLogin(accessToken: token, frmld: "apple") { result, status in
710 if status == .success{//result:UserInfoModel 710 if status == .success{//result:UserInfoModel
711 - //成功  
712 - NotificationCenter.default.post(name: Notification.Name.LoginManage.CNLiveLoginSuccessNotification, object: nil)  
713 - metaAppDelegate.isLogin = true  
714 - if self.navBackButton.isHidden{  
715 - //退出登录后->登录  
716 - let window = UIApplication.shared.delegate?.window  
717 - window??.rootViewController = CNLiveBaseTabBarViewController.init()  
718 - }else{  
719 - //未登录push过来的  
720 - self.navigationController?.popViewController(animated: true) 711 + if let res = result as? UserInfoModel{
  712 + UserInfoManager.cacheUserInfo(userInfo: res)
  713 + if var userDic = UserDefaults.standard.dictionary(forKey: UserInfoManager.shared.userInfo.uid){
  714 +
  715 + }else{
  716 + let tempDic = NSMutableDictionary()
  717 + UserDefaults.standard.setValue(tempDic, forKey: UserInfoManager.shared.userInfo.uid)
  718 + UserDefaults.standard.synchronize()
  719 + }
  720 + //成功
  721 + NotificationCenter.default.post(name: Notification.Name.LoginManage.CNLiveLoginSuccessNotification, object: nil)
  722 + metaAppDelegate.isLogin = true
  723 + if self.navBackButton.isHidden{
  724 + //退出登录后->登录
  725 + let window = UIApplication.shared.delegate?.window
  726 + window??.rootViewController = CNLiveBaseTabBarViewController.init()
  727 + }else{
  728 + //未登录push过来的
  729 + self.navigationController?.popViewController(animated: true)
  730 + }
721 } 731 }
722 - }else{  
723 - let window = UIApplication.shared.delegate?.window  
724 - window??.rootViewController = CNLiveBaseTabBarViewController.init()  
725 } 732 }
  733 +// else{
  734 +// let window = UIApplication.shared.delegate?.window
  735 +// window??.rootViewController = CNLiveBaseTabBarViewController.init()
  736 +// }
726 737
727 } 738 }
728 }else if PNSCodeLoginControllerSuspendDisMissVC == resultCode{ 739 }else if PNSCodeLoginControllerSuspendDisMissVC == resultCode{
metaCode/Classes/Main/LoginPage/ViewModel/CNLiveLoginViewModel.swift
@@ -20,7 +20,7 @@ typealias resultLoginBlock = () -> Void @@ -20,7 +20,7 @@ typealias resultLoginBlock = () -> Void
20 typealias endRefreshBlock = () -> Void 20 typealias endRefreshBlock = () -> Void
21 21
22 22
23 -class CNLiveLoginViewModel : NSObject { 23 +class CNLiveLoginViewModel : NSObject,URLSessionTaskDelegate {
24 24
25 /// 获取验证码 25 /// 获取验证码
26 /// - Parameters: 26 /// - Parameters:
@@ -355,14 +355,13 @@ class CNLiveLoginViewModel : NSObject { @@ -355,14 +355,13 @@ class CNLiveLoginViewModel : NSObject {
355 } 355 }
356 } 356 }
357 357
358 -  
359 /** 358 /**
360 * @abstract App 一键登录 359 * @abstract App 一键登录
361 * 360 *
362 * @param accessToken 阿里云号码认证token 361 * @param accessToken 阿里云号码认证token
363 * @param block 回调 362 * @param block 回调
364 */ 363 */
365 - static func oneClickLogin(accessToken: String, frmld:String, resultBlock: @escaping downSlideResultBlock) { 364 + class func oneClickLogin(accessToken: String, frmld:String, resultBlock: @escaping downSlideResultBlock) {
366 showLoading(message: "") 365 showLoading(message: "")
367 366
368 // 获取当前时间戳(自1970年以来的秒数) 367 // 获取当前时间戳(自1970年以来的秒数)
@@ -377,17 +376,25 @@ class CNLiveLoginViewModel : NSObject { @@ -377,17 +376,25 @@ class CNLiveLoginViewModel : NSObject {
377 param.setValue(CNLiveBusinessTools.getUidForStat(Date()), forKey: "uuid") 376 param.setValue(CNLiveBusinessTools.getUidForStat(Date()), forKey: "uuid")
378 param.setValue(frmld, forKey: "frmId") 377 param.setValue(frmld, forKey: "frmId")
379 param.setValue("i", forKey: "clientPlat") 378 param.setValue("i", forKey: "clientPlat")
380 - param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId") 379 + let appIdStr = CNLiveMCEnvironmentManager.shared.appId_wjj
  380 + param.setValue(appIdStr, forKey: "appId")
381 param.setValue("i", forKey: "plat") 381 param.setValue("i", forKey: "plat")
382 param.setValue(shortVersion, forKey: "ver") 382 param.setValue(shortVersion, forKey: "ver")
383 param.setValue(bundleIdentifier, forKey: "platform_id") 383 param.setValue(bundleIdentifier, forKey: "platform_id")
384 param.setValue(timeString, forKey: "timestamp") 384 param.setValue(timeString, forKey: "timestamp")
385 385
386 let signStr = CNLiveBusinessTools.signvalue(param as! [AnyHashable : Any]) 386 let signStr = CNLiveBusinessTools.signvalue(param as! [AnyHashable : Any])
387 - let string1 = "\(signStr)&key=\(CNLiveMCEnvironmentManager.shared.appKey)" 387 + let appkeyStr = CNLiveMCEnvironmentManager.shared.appKey_wjj
  388 + let string1 = "\(signStr)&key=\(appkeyStr)"
388 let signString1 = CNLiveBusinessTools.sha1(string1).uppercased() 389 let signString1 = CNLiveBusinessTools.sha1(string1).uppercased()
389 param.setValue(signString1, forKey: "sign") 390 param.setValue(signString1, forKey: "sign")
  391 + let custom_param = NSMutableDictionary()
  392 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
  393 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
  394 + CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
390 395
  396 + CNLiveNetworking.setAllowRequestDefaultArgument(false)
  397 + CNLiveNetworking.setupShowDataResult(false)
391 CNLiveNetworking.requestNetwork(with: .POST, urlString: APPLoginHost+"/open/api2/user/getMobileAndLoginApp", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in 398 CNLiveNetworking.requestNetwork(with: .POST, urlString: APPLoginHost+"/open/api2/user/getMobileAndLoginApp", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
392 hiddenLoading() 399 hiddenLoading()
393 if (error == nil) { 400 if (error == nil) {
@@ -407,15 +414,28 @@ class CNLiveLoginViewModel : NSObject { @@ -407,15 +414,28 @@ class CNLiveLoginViewModel : NSObject {
407 if errorCode as? String == "42013"{ 414 if errorCode as? String == "42013"{
408 resultBlock(errorCode ?? "", .failed) 415 resultBlock(errorCode ?? "", .failed)
409 }else{ 416 }else{
  417 + showMessage(message: "登录失败,请重试")
410 resultBlock(NSNull(), .failed) 418 resultBlock(NSNull(), .failed)
411 } 419 }
412 } 420 }
413 } else { 421 } else {
414 - showMessage(message: "登录失败") 422 + showMessage(message: "登录失败,请重试")
415 resultBlock(NSNull(), .failed) 423 resultBlock(NSNull(), .failed)
416 } 424 }
417 425
418 } 426 }
419 } 427 }
  428 + func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
  429 + print("\(response.statusCode)") // 302
  430 + print("\(response.allHeaderFields["Location"] as? String ?? "无重定向地址")") // 重定向地址URL
  431 +
  432 + // 根据业务需求决定是否使用新的请求继续任务
  433 + // completionHandler(request) // 使用新的请求继续任务
  434 + // completionHandler(nil) // 不使用新的请求,取消重定向
  435 +
  436 + // 在这个例子中,我们简单地取消重定向(即不使用新的请求)
  437 + completionHandler(nil)
  438 + }
  439 +
420 440
421 } 441 }