Commit e70fb8e5 authored by Steven杜宇's avatar Steven杜宇

// 一键登录

parent d14e52d9
......@@ -12,7 +12,9 @@ import AuthenticationServices
class YHAppleLoginManager: NSObject {
static let shared = YHAppleLoginManager()
let viewModel = YHAppleLoginViewModel()
func appleLogin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
......@@ -29,27 +31,65 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
var userId = ""
var email = ""
var fullName = ""
var authorizationCodeStr = ""
var identityTokenStr = ""
// 其中`authorization.credential`包含了Token,用户ID等授权所需信息,可上报到后台
let credential = authorization.credential
if credential is ASPasswordCredential {
let passwdCredential = credential as! ASPasswordCredential
let userIdentifier = passwdCredential.user
userId = passwdCredential.user
let username = passwdCredential.user
let password = passwdCredential.password
printLog("username:\(username), passwd:\(password)")
} else if credential is ASAuthorizationAppleIDCredential {
let appleIdCredential = credential as! ASAuthorizationAppleIDCredential
let userIdentifier = appleIdCredential.user
let fullName = appleIdCredential.fullName
let email = appleIdCredential.email ?? "email"
userId = appleIdCredential.user
email = appleIdCredential.email ?? ""
let authorizationCode = appleIdCredential.authorizationCode
let authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self)
authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self)
let identityToken = appleIdCredential.identityToken
let identityTokenStr = String(decoding: identityToken!, as: UTF8.self)
identityTokenStr = String(decoding: identityToken!, as: UTF8.self)
let realUserStatus = appleIdCredential.realUserStatus
printLog("authorizationCodeStr: \(authorizationCodeStr)")
}
printLog("APPLE LOGIN userId:\(userId)")
printLog("APPLE LOGIN identityToken:\(identityTokenStr)")
printLog("APPLE LOGIN authorizationCode: \(authorizationCodeStr)")
let parmas:[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
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)
}
}
}
......
......@@ -10,7 +10,7 @@ import UIKit
class YHAppleLoginViewModel: NSObject {
func appleLogin(params:[String: Any], callBackBlock: @escaping (_ success: Bool,_ error: YHErrorModel?)->()) {
func appleLogin(params:[String: Any], _ callBackBlock: @escaping (_ success: Bool,_ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Auth.appleLogin
let _ = YHNetRequest.postRequest(url: strUrl, params: params) {[weak self] json, code in
......
......@@ -12,7 +12,7 @@ import AVFoundation
class YHOneKeyLoginManager {
static let shared = YHOneKeyLoginManager()
let viewModel = YHOneKeyLoginViewModel()
}
extension YHOneKeyLoginManager {
......@@ -56,7 +56,7 @@ extension YHOneKeyLoginManager {
printLog("设置secretKey结果:\(dict)")
// 进行加速登录 方便点击登录时提速
TXCommonHandler.sharedInstance().accelerateLoginPage(withTimeout: 10.0) {
TXCommonHandler.sharedInstance().accelerateLoginPage(withTimeout: 5.0) {
dic in
printLog("加速登录结果: \(dic)")
}
......@@ -85,7 +85,7 @@ extension YHOneKeyLoginManager {
let model = self.createLoginUIModel()
YHHUD.show(.progress(message: "加载中..."))
TXCommonHandler.sharedInstance().getLoginToken(withTimeout: 3.0, controller: UIViewController.current!, model: model) {
TXCommonHandler.sharedInstance().getLoginToken(withTimeout: 5.0, controller: UIViewController.current!, model: model) {
dict in
DispatchQueue.main.async {
......@@ -106,6 +106,35 @@ extension YHOneKeyLoginManager {
}
printLog("oneKeyLogin token: \(token)")
// 下面用Token去服务器换手机号,此处仅做参考
YHHUD.show(.progress(message: "登录中..."))
self.viewModel.oneKeyLogin(authToken: token) {
success, error in
DispatchQueue.main.async {
YHHUD.hide()
}
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)
}
}
/*
[PNSVerifyTopRequest requestLoginWithToken:token complete:^(BOOL isSuccess, NSString * _Nonnull msg, NSDictionary * _Nonnull data) {
......
......@@ -14,8 +14,8 @@ class YHOneKeyLoginViewModel {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Auth.oneKeySecretKeyInfo
let params = ["iosInfo.bundleId" : "com.intelligence.galaxy"]
let _ = YHNetRequest.getRequest(url: strUrl, params: params) { json, code in
let dic = json.data
let _ = YHNetRequest.getRequest(url: strUrl, params: params) {
json, code in
printLog("model 是 ==> \(json)")
if json.code == 200 {
if let dic = json.data as? [String: Any], let sdkKey = dic["sdkKey"] as? String, !sdkKey.isEmpty {
......@@ -38,9 +38,9 @@ class YHOneKeyLoginViewModel {
let params: [String : Any] = ["auth_token": authToken]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Auth.oneKeyLogin
let _ = YHNetRequest.postRequest(url: strUrl, params: params) {[weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
let _ = YHNetRequest.postRequest(url: strUrl, params: params) {
json, code in
printLog(json)
let dic = json.data
guard let resultModel = YHUserModel.deserialize(dict: dic as? [AnyHashable : Any]) else {
......
......@@ -275,7 +275,6 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
//#endif
if !checkLogin() {
YHOneKeyLoginManager.shared.oneKeyLogin()
return
}
......
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