Explorar el Código

feat:三方登录

“wangdongchao” hace 1 año
padre
commit
523122c9e9

+ 73 - 20
Asteria/Fuction/Login/V/LoginThirdAuthV.m

@@ -106,11 +106,26 @@
 - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(nonnull ASAuthorization *)authorization API_AVAILABLE(ios(13.0)){
 - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(nonnull ASAuthorization *)authorization API_AVAILABLE(ios(13.0)){
     if([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]){
     if([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]){
         ASAuthorizationAppleIDCredential *credential = (ASAuthorizationAppleIDCredential *)authorization.credential;
         ASAuthorizationAppleIDCredential *credential = (ASAuthorizationAppleIDCredential *)authorization.credential;
-        NSString *user = credential.user;
-        NSString *email = credential.email;
 
 
-        NSData *identityToken = credential.identityToken;
-        NSLog(@"user - %@ --- %@--%@",user,email,identityToken);
+        NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding];
+        
+        NSMutableDictionary *paramsDic= [NSMutableDictionary dictionary];
+        NSDictionary *userInfo = @{@"identifier":AS_String_NotNull(credential.user) ,
+                                   @"email":AS_String_NotNull(credential.email),
+                                   @"firstName":AS_String_NotNull(credential.fullName.familyName),
+                                   @"lastName":AS_String_NotNull(credential.fullName.givenName),
+                                   @"displayName":@""};
+        
+        NSString *userInfoStr = [userInfo mj_JSONString];
+        
+        [paramsDic setObject:userInfoStr forKey:@"userInfo"];
+        [paramsDic setObject:@"apple" forKey:@"hauth_done"];
+        [paramsDic setObject:identityToken forKey:@"token"];
+        
+        
+        NSLog(@"paramsDic----%@",paramsDic);
+        [self generaltriggermethodType:ThirdTypeApple data:paramsDic];
+        
     }else if([authorization.credential isKindOfClass:[ASPasswordCredential class]]){
     }else if([authorization.credential isKindOfClass:[ASPasswordCredential class]]){
         ASPasswordCredential *psdCredential = (ASPasswordCredential *)authorization.credential;
         ASPasswordCredential *psdCredential = (ASPasswordCredential *)authorization.credential;
         // 密码凭证对象的用户标识 用户的唯一标识
         // 密码凭证对象的用户标识 用户的唯一标识
@@ -189,14 +204,27 @@
                 NSLog(@"%@",result[@"name"]);
                 NSLog(@"%@",result[@"name"]);
                 if (error == nil) {
                 if (error == nil) {
                     NSMutableDictionary *paramsDic= [NSMutableDictionary dictionary];
                     NSMutableDictionary *paramsDic= [NSMutableDictionary dictionary];
-                    [paramsDic setObject:@(1) forKey:@"type"];
+//                    [paramsDic setObject:@(1) forKey:@"type"];
+//                    [paramsDic setObject:tmpToken forKey:@"token"];
+//                    [paramsDic setObject:MM_str(result[@"email"])  forKey:@"email"];
+//                    [paramsDic setObject:MM_str(result[@"id"])  forKey:@"uid"];
+//                    [paramsDic setObject:MM_str(result[@"first_name"]) forKey:@"firstName"];
+//                    [paramsDic setObject:MM_str(result[@"last_name"]) forKey:@"lastName"];
+//                    [paramsDic setObject:@"" forKey:@"birthday"];
+//                    [paramsDic setObject:@"" forKey:@"gender"];
+                    NSDictionary *userInfo = @{@"identifier":MM_str(result[@"id"]) ,
+                                               @"email":MM_str(result[@"email"]),
+                                               @"firstName":MM_str(result[@"first_name"]),
+                                               @"lastName":MM_str(result[@"last_name"]),
+                                               @"displayName":@""};
+                    
+                    NSString *userInfoStr = [userInfo mj_JSONString];
+                    
+                    [paramsDic setObject:userInfoStr forKey:@"userInfo"];
+                    [paramsDic setObject:@"facebook" forKey:@"hauth_done"];
                     [paramsDic setObject:tmpToken forKey:@"token"];
                     [paramsDic setObject:tmpToken forKey:@"token"];
-                    [paramsDic setObject:MM_str(result[@"email"])  forKey:@"email"];
-                    [paramsDic setObject:MM_str(result[@"id"])  forKey:@"uid"];
-                    [paramsDic setObject:MM_str(result[@"first_name"]) forKey:@"firstName"];
-                    [paramsDic setObject:MM_str(result[@"last_name"]) forKey:@"lastName"];
-                    [paramsDic setObject:@"" forKey:@"birthday"];
-                    [paramsDic setObject:@"" forKey:@"gender"];
+                    
+                    
                     NSLog(@"paramsDic----%@",paramsDic);
                     NSLog(@"paramsDic----%@",paramsDic);
                     [self generaltriggermethodType:ThirdTypeFaceBook data:paramsDic];
                     [self generaltriggermethodType:ThirdTypeFaceBook data:paramsDic];
                     
                     
@@ -211,27 +239,52 @@
 }
 }
 -(void)tool_google{
 -(void)tool_google{
     UIViewController *topvc = topViewController();
     UIViewController *topvc = topViewController();
+    K_WEAK_SELF;
     [MBProgressHUD showHUDAddedTo:topvc.view animated:YES];
     [MBProgressHUD showHUDAddedTo:topvc.view animated:YES];
     [GIDSignIn.sharedInstance signInWithPresentingViewController:topvc completion:^(GIDSignInResult * _Nullable signInResult, NSError * _Nullable error) {
     [GIDSignIn.sharedInstance signInWithPresentingViewController:topvc completion:^(GIDSignInResult * _Nullable signInResult, NSError * _Nullable error) {
+        K_STRONG_SELF;
+        [MBProgressHUD hideHUDForView:topvc.view animated:YES];
+        
         if (error) {
         if (error) {
             NSLog(@"NSError-----%@",error);
             NSLog(@"NSError-----%@",error);
             return;
             return;
         }
         }
         GIDGoogleUser *user = signInResult.user;
         GIDGoogleUser *user = signInResult.user;
-        if (user == nil) { return; }
+        if (user == nil) {
+            return;
+        }
 
 
         NSString *name = user.profile.name;
         NSString *name = user.profile.name;
         NSString *givenName = user.profile.givenName;
         NSString *givenName = user.profile.givenName;
         NSString *familyName = user.profile.familyName;
         NSString *familyName = user.profile.familyName;
         NSMutableDictionary *paramsDic= [NSMutableDictionary dictionary];
         NSMutableDictionary *paramsDic= [NSMutableDictionary dictionary];
-        [paramsDic setObject:@(2) forKey:@"type"];
-        [paramsDic setObject:user.accessToken forKey:@"token"];
-        [paramsDic setObject:user.profile.email forKey:@"email"];
-        [paramsDic setObject:user.userID forKey:@"uid"];
-        [paramsDic setObject:familyName forKey:@"firstName"];
-        [paramsDic setObject:givenName forKey:@"lastName"];
-        [paramsDic setObject:@"" forKey:@"birthday"];
-        [paramsDic setObject:@"" forKey:@"gender"];
+        
+        
+        
+        
+        NSDictionary *userInfo = @{@"identifier":user.userID,
+                                   @"email":user.profile.email,
+                                   @"firstName":familyName,
+                                   @"lastName":givenName,
+                                   @"displayName":@""};
+        
+        NSString *userInfoStr = [userInfo mj_JSONString];
+        
+        [paramsDic setObject:userInfoStr forKey:@"userInfo"];
+        [paramsDic setObject:@"google" forKey:@"hauth_done"];
+        [paramsDic setObject:user.accessToken.tokenString forKey:@"token"];
+        
+//        [paramsDic setObject:user.profile.email forKey:@"email"];
+//        [paramsDic setObject:user.userID forKey:@"identifier"];
+//        [paramsDic setObject:familyName forKey:@"firstName"];
+//        [paramsDic setObject:givenName forKey:@"lastName"];
+//        [paramsDic setObject:@"" forKey:@"birthday"];
+//        [paramsDic setObject:@"" forKey:@"gender"];
+        
+       
+//        [paramsDic setObject:signInResult.serverAuthCode forKey:@"code"];
+//        [paramsDic setObject:@"google" forKey:@"state"];
+        
         NSLog(@"paramsDic----%@",paramsDic);
         NSLog(@"paramsDic----%@",paramsDic);
         [self generaltriggermethodType:ThirdTypeGoogle data:paramsDic];
         [self generaltriggermethodType:ThirdTypeGoogle data:paramsDic];
     }];
     }];

+ 40 - 3
Asteria/Fuction/Login/VC/AS_LoginC.m

@@ -16,7 +16,7 @@
 
 
 
 
 
 
-@interface AS_LoginC ()
+@interface AS_LoginC () <TT_basevDelegate>
 @property (nonatomic, strong) UIScrollView *scrollview;
 @property (nonatomic, strong) UIScrollView *scrollview;
 @property (nonatomic, strong) EamilTFmatchV *xxx_emailTFV;
 @property (nonatomic, strong) EamilTFmatchV *xxx_emailTFV;
 @property (nonatomic, strong) PassWordSecureBtnV *xxx_passwordV;
 @property (nonatomic, strong) PassWordSecureBtnV *xxx_passwordV;
@@ -142,6 +142,44 @@
     [self.navigationController pushViewController:forgoC animated:YES];
     [self.navigationController pushViewController:forgoC animated:YES];
 }
 }
 
 
+#pragma mark ---- TT_basevDelegate 三方登录授权成功回调 -----
+
+- (void)tengteng_configtaptype:(NSInteger)num data:(id)data {
+    NSLog(@"======%ld\n=====%@", (long)num, data);
+    
+    if (num == ThirdTypeApple) {
+        
+    } else if (num == ThirdTypeFaceBook) {
+        
+    } else if (num == ThirdTypeGoogle) {
+        
+    }
+    
+    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
+    K_WEAK_SELF;
+    [ASNetTools.shared formData_postWithPath:userThirdLoginUrl param:(NSDictionary *)data success:^(id _Nonnull json) {
+        K_STRONG_SELF;
+        [MBProgressHUD hideHUDForView:self.view animated:YES];
+        
+        NSString *token = [NSString stringWithFormat:@"Bearer %@", json];
+        
+        [DataUtil setLoginToken:token];
+        [ASNetTools.shared updateEngine];
+        [ASUserInfoManager.shared getInfo];
+        
+        K_WEAK_SELF;
+        [self.view makeToast:@"Login Suecess" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
+            K_STRONG_SELF;
+            [self handle_closeEvent:nil];
+        }];
+        
+    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
+        K_STRONG_SELF;
+        [MBProgressHUD hideHUDForView:self.view animated:YES];
+        [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
+    }];
+}
+
 #pragma mark - **************** 懒加载 ****************
 #pragma mark - **************** 懒加载 ****************
 -(UIView *)logNavView{
 -(UIView *)logNavView{
     IPhoneXHeigh
     IPhoneXHeigh
@@ -197,11 +235,10 @@
     return _xxx_logInBtn;
     return _xxx_logInBtn;
 }
 }
 
 
-
-
 - (LoginThirdAuthV *)xxx_authV {
 - (LoginThirdAuthV *)xxx_authV {
     if (!_xxx_authV) {
     if (!_xxx_authV) {
         _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)];
         _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)];
+        _xxx_authV.basedelegate = self;
     }
     }
     return _xxx_authV;
     return _xxx_authV;
 }
 }

+ 2 - 0
Asteria/NetTools/ASNetApis.h

@@ -59,6 +59,8 @@
 #define userinfoUrl BaseRequestrUrl(@"customers/me")
 #define userinfoUrl BaseRequestrUrl(@"customers/me")
 #define vipInfoUrl BaseRequestrUrl(@"vip/index")
 #define vipInfoUrl BaseRequestrUrl(@"vip/index")
 #define userBirthUrl BaseRequestrUrl(@"vip/birthday")
 #define userBirthUrl BaseRequestrUrl(@"vip/birthday")
+//三方登录
+#define userThirdLoginUrl BaseRequestrUrl(@"callback")
 
 
 // MARK: - 修改用户信息
 // MARK: - 修改用户信息
 #define putUserInfo BaseRequestrUrl(@"customers/me")
 #define putUserInfo BaseRequestrUrl(@"customers/me")