Commit 1c7cc75d authored by Steven杜宇's avatar Steven杜宇

一键登录和苹果登录接口调用

parent 6dca44b7
......@@ -14,6 +14,7 @@ class YHAppleLoginManager: NSObject {
static let shared = YHAppleLoginManager()
let viewModel = YHAppleLoginViewModel()
var success: (([String: Any]) ->())?
func appleLogin() {
......@@ -61,36 +62,14 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio
printLog("APPLE LOGIN identityToken:\(identityTokenStr)")
printLog("APPLE LOGIN authorizationCode: \(authorizationCodeStr)")
let parmas:[String: Any] = ["apple_id": "string",
let params:[String: Any] = ["apple_id": "string",
"user_id": userId,
"email": "string",
"full_name": "string",
"authorization_code": authorizationCodeStr,
"identity_token": identityTokenStr,
"mobile": "",
"sms_code": ""]
self.viewModel.appleLogin(params: parmas) {
success, error in
"identity_token": identityTokenStr]
if success {
return
}
if let err = error {
// 首次登录,没有传电话号码和验证码返回错误码:30001
if err.errorCode == 30001 {
return
}
var msg = err.errorMsg
if msg.isEmpty {
msg = "登录失败"
}
YHHUD.flash(message: msg)
}
}
self.success?(params)
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
......
......@@ -120,17 +120,10 @@ extension YHOneKeyLoginManager {
return
}
if let err = error {
// 首次登录,没有传电话号码和验证码返回错误码:30001
// if err.errorCode == 30001 {
//
// return
// }
var msg = err.errorMsg
if msg.isEmpty {
msg = "登录失败"
}
YHHUD.flash(message: msg)
}
......
......@@ -21,7 +21,9 @@ class YHCodeSueecssViewController: YHBaseViewController {
var phoneNumber: String?
var type: YHLoginType = .phone
var viewModel: YHLoginViewModel?
let appleLoginViewModel = YHAppleLoginViewModel()
var token: String = ""
var appleLoginParams: [String : Any] = [:]
override func viewDidLoad() {
super.viewDidLoad()
......@@ -168,6 +170,23 @@ class YHCodeSueecssViewController: YHBaseViewController {
if type == .apple {
//苹果登录逻辑
var params = self.appleLoginParams
params["sms_code"] = code
params["mobile"] = phone
printLog("Apple login parmas: \(params)")
YHHUD.show(.progress(message: ""))
self.appleLoginViewModel.appleLogin(params: params) { success, error in
YHHUD.hide()
if success == false {
YHHUD.flash(message: error?.errorMsg ?? "")
} else {
YHLoginManager.shared.loginSuccessActionBlock?()
YHHUD.flash(message: "登录成功")
TXCommonHandler.sharedInstance().cancelLoginVC(animated: true)
self.dismiss(animated: true)
self.navigationController?.popToRootViewController(animated: true)
}
}
}
}
......
......@@ -33,8 +33,10 @@ class YHOtherLoginViewController: YHBaseViewController {
var appleButton: UIButton!
var privacyView: YHLoginPrivacyView!
var viewModel: YHLoginViewModel!
let appleLoginViewModel = YHAppleLoginViewModel()
var type: YHLoginType = .phone
var token: String = ""
var appleLoginParams: [String : Any] = [:]
override func viewDidLoad() {
super.viewDidLoad()
......@@ -310,6 +312,7 @@ class YHOtherLoginViewController: YHBaseViewController {
vc.phoneNumber = self.phoneMessageView.phoneTextField.text
vc.type = self.type
vc.token = self.token
vc.appleLoginParams = self.appleLoginParams
self.navigationController?.pushViewController(vc)
} else {
var msg = error?.errorMsg ?? ""
......@@ -356,6 +359,43 @@ class YHOtherLoginViewController: YHBaseViewController {
// vc.type = .apple
// navigationController?.pushViewController(vc)
YHAppleLoginManager.shared.success = {
dict in
YHHUD.flash(message: "登录中...")
self.appleLoginViewModel.appleLogin(params: dict) {
success, error in
YHHUD.hide()
if success {
YHLoginManager.shared.loginSuccessActionBlock?()
YHHUD.flash(message: "登录成功")
self.dismiss(animated: true)
TXCommonHandler.sharedInstance().cancelLoginVC(animated: true)
self.navigationController?.popToRootViewController(animated: true)
return
}
if let err = error {
var msg = err.errorMsg
if msg.isEmpty {
msg = "登录失败"
}
YHHUD.flash(message: msg)
if err.errorCode == 30001 {
// 首次登录,没有传电话号码和验证码返回错误码:30001
// 进入手机绑定页面
let bindVC = YHOtherLoginViewController()
bindVC.type = .apple
bindVC.appleLoginParams = dict
UIViewController.current?.navigationController?.pushViewController(bindVC)
return
}
}
}
}
YHAppleLoginManager.shared.appleLogin()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment