ATAuthSDKManager.swift 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // ATAuthSDKManager.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/8/1.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyJSON
  10. import SwiftyMediator
  11. class ATAuthSDKManager: NSObject {
  12. /// 手机一键登录
  13. class func oneBuiltLogin(vc:UIViewController?) {
  14. TXCommonHandler.sharedInstance().checkAsyncGatewayVerifyEnable(nil) {[weak vc] (enable) in
  15. NXLLog(TXCommonHandler.sharedInstance().getVersion())
  16. DispatchQueue.main.async {
  17. [weak vc] in
  18. if !enable {//先获取authortoken并认证
  19. Mediator.push(RegisterLoginRouterModuleType.pushmobileLoginView)
  20. SwiftProgressHUD.shared().showText("一键登录失败,请使用验证码登录")
  21. return
  22. }
  23. let modelNew = TXCustomModel()
  24. /// navigationbara
  25. modelNew.navColor = kffffffColor
  26. modelNew.navBackImage = kImage(name: "navbar_back_black")!
  27. WRNavigationBar.defaultNavBarBackgroundImage = UIImage.imageWithColor(color: kffffffColor)
  28. UINavigationBar.appearance().tintColor = UIColor.black
  29. WRNavigationBar.defaultStatusBarStyle = .default
  30. //Moblie
  31. modelNew.numberFont = kRegularFont36!
  32. modelNew.numberColor = UIColor.black
  33. modelNew.numberTopOffetY = 120 * kScaleWidth
  34. // slogan
  35. modelNew.sloganIsHidden = false
  36. modelNew.sloganText = NSAttributedString(string: "阿里云提供认证服务", attributes: [
  37. NSAttributedString.Key.foregroundColor: k333333Color,
  38. NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14.0)
  39. ])
  40. modelNew.sloganTopOffetY = 175 * kScaleWidth
  41. //changeBtn
  42. modelNew.changeBtnIsHidden = true
  43. //协议
  44. modelNew.checkBoxImages = [UIImage(named: "icon_uncheck")!,UIImage(named: "icon_check")!]
  45. modelNew.privacyOne = ["由你用户协议",kH5ContentId6Url];
  46. modelNew.privacyTwo = ["隐私条款",kH5ContentId11Url];
  47. modelNew.checkBoxIsChecked = true
  48. modelNew.privacyBottomOffetY = 46.5 - kSafeTabBarHeight
  49. modelNew.privacyColors = [kbbbbbbColor,k333333Color];
  50. //loginBtn
  51. let normalImage = UIImage.image(with: kThemeColor, size: CGSize(width: 295, height: 48.0), isRoundedCorner: true)
  52. let disableImage = UIImage.image(with: kThemeColor, size: CGSize(width: 295, height: 48.0), isRoundedCorner: true)
  53. let lightedImage = UIImage.image(with: kThemeColor, size: CGSize(width: 295, height: 48.0), isRoundedCorner: true)
  54. modelNew.loginBtnBgImgs = [normalImage as Any,disableImage as Any,lightedImage as Any]
  55. // modelNew.loginBtnTitle = "一键登录"
  56. // modelNew.loginBtnTitleColor = UIColor.white
  57. modelNew.loginBtnTopOffetY = 245 * kScaleWidth
  58. TXCommonHandler.sharedInstance().getLoginToken(with: vc!, model: modelNew, timeout: 10, complete: { [weak vc] (resultDic) in
  59. let resultDic = resultDic as NSDictionary
  60. let atAuthSDKModel = ATAuthSDKModel(JSON: resultDic as! [String : Any])
  61. switch atAuthSDKModel?.resultCode {
  62. case TX_Login_SSO_Action:
  63. SwiftMoyaNetWorkServiceUser.shared().userMobileAuthorizationLoginApi(token: atAuthSDKModel?.token ?? "", completion: {
  64. [weak vc] (userModel) -> (Void) in
  65. TXCommonHandler.sharedInstance().cancelLoginVC(animated: true, complete: {
  66. [weak vc] in
  67. RegisterLoginManager.registerLoginSuccessApi(vc: vc)
  68. })
  69. })
  70. break
  71. case TX_Auth_Result_Success,TX_Login_Return_Action,TX_Login_Change_Action:
  72. break
  73. default:
  74. SwiftProgressHUD.shared().showText(atAuthSDKModel?.msg ?? "数据有误")
  75. break
  76. }
  77. })
  78. }
  79. }
  80. }
  81. }