Commit 4b46ed20edc13f931472ea3ee24e4b86b1f162fd

Authored by “张旭”
1 parent b65580f1

微信登录 , 苹果登录 , 绑定手机号

metaCode.xcodeproj/project.pbxproj
... ... @@ -126,6 +126,8 @@
126 126 19BB1FF02AF0E5B30094D962 /* CNLiveShopDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19BB1FEF2AF0E5B30094D962 /* CNLiveShopDetailModel.swift */; };
127 127 19BB1FF22AF21A950094D962 /* CNLliveShopDetailBannerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19BB1FF12AF21A950094D962 /* CNLliveShopDetailBannerCell.swift */; };
128 128 19BB202B2AF382150094D962 /* CNLiveAdaptTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19BB202A2AF382150094D962 /* CNLiveAdaptTool.swift */; };
  129 + 19C0F7672BD8DC4D0097CC8F /* CNThreeLoginModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C0F7662BD8DC4D0097CC8F /* CNThreeLoginModel.swift */; };
  130 + 19C0F7692BD9F9F70097CC8F /* CNThreeLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C0F7682BD9F9F70097CC8F /* CNThreeLoginViewController.swift */; };
129 131 19CC4D472ADD006600308E2A /* CNDownSlideSingleCourseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19CC4D462ADD006600308E2A /* CNDownSlideSingleCourseCell.swift */; };
130 132 19CC4D492ADD06C500308E2A /* UITableView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19CC4D482ADD06C500308E2A /* UITableView+Extension.swift */; };
131 133 19CC4D4B2ADD086F00308E2A /* CNUpSlideDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19CC4D4A2ADD086F00308E2A /* CNUpSlideDetailViewController.swift */; };
... ... @@ -401,6 +403,8 @@
401 403 19BB1FEF2AF0E5B30094D962 /* CNLiveShopDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopDetailModel.swift; sourceTree = "<group>"; };
402 404 19BB1FF12AF21A950094D962 /* CNLliveShopDetailBannerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLliveShopDetailBannerCell.swift; sourceTree = "<group>"; };
403 405 19BB202A2AF382150094D962 /* CNLiveAdaptTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveAdaptTool.swift; sourceTree = "<group>"; };
  406 + 19C0F7662BD8DC4D0097CC8F /* CNThreeLoginModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNThreeLoginModel.swift; sourceTree = "<group>"; };
  407 + 19C0F7682BD9F9F70097CC8F /* CNThreeLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNThreeLoginViewController.swift; sourceTree = "<group>"; };
404 408 19CC4D462ADD006600308E2A /* CNDownSlideSingleCourseCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNDownSlideSingleCourseCell.swift; sourceTree = "<group>"; };
405 409 19CC4D482ADD06C500308E2A /* UITableView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableView+Extension.swift"; sourceTree = "<group>"; };
406 410 19CC4D4A2ADD086F00308E2A /* CNUpSlideDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNUpSlideDetailViewController.swift; sourceTree = "<group>"; };
... ... @@ -1008,6 +1012,14 @@
1008 1012 path = Model;
1009 1013 sourceTree = "<group>";
1010 1014 };
  1015 + 19C0F7652BD8DC390097CC8F /* Model */ = {
  1016 + isa = PBXGroup;
  1017 + children = (
  1018 + 19C0F7662BD8DC4D0097CC8F /* CNThreeLoginModel.swift */,
  1019 + );
  1020 + path = Model;
  1021 + sourceTree = "<group>";
  1022 + };
1011 1023 19CC4D502ADD126D00308E2A /* Util */ = {
1012 1024 isa = PBXGroup;
1013 1025 children = (
... ... @@ -1057,10 +1069,10 @@
1057 1069 790D018C2A2D8C9A00C5978D /* LoginPage */ = {
1058 1070 isa = PBXGroup;
1059 1071 children = (
  1072 + 19C0F7652BD8DC390097CC8F /* Model */,
1060 1073 790D01942A2DB9EF00C5978D /* View */,
1061 1074 790D018D2A2D8C9A00C5978D /* ViewModel */,
1062 1075 790D018E2A2D8C9A00C5978D /* Controller */,
1063   - 790D018F2A2D8C9A00C5978D /* Model */,
1064 1076 );
1065 1077 path = LoginPage;
1066 1078 sourceTree = "<group>";
... ... @@ -1077,17 +1089,11 @@
1077 1089 isa = PBXGroup;
1078 1090 children = (
1079 1091 790D018A2A2D8B3300C5978D /* CNLiveLoginViewController.swift */,
  1092 + 19C0F7682BD9F9F70097CC8F /* CNThreeLoginViewController.swift */,
1080 1093 );
1081 1094 path = Controller;
1082 1095 sourceTree = "<group>";
1083 1096 };
1084   - 790D018F2A2D8C9A00C5978D /* Model */ = {
1085   - isa = PBXGroup;
1086   - children = (
1087   - );
1088   - path = Model;
1089   - sourceTree = "<group>";
1090   - };
1091 1097 790D01942A2DB9EF00C5978D /* View */ = {
1092 1098 isa = PBXGroup;
1093 1099 children = (
... ... @@ -1749,6 +1755,7 @@
1749 1755 1917334C2B2BE9CA007BCC04 /* CNLiveCreateCouponTypeMoneyView.swift in Sources */,
1750 1756 191733002B0B58E5007BCC04 /* CNLiveSelectUploadImageModel.swift in Sources */,
1751 1757 19F1C2332AB5728B0083D06C /* CNIDCardView.swift in Sources */,
  1758 + 19C0F7692BD9F9F70097CC8F /* CNThreeLoginViewController.swift in Sources */,
1752 1759 191732F32B084DBC007BCC04 /* CNLiveShopClassifySwitchTableViewCell.swift in Sources */,
1753 1760 191732E72B0615C1007BCC04 /* UIScrollView+CNLiveExtensions.swift in Sources */,
1754 1761 1917328E2B032583007BCC04 /* CNLiveRoundedRectView.swift in Sources */,
... ... @@ -1929,6 +1936,7 @@
1929 1936 1938BD262B479D3400390A34 /* UILabel+FormattedText.swift in Sources */,
1930 1937 79DC67642B5FB60900261A94 /* CNLiveMineAuthFormViewController.swift in Sources */,
1931 1938 790D01852A2D89E100C5978D /* UIColor+CNLiveExtensions.swift in Sources */,
  1939 + 19C0F7672BD8DC4D0097CC8F /* CNThreeLoginModel.swift in Sources */,
1932 1940 794FF1092B02131300385E85 /* CNLiveSaveSearchDB.swift in Sources */,
1933 1941 79396EED2A319F220053E1AF /* NSObject+CNLiveExtensions.swift in Sources */,
1934 1942 1917331B2B10A0EF007BCC04 /* CNLivePlayerLoadingView.swift in Sources */,
... ...
metaCode/Classes/Main/LoginPage/Controller/CNLiveLoginViewController.swift
... ... @@ -10,6 +10,7 @@ import UIKit
10 10 import SnapKit
11 11 import APButton
12 12 import CNLiveShareToolKit
  13 +import AuthenticationServices
13 14  
14 15 class CNLiveLoginViewController : CNLiveBaseViewController, UITextViewDelegate {
15 16  
... ... @@ -77,9 +78,20 @@ class CNLiveLoginViewController : CNLiveBaseViewController, UITextViewDelegate {
77 78 wxButton.addTarget(self, action: #selector(sendWXLoginActionMothod), for: .touchUpInside)
78 79 return wxButton
79 80 }()
  81 +
  82 + lazy var tipLabel: UILabel = {
  83 + let tipLabel = UILabel.init()
  84 + tipLabel.text = "未注册的手机号验证后自动为您创建元码账户"
  85 + tipLabel.textColor = HexColor("#464646")
  86 + tipLabel.textAlignment = .left
  87 + tipLabel.font = Font_11_Fit
  88 + return tipLabel
  89 + }()
  90 +
80 91  
81 92 var is_agree : Bool = false //是否同意协议
82   - var country : String = "86"
  93 + var countryCode: String = "86"
  94 +// var countryStr: String = "中国大陆"
83 95 var timeOut = 30//多少秒计时器
84 96  
85 97  
... ... @@ -204,22 +216,95 @@ class CNLiveLoginViewController : CNLiveBaseViewController, UITextViewDelegate {
204 216 make.left.equalTo(verView.snp.left).offset(40)
205 217 }
206 218  
207   - let tipLabel = UILabel.init()
208   - tipLabel.text = "未注册的手机号验证后自动为您创建元码账户"
209   - tipLabel.textColor = HexColor("#464646")
210   - tipLabel.textAlignment = .left
211   - tipLabel.font = Font_11_Fit
212 219 self.view.addSubview(tipLabel)
213 220 tipLabel.snp.makeConstraints { make in
214   - make.centerX.equalTo(self.view)
215   - make.left.right.equalTo(self.view).offset(40)
  221 + make.centerX.equalToSuperview()
  222 + make.width.equalTo(KSreenWidth-80)
216 223 make.top.equalTo(verView.snp.bottom).offset(10)
217 224 }
218 225 }
219 226  
220 227 @objc func sendWXLoginActionMothod() {
221   - CNLiveShareImageManager.send(CNLiveSendAuthRespWX) { resp, userInfo, error in
  228 + if !is_agree {
  229 + showMessage(message: "请先阅读并同意协议")
  230 + return
  231 + }
  232 + self.threeLogin(resp: CNLiveSendAuthRespWX)
  233 + }
  234 +
  235 + @objc func appleButtonAction(sender : UIButton) {
  236 + if !is_agree {
  237 + showMessage(message: "请先阅读并同意协议")
  238 + return
  239 + }
  240 + self.threeLogin(resp: CNLiveSendAuthRespApple)
  241 + }
  242 +
  243 + //三方登录
  244 + func threeLogin(resp:CNLiveSendAuthResp){
  245 + CNLiveShareImageManager.send(resp) { [weak self] resp, userInfo, error in
  246 + if (error != nil){
  247 + if let err = error as? NSError{
  248 +// if err.code == 1001{//苹果登录错误
  249 +// showMessage(message: "取消登录")
  250 +// return
  251 +// }
  252 + if err.code == 10000{//用户取消
  253 + showMessage(message: "取消登录")
  254 + }else{
  255 + showMessage(message: "登录失败")
  256 + }
  257 + return
  258 + }else{
  259 + showMessage(message: "登录失败")
  260 + }
  261 + return
  262 + }
  263 + if let userModel = userInfo{
  264 + let threeModel = CNThreeLoginModel()
  265 + threeModel.thirdPartyId = userModel.thirdPartyId
  266 + threeModel.nickName = userModel.nickName ?? ""
  267 + threeModel.gender = userModel.gender ?? ""
  268 + threeModel.location = userModel.location ?? ""
  269 + threeModel.faceUrl = userModel.faceUrl ?? ""
  270 + threeModel.access_token = userModel.access_token ?? ""
  271 + threeModel.refresh_token = userModel.refresh_token ?? ""
  272 + threeModel.type = CNLiveSendAuthRespWX
  273 +// threeModel.countryName = self!.countryStr
  274 + threeModel.countryCode = self!.countryCode
  275 + threeModel.frmId = "Apple"//[CNTools getFrmId]
  276 + switch resp {
  277 + case CNLiveSendAuthRespApple:
  278 + threeModel.thirdPartyPlat = "5"
  279 + break
  280 + case CNLiveSendAuthRespWX:
  281 + threeModel.thirdPartyPlat = "3"
  282 + break
  283 + default:
  284 + threeModel.thirdPartyPlat = "3"
  285 + break
  286 + }
  287 + if resp == CNLiveSendAuthRespApple{
  288 + self!.appleLogin(model: threeModel)
  289 + }else{
  290 + self!.thirdPartyLoginWithType(type: resp, model: threeModel)
  291 + }
  292 + }else{
  293 +
  294 + }
222 295  
  296 +
  297 + }
  298 + }
  299 +
  300 + func appleLogin(model:CNThreeLoginModel){
  301 + CNLiveLoginViewModel.appleLogin(model: model) { result, status in
  302 + if status == .success{
  303 + let window = UIApplication.shared.delegate?.window
  304 + window??.rootViewController = CNLiveBaseTabBarViewController.init()
  305 + }else{
  306 +
  307 + }
223 308 }
224 309 }
225 310  
... ... @@ -258,33 +343,96 @@ class CNLiveLoginViewController : CNLiveBaseViewController, UITextViewDelegate {
258 343 make.right.equalTo(view.snp.right).offset(-25)
259 344 }
260 345  
261   - view.addSubview(wxButton)
262   - wxButton.snp.makeConstraints { make in
263   - make.centerX.equalTo(view)
264   - make.bottom.equalTo(textView.snp.top).offset(-10)
265   - make.left.equalTo(40)
266   - make.right.equalTo(-40)
267   - make.height.equalTo(40)
268   - }
269 346 view.addSubview(loginButton)
270 347 loginButton.snp.makeConstraints { make in
271 348 make.centerX.equalTo(view)
272   - make.bottom.equalTo(wxButton.snp.top).offset(-10)
  349 + make.top.equalTo(tipLabel.snp.bottom).offset(adapt_length(length: 102))
273 350 make.left.equalTo(40)
274 351 make.right.equalTo(-40)
275 352 make.height.equalTo(40)
276 353 }
  354 + view.addSubview(wxButton)
  355 +
  356 + if #available(iOS 13.0, *) {
  357 + let appleButton = ASAuthorizationAppleIDButton(type: ASAuthorizationAppleIDButton.ButtonType.default, style: ASAuthorizationAppleIDButton.Style.white)
  358 + appleButton.addTarget(self, action: #selector(appleButtonAction), for: .touchUpInside)
  359 + appleButton.layer.masksToBounds = true
  360 + appleButton.layer.cornerRadius = 20
  361 + appleButton.layer.borderWidth = 1.0
  362 + appleButton.layer.borderColor = UIColor.black.cgColor
  363 + view.addSubview(appleButton)
  364 + appleButton.snp.makeConstraints { make in
  365 + make.left.equalTo(40)
  366 + make.right.equalTo(loginButton.snp.centerX).offset(-5)
  367 + make.top.equalTo(loginButton.snp.bottom).offset(15)
  368 + make.height.equalTo(loginButton.snp.height)
  369 + }
  370 +
  371 + wxButton.snp.makeConstraints { make in
  372 + make.right.equalTo(loginButton.snp.right)
  373 + make.left.equalTo(loginButton.snp.centerX).offset(5)
  374 + make.top.equalTo(loginButton.snp.bottom).offset(15)
  375 + make.height.equalTo(loginButton.snp.height)
  376 + }
  377 + } else {
  378 + // Fallback on earlier versions
  379 + wxButton.snp.makeConstraints { make in
  380 + make.centerX.equalTo(view)
  381 + make.top.equalTo(loginButton.snp.bottom).offset(15)
  382 + make.left.equalTo(40)
  383 + make.right.equalTo(-40)
  384 + make.height.equalTo(40)
  385 + }
  386 + }
277 387  
278 388 loginButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 0.3),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
279   - wxButton.setGradient(colors: [UIColor(red: 35/255.0, green: 203/255.0, blue: 105/255.0, alpha: 0.3),UIColor(red: 13/255.0, green: 179/255.0, blue: 85/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
  389 + wxButton.setGradient(colors: [UIColor(red: 35/255.0, green: 203/255.0, blue: 105/255.0, alpha: 1),UIColor(red: 13/255.0, green: 179/255.0, blue: 85/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
  390 +// wxButton.setGradient(colors: [UIColor(red: 35/255.0, green: 203/255.0, blue: 105/255.0, alpha: 0.3),UIColor(red: 13/255.0, green: 179/255.0, blue: 85/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
  391 + }
  392 +
  393 + // MARK: - 三方登录
  394 + func thirdPartyLoginWithType(type:CNLiveSendAuthResp,model:CNThreeLoginModel){
  395 + //test
  396 + let vc = CNThreeLoginViewController(model: model)
  397 + self.navigationController?.pushViewController(vc, animated: true)
  398 + return
  399 +
  400 +// showLoading(message: "")
  401 +// CNLiveLoginViewModel.thirdPartyLoginWithType(type: type, model: model) {[weak self] result, status in
  402 +// hiddenLoading()
  403 +// if status == .success{
  404 +// //登录成功
  405 +// let window = UIApplication.shared.delegate?.window
  406 +// window??.rootViewController = CNLiveBaseTabBarViewController.init()
  407 +// }else{
  408 +// if let res = result as? String{
  409 +// if res == "42013"{
  410 +// if (type == CNLiveSendAuthRespApple) {
  411 +// let window = UIApplication.shared.delegate?.window
  412 +// window??.rootViewController = CNLiveBaseTabBarViewController.init()
  413 +// return
  414 +// }
  415 +//
  416 +// //未注册,需要绑定手机号
  417 +// //跳转绑定手机号页面
  418 +// let vc = CNThreeLoginViewController(model: model)
  419 +//
  420 +// self!.navigationController?.pushViewController(vc, animated: true)
  421 +// }
  422 +// }else{
  423 +//
  424 +// }
  425 +// }
  426 +// }
280 427 }
  428 +
281 429 }
282 430  
283 431 extension CNLiveLoginViewController {
284 432  
285 433 @objc func changeCityNumberMothod(sender : UIButton) {
286 434 CNLiveLoginPickerView.showSelectView { [weak self] text in
287   - self!.country = text
  435 + self!.countryCode = text
288 436 self!.areaButton.setTitle("+\(text)", for: .normal)
289 437 self!.areaButton.setTitle("+\(text)", for: .highlighted)
290 438 }
... ... @@ -292,7 +440,7 @@ extension CNLiveLoginViewController {
292 440  
293 441 @objc func sendVerifiCodeMothod(sender : UIButton) {
294 442 view.endEditing(true)
295   - CNLiveLoginViewModel.requestVerCodeAction(phone: phoneText.text ?? "", code: country) { [weak self] in
  443 + CNLiveLoginViewModel.requestVerCodeAction(phone: phoneText.text ?? "", code: countryCode) { [weak self] in
296 444 self!.setupCountdownAction(sender: sender)
297 445 }
298 446 }
... ... @@ -305,7 +453,7 @@ extension CNLiveLoginViewController {
305 453 wxButton.setGradient(colors: [UIColor(red: 35/255.0, green: 203/255.0, blue: 105/255.0, alpha: 1),UIColor(red: 13/255.0, green: 179/255.0, blue: 85/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
306 454 } else {
307 455 loginButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 0.3),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
308   - wxButton.setGradient(colors: [UIColor(red: 35/255.0, green: 203/255.0, blue: 105/255.0, alpha: 0.3),UIColor(red: 13/255.0, green: 179/255.0, blue: 85/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
  456 +// wxButton.setGradient(colors: [UIColor(red: 35/255.0, green: 203/255.0, blue: 105/255.0, alpha: 0.3),UIColor(red: 13/255.0, green: 179/255.0, blue: 85/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
309 457 }
310 458 }
311 459  
... ... @@ -317,7 +465,7 @@ extension CNLiveLoginViewController {
317 465 view.endEditing(true)
318 466 loginButton.startAnimating()
319 467  
320   - CNLiveLoginViewModel.requestLoginAction(userName: phoneText.text ?? "", countryCode: country, verCode: veriText.text ?? "") {[self] in
  468 + CNLiveLoginViewModel.requestLoginAction(userName: phoneText.text ?? "", countryCode: countryCode, verCode: veriText.text ?? "") {[self] in
321 469 loginButton.stopAnimating()
322 470 let window = UIApplication.shared.delegate?.window
323 471 window??.rootViewController = CNLiveBaseTabBarViewController.init()
... ...
metaCode/Classes/Main/LoginPage/Controller/CNThreeLoginViewController.swift 0 → 100644
  1 +//
  2 +// CNThreeLoginViewController.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2024/4/25.
  6 +// 三方登录绑定手机号页
  7 +
  8 +import Foundation
  9 +import APButton
  10 +import SnapKit
  11 +
  12 +class CNThreeLoginViewController:CNLiveBaseViewController{
  13 +
  14 + lazy var bindingTitleLabel: UILabel = {
  15 + let label = UILabel()
  16 + let attrString = NSMutableAttributedString(string: "绑定您的手机号")
  17 + label.frame = CGRect(x: 45, y: 150, width: 182, height: 36.5)
  18 + label.numberOfLines = 0
  19 + let attr: [NSAttributedString.Key : Any] = [.font: BoldFont(26) ,.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)]
  20 + attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
  21 + label.attributedText = attrString
  22 + return label
  23 + }()
  24 +
  25 +
  26 + lazy var headerView : UIView = {
  27 + let layerView = UIView()
  28 + layerView.frame = CGRect(x: 0, y: 0, width: KSreenWidth, height: 427.5*KSreenWidth/375)
  29 + // fillCode
  30 + let bgLayer1 = CAGradientLayer()
  31 + bgLayer1.colors = [UIColor(red: 0.91, green: 0.94, blue: 1, alpha: 1).cgColor, UIColor(red: 1, green: 1, blue: 1, alpha: 1).cgColor]
  32 + bgLayer1.locations = [0, 1]
  33 + bgLayer1.frame = layerView.bounds
  34 + bgLayer1.startPoint = CGPoint(x: 0.5, y: 0)
  35 + bgLayer1.endPoint = CGPoint(x: 1, y: 1)
  36 + layerView.layer.addSublayer(bgLayer1)
  37 + return layerView
  38 + }()
  39 +
  40 + lazy var areaButton : UIButton = {
  41 + let areaButton = UIButton(type: .custom)
  42 + areaButton.backgroundColor = .white
  43 + areaButton.setTitle("+86", for: .normal)
  44 + areaButton.setTitle("+86", for: .highlighted)
  45 + areaButton.titleLabel?.font = BoldFont_16
  46 + areaButton.setTitleColor(HexColor("#333333"), for: .normal)
  47 + areaButton.setTitleColor(HexColor("#333333"), for: .highlighted)
  48 + areaButton.addTarget(self, action: #selector(changeCityNumberMothod), for: .touchUpInside)
  49 + return areaButton
  50 + }()
  51 +
  52 + lazy var phoneText : UITextField = {
  53 + let phoneText = UITextField.init()
  54 + phoneText.backgroundColor = .white
  55 + phoneText.placeholder = "输入手机号"
  56 + phoneText.font = BoldFont_16_Fit
  57 + phoneText.keyboardType = .numberPad
  58 + phoneText.clearButtonMode = .whileEditing
  59 + return phoneText
  60 + }()
  61 +
  62 + lazy var veriText: UITextField = {
  63 + let veriText = UITextField.init()
  64 + veriText.backgroundColor = .white
  65 + veriText.placeholder = "输入验证码"
  66 + veriText.font = BoldFont_16_Fit
  67 + veriText.keyboardType = .numberPad
  68 + veriText.clearButtonMode = .whileEditing
  69 + return veriText
  70 + }()
  71 +
  72 + lazy var loginButton: APButton = {
  73 + let loginButton = APButton()
  74 + loginButton.setTitle("绑 定", for: .normal)
  75 + loginButton.setTitleColor(.white, for: .normal)
  76 + loginButton.titleLabel?.font = BoldFont_16_Fit
  77 + loginButton.layer.cornerRadius = 20
  78 + loginButton.activityIndicator.color = .white
  79 + loginButton.layer.masksToBounds = true
  80 + loginButton.addTarget(self, action: #selector(sendLoginActionMothod), for: .touchUpInside)
  81 + return loginButton
  82 + }()
  83 +
  84 + var countryCode: String = "86"
  85 + var timeOut = 30//多少秒计时器
  86 + var model:CNThreeLoginModel?
  87 +
  88 + init(model:CNThreeLoginModel) {
  89 + super.init(nibName: nil, bundle: nil)
  90 + self.model = model
  91 + }
  92 +
  93 + required init?(coder: NSCoder) {
  94 + fatalError("init(coder:) has not been implemented")
  95 + }
  96 +
  97 + override func viewDidLoad() {
  98 + super.viewDidLoad()
  99 + setNeedsStatusBarAppearanceUpdate()
  100 + view.backgroundColor = .white
  101 + navigationBarHidden = false
  102 +
  103 + //添加主视图
  104 + self.view.addSubview(self.headerView)
  105 + self.view.sendSubviewToBack(self.headerView)
  106 + self.headerView.snp.makeConstraints { make in
  107 + make.centerX.equalTo(self.view)
  108 + make.left.right.equalTo(self.view)
  109 + make.top.equalTo(KNavigationHeight)
  110 + make.height.equalTo(427.5*KSreenWidth/375)
  111 + }
  112 +
  113 + self.view.addSubview(self.bindingTitleLabel)
  114 + self.bindingTitleLabel.snp.makeConstraints { make in
  115 + make.left.equalToSuperview().offset(45)
  116 + make.top.equalTo(KNavigationHeight+adapt_length(length: 100))
  117 + make.width.equalTo(KSreenWidth-90)
  118 + make.height.equalTo(40)
  119 + }
  120 +
  121 + self.setupPhoneView()
  122 + self.setupVeriCodeView()
  123 + self.setupLoginButtonView()
  124 + }
  125 +
  126 + deinit {
  127 + print("已经销毁了")
  128 + }
  129 +
  130 + override var preferredStatusBarStyle: UIStatusBarStyle {
  131 + return .lightContent
  132 + }
  133 +
  134 + func setupPhoneView() {
  135 +
  136 + let phoneV = UIView.init()
  137 + phoneV.backgroundColor = .white
  138 + view.addSubview(phoneV)
  139 + phoneV.snp.makeConstraints { make in
  140 + make.left.right.equalToSuperview()
  141 + make.top.equalTo(self.bindingTitleLabel.snp.bottom).offset(adapt_length(length: 60))
  142 + make.height.equalTo(50)
  143 + }
  144 +
  145 + phoneV.addSubview(areaButton)
  146 + areaButton.snp.makeConstraints { make in
  147 + make.centerY.equalTo(phoneV)
  148 + make.left.equalTo(phoneV.left).offset(40)
  149 + make.width.lessThanOrEqualTo(50)
  150 + }
  151 +
  152 + let v_line = UILabel.init()
  153 + v_line.backgroundColor = HexColor("#EBEBEB")
  154 + phoneV.addSubview(v_line)
  155 + v_line.snp.makeConstraints { make in
  156 + make.centerY.equalTo(phoneV)
  157 + make.left.equalTo(areaButton.snp.right).offset(10)
  158 + make.width.equalTo(1)
  159 + make.height.equalTo(areaButton.snp.height).multipliedBy(0.35)
  160 + }
  161 +
  162 + let h_line = UILabel.init()
  163 + h_line.backgroundColor = HexColor("#EBEBEB")
  164 + phoneV.addSubview(h_line)
  165 + h_line.snp.makeConstraints { make in
  166 + make.left.equalTo(phoneV.left).offset(40)
  167 + make.right.equalTo(phoneV.right).offset(-40)
  168 + make.height.equalTo(v_line.snp.width)
  169 + make.bottom.equalTo(phoneV.snp.bottom).offset(-1)
  170 + }
  171 +
  172 + phoneV.addSubview(phoneText)
  173 + phoneText.snp.makeConstraints { make in
  174 + make.centerY.equalTo(phoneV)
  175 + make.left.equalTo(areaButton.snp.right).offset(21)
  176 + make.height.equalTo(areaButton.snp.height)
  177 + make.right.equalTo(phoneV.right).offset(-40)
  178 + }
  179 + }
  180 +
  181 + func setupVeriCodeView() {
  182 +
  183 + let verView = UIView.init()
  184 + verView.backgroundColor = .white
  185 + self.view.addSubview(verView)
  186 + verView.snp.makeConstraints { make in
  187 + make.left.right.equalTo(self.view)
  188 + make.top.equalTo(self.phoneText.snp.bottom).offset(adapt_length(length: 40))
  189 + make.height.equalTo(50)
  190 + }
  191 +
  192 + let h_line = UILabel.init()
  193 + h_line.backgroundColor = HexColor("#EBEBEB")
  194 + verView.addSubview(h_line)
  195 + h_line.snp.makeConstraints { make in
  196 + make.left.equalTo(verView.left).offset(40)
  197 + make.right.equalTo(verView.right).offset(-40)
  198 + make.height.equalTo(1)
  199 + make.bottom.equalTo(verView.snp.bottom).offset(-1)
  200 + }
  201 +
  202 + let codeButton = UIButton(type: .custom)
  203 + codeButton.backgroundColor = .white
  204 + codeButton.setTitle("获取验证码", for: .normal)
  205 + codeButton.setTitle("获取验证码", for: .highlighted)
  206 + codeButton.titleLabel?.font = Font_16
  207 + codeButton.setTitleColor(HexColor("#0066FE"), for: .normal)
  208 + codeButton.setTitleColor(HexColor("#0066FE"), for: .highlighted)
  209 + codeButton.addTarget(self, action: #selector(sendVerifiCodeMothod), for: .touchUpInside)
  210 + verView.addSubview(codeButton)
  211 + codeButton.snp.makeConstraints { make in
  212 + make.centerY.equalTo(verView)
  213 + make.right.equalTo(verView.snp.right).offset(-40)
  214 + make.width.lessThanOrEqualTo(100)
  215 + }
  216 +
  217 + verView.addSubview(veriText)
  218 + veriText.snp.makeConstraints { make in
  219 + make.centerY.equalTo(verView)
  220 + make.right.equalTo(codeButton.snp.left).offset(-20)
  221 + make.height.equalTo(codeButton.snp.height)
  222 + make.left.equalTo(verView.snp.left).offset(40)
  223 + }
  224 + }
  225 + func setupLoginButtonView() {
  226 +
  227 + view.addSubview(loginButton)
  228 + loginButton.snp.makeConstraints { make in
  229 + make.centerX.equalTo(view)
  230 + make.top.equalTo(veriText.snp.bottom).offset(adapt_length(length: 105))
  231 + make.left.equalTo(40)
  232 + make.right.equalTo(-40)
  233 + make.height.equalTo(40)
  234 + }
  235 +
  236 + loginButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
  237 +
  238 + }
  239 +
  240 + @objc func changeCityNumberMothod(sender : UIButton) {
  241 + CNLiveLoginPickerView.showSelectView { [weak self] text in
  242 + self!.countryCode = text
  243 + self!.areaButton.setTitle("+\(text)", for: .normal)
  244 + self!.areaButton.setTitle("+\(text)", for: .highlighted)
  245 + }
  246 + }
  247 +
  248 + @objc func sendVerifiCodeMothod(sender : UIButton) {
  249 + view.endEditing(true)
  250 + CNLiveLoginViewModel.requestVerCodeAction(phone: phoneText.text ?? "", code: countryCode) { [weak self] in
  251 + self!.setupCountdownAction(sender: sender)
  252 + }
  253 + }
  254 +
  255 + @objc func sendLoginActionMothod(sender : UIButton) {
  256 + view.endEditing(true)
  257 + if phoneText.text ?? "" == ""{
  258 + showMessage(message: "请输入手机号")
  259 + return
  260 + }
  261 + if veriText.text ?? "" == ""{
  262 + showMessage(message: "请输入验证码")
  263 + return
  264 + }
  265 + showLoading(message: "")
  266 + // 绑定手机号请求登录
  267 + CNLiveLoginViewModel.thirdPartyLoginBindingTel(mobile: phoneText.text ?? "", verificationCode: veriText.text ?? "", model: self.model!) { result, status in
  268 + hiddenLoading()
  269 + if status == .success{
  270 + let window = UIApplication.shared.delegate?.window
  271 + window??.rootViewController = CNLiveBaseTabBarViewController.init()
  272 + }
  273 + }
  274 +
  275 +
  276 +
  277 + }
  278 +
  279 + /// 设置发送验证码按钮
  280 + /// - Parameter sender: 按钮
  281 + private func setupCountdownAction(sender : UIButton) {
  282 + var timeOut = self.timeOut
  283 + let queue: DispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default)
  284 + let _timer: DispatchSource = DispatchSource.makeTimerSource(flags: [], queue: queue) as! DispatchSource
  285 + _timer.schedule(wallDeadline: DispatchWallTime.now(), repeating: .seconds(1))
  286 + //一秒执行
  287 + _timer.setEventHandler(handler: { () -> Void in
  288 + if timeOut <= 0 {
  289 + _timer.cancel()
  290 + DispatchQueue.main.sync(execute: { () -> Void in
  291 + sender.setTitle("获取验证码", for: .normal)
  292 + sender.isEnabled = true
  293 + })
  294 + } else {
  295 + let seconds = timeOut
  296 + DispatchQueue.main.sync(execute: {() -> Void in
  297 + let str = String(describing: seconds)
  298 + sender.setTitle("\(str)s重新获取", for: .normal)
  299 + sender.isEnabled = false
  300 + })
  301 + timeOut -= 1
  302 + }
  303 + })
  304 + _timer.resume()
  305 + }
  306 +
  307 +}
... ...
metaCode/Classes/Main/LoginPage/Model/CNThreeLoginModel.swift 0 → 100644
  1 +//
  2 +// CNThreeLoginModel.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2024/4/24.
  6 +//
  7 +
  8 +import Foundation
  9 +import CNLiveShareToolKit
  10 +
  11 +class CNThreeLoginModel:BaseModel{
  12 +
  13 +
  14 + /*
  15 + mobile true string 手机号
  16 + countryCode true string 手机号国家码;中国为86
  17 + verificationCode true string 手机验证码
  18 + thirdPartyPlat true int 第三方平台编号 [platform : 1:sina 2:qq 3:weixin 4:renren]
  19 + thirdPartyId true string 第三方用户ID
  20 + [qq: 建议使用openid, wx: 建议使用unionid, sina: 建议使用idstr];
  21 + 注意:同一用户在登录Sp下不同app时,thirdPartyId必须相同
  22 +
  23 + frmId true string 渠道ID
  24 + clientPlat true string 客户端平台[i:IOS客户端,a:Android客户端, w: 网页]
  25 + nickName true string 用户昵称
  26 + gender false string 性别,m:男、f:女、n:未知
  27 + location false string 用户所在地
  28 + faceUrl false string 头像,约100*100
  29 + */
  30 + var countryName = ""
  31 + var countryCode = ""
  32 + var thirdPartyPlat = ""
  33 + var thirdPartyId = ""
  34 + var frmId = ""
  35 + var nickName = ""
  36 + var gender = ""
  37 + var location = ""
  38 + var faceUrl = ""
  39 + var access_token = ""
  40 + var refresh_token = ""
  41 + var type:CNLiveSendAuthResp = CNLiveSendAuthRespWX
  42 +}
... ...
metaCode/Classes/Main/LoginPage/View/CNLiveLoginPickerView.swift
... ... @@ -179,6 +179,11 @@ extension CNLiveLoginPickerView {
179 179  
180 180 @objc func setupDoneButtonAction(){
181 181 if let resutBlock = resutBlock {
  182 + if result_string == ""{
  183 + let param = country_array[0] as! NSDictionary
  184 + let code = param["code"] as? String
  185 + result_string = code ?? ""
  186 + }
182 187 resutBlock(result_string)
183 188 }
184 189 disMissView()
... ...
metaCode/Classes/Main/LoginPage/ViewModel/CNLiveLoginViewModel.swift
... ... @@ -9,6 +9,8 @@ import Foundation
9 9 import CNLiveRequestBastKit
10 10 import HandyJSON
11 11 import RangersAPM
  12 +import CNLiveShareToolKit
  13 +import CNLiveBusinessTools
12 14  
13 15 //验证码发送成功回调
14 16 typealias resultCodeBlock = () -> Void
... ... @@ -137,4 +139,133 @@ class CNLiveLoginViewModel : NSObject {
137 139 }
138 140 }
139 141 }
  142 +
  143 + /**
  144 + * @abstract 三方登录
  145 + *
  146 + * @param type 三方类型
  147 + * @param model 模型
  148 + * @param block 回调
  149 + */
  150 + static func thirdPartyLoginWithType(type: CNLiveSendAuthResp, model: CNThreeLoginModel, resultBlock: @escaping downSlideResultBlock) {
  151 + showLoading(message: "")
  152 +
  153 + let param = ["thirdPartyPlat":model.thirdPartyPlat,"thirdPartyId":model.thirdPartyId,"frmId":model.frmId,"clientPlat":"i"]
  154 + let custom_param = NSMutableDictionary()
  155 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
  156 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
  157 + CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
  158 + CNLiveNetworking.setAllowRequestDefaultArgument(true)
  159 + CNLiveNetworking.setupShowDataResult(false)
  160 + CNLiveNetworking.requestNetwork(with: .POST, urlString: APPLoginHost+"/open/api2/user/loginIn3rdForMetaCode", param: param, cacheType: .networkOnly) { task, result, error in
  161 + hiddenLoading()
  162 + if (error == nil) {
  163 + let resp = result as! NSDictionary
  164 + let errorCode = resp["errorCode"]
  165 + if (errorCode as! String == "0") {
  166 + if resp.allKeys.contains(where: { item in
  167 + return item as! String == "data"
  168 + }) {
  169 + let userInfoModel = dictionaryToModel(resp as! [String : Any], UserInfoModel.self,"data")
  170 + UserInfoManager.cacheUserInfo(userInfo: userInfoModel as! UserInfoModel)
  171 + UserDefaults.standard.set(true,forKey: "is_login")
  172 + RangersAPM.setUserID(UserInfoManager.shared.userInfo.uid)
  173 + resultBlock(userInfoModel, .success)
  174 + }
  175 + } else {
  176 + showMessage(message: resp["errorMessage"] as! String)
  177 + if errorCode as? String == "42013"{
  178 + resultBlock(errorCode ?? "", .failed)
  179 + }else{
  180 + resultBlock(NSNull(), .failed)
  181 + }
  182 + }
  183 + } else {
  184 + showMessage(message: "登录失败")
  185 + resultBlock(NSNull(), .failed)
  186 + }
  187 + }
  188 + }
  189 +
  190 + /**
  191 + * @abstract 绑定手机号请求登录
  192 + *
  193 + * @param block 回调
  194 + */
  195 + static func thirdPartyLoginBindingTel(mobile: String,verificationCode:String, model: CNThreeLoginModel, resultBlock: @escaping downSlideResultBlock) {
  196 + showLoading(message: "")
  197 +
  198 + let param = ["mobile":mobile,"countryCode":model.countryCode,"verificationCode":verificationCode,"thirdPartyPlat":model.thirdPartyPlat,"thirdPartyId":model.thirdPartyId,"frmId":model.frmId,"clientPlat":"i","nickName":model.nickName,"gender":model.gender,"location":model.location,"faceUrl":model.faceUrl]
  199 + let custom_param = NSMutableDictionary()
  200 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
  201 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
  202 + CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
  203 + CNLiveNetworking.setAllowRequestDefaultArgument(true)
  204 + CNLiveNetworking.setupShowDataResult(false)
  205 + CNLiveNetworking.requestNetwork(with: .POST, urlString: APPLoginHost+"/open/api2/user/loginIn3rdAndMobileForMetaCode", param: param, cacheType: .networkOnly) { task, result, error in
  206 + hiddenLoading()
  207 + if (error == nil) {
  208 + let resp = result as! NSDictionary
  209 + let errorCode = resp["errorCode"]
  210 + if (errorCode as! String == "0") {
  211 + if resp.allKeys.contains(where: { item in
  212 + return item as! String == "data"
  213 + }) {
  214 + let userInfoModel = dictionaryToModel(resp as! [String : Any], UserInfoModel.self,"data")
  215 + UserInfoManager.cacheUserInfo(userInfo: userInfoModel as! UserInfoModel)
  216 + UserDefaults.standard.set(true,forKey: "is_login")
  217 + RangersAPM.setUserID(UserInfoManager.shared.userInfo.uid)
  218 + resultBlock(userInfoModel, .success)
  219 + }
  220 + } else {
  221 + showMessage(message: resp["errorMessage"] as! String)
  222 + resultBlock(NSNull(), .failed)
  223 + }
  224 + } else {
  225 + showMessage(message: "登录失败")
  226 + resultBlock(NSNull(), .failed)
  227 + }
  228 + }
  229 + }
  230 +
  231 + /**
  232 + * @abstract 苹果登录
  233 + *
  234 + * @param block 回调
  235 + */
  236 + static func appleLogin(model: CNThreeLoginModel, resultBlock: @escaping downSlideResultBlock) {
  237 + showLoading(message: "")
  238 +
  239 + let param = ["thirdPartyPlat":model.thirdPartyPlat,"thirdPartyId":model.thirdPartyId,"frmId":model.frmId,"clientPlat":"i","nickName":model.nickName,"gender":model.gender,"location":model.location,"faceUrl":model.faceUrl,"uuid": CNLiveBusinessTools.getUidForStat(Date()),"accessToken":model.access_token,"appId":CNLiveMCEnvironmentManager.shared.appId]
  240 + let custom_param = NSMutableDictionary()
  241 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
  242 + custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
  243 + CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
  244 + CNLiveNetworking.setAllowRequestDefaultArgument(true)
  245 + CNLiveNetworking.setupShowDataResult(false)
  246 + CNLiveNetworking.requestNetwork(with: .POST, urlString: APPLoginHost+"/open/api2/user/loginIn3rdForMetaCodeApple", param: param, cacheType: .networkOnly) { task, result, error in
  247 + hiddenLoading()
  248 + if (error == nil) {
  249 + let resp = result as! NSDictionary
  250 + let errorCode = resp["errorCode"]
  251 + if (errorCode as! String == "0") {
  252 + if resp.allKeys.contains(where: { item in
  253 + return item as! String == "data"
  254 + }) {
  255 + let userInfoModel = dictionaryToModel(resp as! [String : Any], UserInfoModel.self,"data")
  256 + UserInfoManager.cacheUserInfo(userInfo: userInfoModel as! UserInfoModel)
  257 + UserDefaults.standard.set(true,forKey: "is_login")
  258 + RangersAPM.setUserID(UserInfoManager.shared.userInfo.uid)
  259 + resultBlock(userInfoModel, .success)
  260 + }
  261 + } else {
  262 + showMessage(message: resp["errorMessage"] as! String)
  263 + resultBlock(NSNull(), .failed)
  264 + }
  265 + } else {
  266 + showMessage(message: "登录失败")
  267 + resultBlock(NSNull(), .failed)
  268 + }
  269 + }
  270 + }
140 271 }
... ...
metaCode/Classes/Other/AppDelegate.swift
... ... @@ -49,7 +49,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
49 49 window = UIWindow.init(frame: UIScreen.main.bounds)
50 50 window?.backgroundColor = KVCBackgroupColor
51 51 let is_login = UserDefaults.standard.bool(forKey: "is_login")
52   - window?.rootViewController = is_login ? CNLiveBaseTabBarViewController.init() : CNLiveLoginViewController.init()
  52 + window?.rootViewController = is_login ? CNLiveBaseTabBarViewController.init() : UINavigationController(rootViewController: CNLiveLoginViewController.init())
53 53 window?.makeKeyAndVisible()
54 54  
55 55 ///设置APM监控SDK
... ...