美文网首页
第三方登录

第三方登录

作者: huicuihui | 来源:发表于2018-01-31 11:24 被阅读32次

    1、引入头文件

    #import <UMSocialCore/UMSocialCore.h>
    #import <UShareUI/UShareUI.h>
    

    2、在点击微信或QQ等按钮进行第三方登录的方法中去调用登录不同平台的方法

        //    微信登录
        [self getUserInfoForPlatform:UMSocialPlatformType_WechatSession];
    
        //    qq登录
        [self getUserInfoForPlatform:UMSocialPlatformType_QQ];
    

    3、实现不同平台登录

    #pragma mark - 友盟第三方登录
    - (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType
    {
        [UMSocialGlobal shareInstance].isClearCacheWhenGetUserInfo = YES;
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {
            UMSocialUserInfoResponse *resp = result;
            
            if (error) {
                NSLog(@"=====授权失败:%@",error);
            } else {
                
                NSLog(@"=====授权成功=====");
                
                // 第三方登录数据(为空表示平台未提供)
                // 授权数据
                //            B22D5D5D4A6DC3C22F41F003D56E76CA
                NSLog(@" uid: %@", resp.uid);
                NSLog(@" openid: %@", resp.openid);
                NSLog(@" accessToken: %@", resp.accessToken);
                NSLog(@" refreshToken: %@", resp.refreshToken);
                NSLog(@" expiration: %@", resp.expiration);
                NSLog(@" resp.unionId: %@", resp.unionId);
                // 用户数据
                NSLog(@" name: %@", resp.name);
                NSLog(@" iconurl: %@", resp.iconurl);
                NSLog(@" gender: %@", resp.unionGender);
                
                // 第三方平台SDK原始数据
                NSLog(@" originalResponse: %@", resp.originalResponse);
                
                /*
                 然后就可以在里面写自己服务器的网络请求, 去登录自己服务器。
                 */
                
            }
        }];
    }
    

    相关文章

      网友评论

          本文标题:第三方登录

          本文链接:https://www.haomeiwen.com/subject/serkzxtx.html