第三方登录

This commit is contained in:
fengshuo
2021-09-13 18:56:16 +08:00
parent fd6248ab1a
commit 895e5d8a69
21 changed files with 393 additions and 111 deletions

View File

@@ -15,5 +15,10 @@ target 'xplan-ios' do
pod 'NTESQuickPass', '~> 2.1.6'
#模型转化
pod 'MJExtension'
#登录的
pod 'mob_sharesdk'
pod 'mob_sharesdk/ShareSDKPlatforms/QQ'
pod 'mob_sharesdk/ShareSDKPlatforms/WeChat'
pod 'mob_sharesdk/ShareSDKPlatforms/Apple'
end

View File

@@ -17,6 +17,21 @@ PODS:
- Masonry (1.1.0)
- MBProgressHUD (1.2.0)
- MJExtension (3.3.0)
- mob_sharesdk (4.4.2):
- mob_sharesdk/ShareSDK (= 4.4.2)
- MOBFoundation (>= 3.2.9)
- mob_sharesdk/ShareSDK (4.4.2):
- MOBFoundation (>= 3.2.9)
- mob_sharesdk/ShareSDKPlatforms/Apple (4.4.2):
- mob_sharesdk/ShareSDK
- MOBFoundation (>= 3.2.9)
- mob_sharesdk/ShareSDKPlatforms/QQ (4.4.2):
- mob_sharesdk/ShareSDK
- MOBFoundation (>= 3.2.9)
- mob_sharesdk/ShareSDKPlatforms/WeChat (4.4.2):
- mob_sharesdk/ShareSDK
- MOBFoundation (>= 3.2.9)
- MOBFoundation (3.2.27)
- NTESQuickPass (2.1.9)
- ReactiveObjC (3.1.1)
- YYText (1.0.7)
@@ -26,6 +41,10 @@ DEPENDENCIES:
- Masonry
- MBProgressHUD
- MJExtension
- mob_sharesdk
- mob_sharesdk/ShareSDKPlatforms/Apple
- mob_sharesdk/ShareSDKPlatforms/QQ
- mob_sharesdk/ShareSDKPlatforms/WeChat
- NTESQuickPass (~> 2.1.6)
- ReactiveObjC
- YYText
@@ -36,6 +55,8 @@ SPEC REPOS:
- Masonry
- MBProgressHUD
- MJExtension
- mob_sharesdk
- MOBFoundation
- NTESQuickPass
- ReactiveObjC
- YYText
@@ -45,10 +66,12 @@ SPEC CHECKSUMS:
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
MJExtension: 01704cca2b60a214c10761b6491eab74069d68a9
mob_sharesdk: a60006891a079486ff3269ed326adfa05a967c01
MOBFoundation: efdc3ce6b843fbc10ae8c1c6122a02b0d845b39b
NTESQuickPass: 8431dc52737c95883cd382c2ee75664d58f39377
ReactiveObjC: 011caa393aa0383245f2dcf9bf02e86b80b36040
YYText: 5c461d709e24d55a182d1441c41dc639a18a4849
PODFILE CHECKSUM: 6662a976a7be0eed298430e68b706dbb92d1ad1e
PODFILE CHECKSUM: 82677bb54bd8940f2a6cc6f00b6eaefb58c721b7
COCOAPODS: 1.11.0

View File

@@ -66,6 +66,8 @@
E81C279D26EEEC620031E639 /* XPConstant.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C279C26EEEC620031E639 /* XPConstant.m */; };
E81C27A026EEF83D0031E639 /* XPHtmlUrl.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C279F26EEF83D0031E639 /* XPHtmlUrl.m */; };
E81C27A226EF23490031E639 /* XPEnum.h in Sources */ = {isa = PBXBuildFile; fileRef = E81C27A126EF23370031E639 /* XPEnum.h */; };
E81C27AB26EF2D920031E639 /* ThirdUserInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C27AA26EF2D920031E639 /* ThirdUserInfo.m */; };
E81C27AE26EF39AB0031E639 /* AppDelegate+ThirdConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */; };
E872308926E89BE000B90D4F /* LoginPhoneViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E872308826E89BE000B90D4F /* LoginPhoneViewController.m */; };
E872308D26E89DAA00B90D4F /* LoginInputView.m in Sources */ = {isa = PBXBuildFile; fileRef = E872308C26E89DAA00B90D4F /* LoginInputView.m */; };
E872309326E8D31500B90D4F /* LoginVerifCodeView.m in Sources */ = {isa = PBXBuildFile; fileRef = E872309226E8D31500B90D4F /* LoginVerifCodeView.m */; };
@@ -197,6 +199,10 @@
E81C279E26EEF83D0031E639 /* XPHtmlUrl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPHtmlUrl.h; sourceTree = "<group>"; };
E81C279F26EEF83D0031E639 /* XPHtmlUrl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPHtmlUrl.m; sourceTree = "<group>"; };
E81C27A126EF23370031E639 /* XPEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPEnum.h; sourceTree = "<group>"; };
E81C27A926EF2D920031E639 /* ThirdUserInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ThirdUserInfo.h; sourceTree = "<group>"; };
E81C27AA26EF2D920031E639 /* ThirdUserInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ThirdUserInfo.m; sourceTree = "<group>"; };
E81C27AC26EF39AB0031E639 /* AppDelegate+ThirdConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AppDelegate+ThirdConfig.h"; sourceTree = "<group>"; };
E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "AppDelegate+ThirdConfig.m"; sourceTree = "<group>"; };
E872308726E89BE000B90D4F /* LoginPhoneViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginPhoneViewController.h; sourceTree = "<group>"; };
E872308826E89BE000B90D4F /* LoginPhoneViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginPhoneViewController.m; sourceTree = "<group>"; };
E872308B26E89DAA00B90D4F /* LoginInputView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginInputView.h; sourceTree = "<group>"; };
@@ -275,8 +281,7 @@
E81C279926EB64BA0031E639 /* Global */,
189DD56B26DF5B0900AB55B1 /* Base */,
189DD56126DE45F800AB55B1 /* Main */,
189DD52C26DE255300AB55B1 /* AppDelegate.h */,
189DD52D26DE255300AB55B1 /* AppDelegate.m */,
E81C27AF26EF39B00031E639 /* Appdelegate */,
189DD53826DE255600AB55B1 /* Assets.xcassets */,
189DD53A26DE255600AB55B1 /* LaunchScreen.storyboard */,
189DD53D26DE255600AB55B1 /* Info.plist */,
@@ -592,6 +597,17 @@
path = Global;
sourceTree = "<group>";
};
E81C27AF26EF39B00031E639 /* Appdelegate */ = {
isa = PBXGroup;
children = (
189DD52C26DE255300AB55B1 /* AppDelegate.h */,
189DD52D26DE255300AB55B1 /* AppDelegate.m */,
E81C27AC26EF39AB0031E639 /* AppDelegate+ThirdConfig.h */,
E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */,
);
path = Appdelegate;
sourceTree = "<group>";
};
E872308A26E89D5100B90D4F /* CustomView */ = {
isa = PBXGroup;
children = (
@@ -610,6 +626,8 @@
children = (
E8B825BD26E9E57D009E8E9F /* LoginTicketInfo.h */,
E8B825BE26E9E57D009E8E9F /* LoginTicketInfo.m */,
E81C27A926EF2D920031E639 /* ThirdUserInfo.h */,
E81C27AA26EF2D920031E639 /* ThirdUserInfo.m */,
);
path = Model;
sourceTree = "<group>";
@@ -755,11 +773,13 @@
E81C279626EB39CC0031E639 /* LoginForgetPasswordPresent.m in Sources */,
E8B825B726E9A7D8009E8E9F /* BaseObject.m in Sources */,
189DD53426DE255300AB55B1 /* TabbarViewController.m in Sources */,
E81C27AB26EF2D920031E639 /* ThirdUserInfo.m in Sources */,
E81C279D26EEEC620031E639 /* XPConstant.m in Sources */,
187EEEFE26E8A82C002833B2 /* NSObject+AutoCoding.m in Sources */,
189DD55A26DE39D200AB55B1 /* BaseMvpPresenter.m in Sources */,
189DD6FF26E20E5900AB55B1 /* HttpRequestHelper.m in Sources */,
189DD74A26E21D8400AB55B1 /* SSKeychain.m in Sources */,
E81C27AE26EF39AB0031E639 /* AppDelegate+ThirdConfig.m in Sources */,
E8B825D026EA3825009E8E9F /* LoginPasswordViewController.m in Sources */,
189DD68426E1FDBB00AB55B1 /* XCHUDTool.m in Sources */,
189DD73F26E21C3F00AB55B1 /* YYUtility+Carrier.m in Sources */,

View File

@@ -0,0 +1,17 @@
//
// AppDelegate+ThirdConfig.h
// xplan-ios
//
// Created by 冯硕 on 2021/9/13.
//
#import "AppDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@interface AppDelegate (ThirdConfig)
/// 初始化一些第三方配置
- (void)initThirdConfig;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,32 @@
//
// AppDelegate+ThirdConfig.m
// xplan-ios
//
// Created by on 2021/9/13.
//
#import "AppDelegate+ThirdConfig.h"
///Third
#import <ShareSDK/ShareSDK.h>
///Tool
#import "XPConstant.h"
@implementation AppDelegate (ThirdConfig)
///
- (void)initThirdConfig {
[self configShareSDK];
}
- (void)configShareSDK {
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
//QQ
NSString *universalLink = @"https://6cqhk.share2dlink.com/";
NSString *qqUniversalLink = @"https://6cqhk.share2dlink.com/qq_conn/101937205";
[platformsRegister setupQQWithAppId:KeyWithType(KeyType_QQAppid) appkey:KeyWithType(KeyType_QQSecret) enableUniversalLink:YES universalLink:qqUniversalLink];
[platformsRegister setupWeChatWithAppId:KeyWithType(KeyType_WechatAppid) appSecret:KeyWithType(KeyType_WechatSecret) universalLink:universalLink];
}];
}
@end

View File

@@ -9,6 +9,7 @@
#import "TabbarViewController.h"
#import "BaseNavigationController.h"
#import "FlutterBoost+Xplan.h"
#import "AppDelegate+ThirdConfig.h"
@interface AppDelegate ()
@@ -19,12 +20,13 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FlutterBoost instance] setup:application];
TabbarViewController *vc = [[TabbarViewController alloc] init];
BaseNavigationController *bnc = [[BaseNavigationController alloc] initWithRootViewController:vc];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = bnc;
[self.window makeKeyAndVisible];
/// sdk
[self initThirdConfig];
return YES;
}

View File

@@ -7,9 +7,10 @@
//
#import <Foundation/Foundation.h>
#import "AccountModel.h"
@interface AccountInfoStorage : NSObject
@class AccountModel;
@interface AccountInfoStorage : NSObject
@property (nonatomic, strong, readonly) AccountModel *accountModel;
+ (instancetype)instance;
- (instancetype)init NS_UNAVAILABLE;

View File

@@ -9,6 +9,7 @@
#define kDataKey @"accountInfo"
#import "AccountInfoStorage.h"
#import "AccountModel.h"
@interface AccountInfoStorage()

View File

@@ -11,9 +11,17 @@ NS_ASSUME_NONNULL_BEGIN
@interface XPConstant : NSObject
UIKIT_EXTERN NSString * const kUMengAppkey;
UIKIT_EXTERN NSString * const kChannelKey;
typedef NS_ENUM(NSUInteger, KeyType) {
KeyType_PasswordEncode,///密码des 加密的
KeyType_NTESQuickLoginBusinessId,///玩意易盾 快捷登录 id
KeyType_QQAppid,///qqde appid
KeyType_QQSecret, ///QQ的 secret
KeyType_WechatAppid,///微信的appid
KeyType_WechatSecret,///微信的secret
};
/// 获取当前项目中所用到的 type 所对应的valu的值 type 类型

View File

@@ -9,6 +9,10 @@
@implementation XPConstant
NSString * const kUMengAppKey = @"5ff6bc6dadb42d5826a1cbc4";
NSString * const kChannelKey = @"App Store";
///
NSString * const KeyWithType(KeyType type) {
BOOL isRelease = YES;
@@ -16,12 +20,20 @@ NSString * const KeyWithType(KeyType type) {
///
@(YES):@{
@(KeyType_PasswordEncode): @"1ea53d260ecf11e7b56e00163e046a26",
@(KeyType_NTESQuickLoginBusinessId): @"09c1214706c34f4798d3f05d86148608"
@(KeyType_NTESQuickLoginBusinessId): @"09c1214706c34f4798d3f05d86148608",
@(KeyType_QQAppid) : @"101937205",
@(KeyType_QQSecret) : @"458ed9d671ba4b177799189db5fbc434",
@(KeyType_WechatAppid) : @"wx3f0462eb7eccd64f",
@(KeyType_WechatSecret) : @"1c07949e3f53433f1c6038bfcdd54c40",
},
///
@(NO):@{
@(KeyType_PasswordEncode): @"1ea53d260ecf11e7b56e00163e046a26",
@(KeyType_NTESQuickLoginBusinessId): @"09c1214706c34f4798d3f05d86148608"
@(KeyType_NTESQuickLoginBusinessId): @"09c1214706c34f4798d3f05d86148608",
@(KeyType_QQAppid) : @"101937205",
@(KeyType_QQSecret) : @"458ed9d671ba4b177799189db5fbc434",
@(KeyType_WechatAppid) : @"wx3f0462eb7eccd64f",
@(KeyType_WechatSecret) : @"1c07949e3f53433f1c6038bfcdd54c40",
}
};
NSDictionary * enviroDic = [dic objectForKey:@(isRelease)];

View File

@@ -9,9 +9,9 @@
#define XPEnum_h
typedef NS_ENUM(NSUInteger, ThirdLoginType) {
ThirdLoginType_WeChat,///微信
ThirdLoginType_QQ,///QQ
ThirdLoginType_Apple,///苹果登录
ThirdLoginType_WeChat = 1,///微信
ThirdLoginType_QQ = 2,///QQ
ThirdLoginType_Apple = 5,///苹果登录
};
#endif /* XPEnum_h */

View File

@@ -18,10 +18,48 @@
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>tencent101937205</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wx3f0462eb7eccd64f</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MOBAppKey</key>
<string>m327090efb1260</string>
<key>MOBAppSecret</key>
<string>85b767077fd991853329d54fbbaee19c</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>wechat</string>
<string>weixinULAPI</string>
<string>mqq</string>
<string>mqqapi</string>
<string>mqqwpa</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>wtloginmqq2</string>
<string>mqzone</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqopensdkminiapp</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>

View File

@@ -6,7 +6,6 @@
//
#import "Api.h"
NS_ASSUME_NONNULL_BEGIN
@interface Api (Login)
@@ -37,6 +36,14 @@ NS_ASSUME_NONNULL_BEGIN
/// @param newPwd 新的密码
/// @param smsCode 验证码
+ (void)resetPasswordWithPhone:(HttpRequestHelperCompletion)complction phone:(NSString *)phone newPwd:(NSString *)newPwd smsCode:(NSString *)smsCode;
/// 第三方登录
/// @param complction 完成
/// @param openid 唯一标识符
/// @param unionid unionid
/// @param access_token access_token
/// @param type 第三方登录的类型
+ (void)loginWithThirdPartWithComplction:(HttpRequestHelperCompletion)complction openid:(NSString *)openid unionid:(NSString *)unionid access_token:(NSString *)access_token type:(NSString *)type;
@end
NS_ASSUME_NONNULL_END

View File

@@ -39,12 +39,23 @@
}
///
/// @param complction
/// @param completion
/// @param phone
/// @param newPwd
/// @param smsCode
+ (void)resetPasswordWithPhone:(HttpRequestHelperCompletion)complction phone:(NSString *)phone newPwd:(NSString *)newPwd smsCode:(NSString *)smsCode {
[self makeRequest:@"acc/pwd/reset" method:HttpRequestHelperMethodPOST completion:complction, __FUNCTION__, phone, newPwd, smsCode, nil];
+ (void)resetPasswordWithPhone:(HttpRequestHelperCompletion)completion phone:(NSString *)phone newPwd:(NSString *)newPwd smsCode:(NSString *)smsCode {
[self makeRequest:@"acc/pwd/reset" method:HttpRequestHelperMethodPOST completion:completion, __FUNCTION__, phone, newPwd, smsCode, nil];
}
///
/// @param complction
/// @param openid
/// @param unionid unionid
/// @param access_token access_token
/// @param type
+ (void)loginWithThirdPartWithComplction:(HttpRequestHelperCompletion)complction openid:(NSString *)openid unionid:(NSString *)unionid access_token:(NSString *)access_token type:(NSString *)type {
[self makeRequest:@"acc/third/login" method:HttpRequestHelperMethodPOST completion:complction, __FUNCTION__, openid, unionid, access_token, type, nil];
}
@end

View File

@@ -0,0 +1,20 @@
//
// ThirdUserInfo.h
// xplan-ios
//
// Created by 冯硕 on 2021/9/13.
//
#import "BaseObject.h"
NS_ASSUME_NONNULL_BEGIN
@interface ThirdUserInfo : BaseObject
///用户名
@property (nonatomic,copy) NSString *userName;
///头像的地址
@property (nonatomic,copy) NSString *avatarUrl;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,12 @@
//
// ThirdUserInfo.m
// xplan-ios
//
// Created by on 2021/9/13.
//
#import "ThirdUserInfo.h"
@implementation ThirdUserInfo
@end

View File

@@ -6,13 +6,18 @@
//
#import "BaseMvpPresenter.h"
#import "XPEnum.h"
NS_ASSUME_NONNULL_BEGIN
@interface LoginPresenter : BaseMvpPresenter
- (void)phoneQuickLogin:(NSString *)accessToken token:(NSString*) token;
/// 第三方登录
/// @param type 登录的类型
- (void)thirdLoginWithType:(ThirdLoginType)type;
@end
NS_ASSUME_NONNULL_END

View File

@@ -6,13 +6,20 @@
//
#import "LoginPresenter.h"
///
///Third
#import <ReactiveObjC/ReactiveObjC.h>
#import "LoginProtocol.h"
#import <ShareSDK/ShareSDK.h>
///APi
#import "Api+Login.h"
///Tool
#import "AccountInfoStorage.h"
#import "XCHUDTool.h"
///P
#import "LoginProtocol.h"
///Model
#import "LoginTicketInfo.h"
#import "ThirdUserInfo.h"
#import "AccountModel.h"
@implementation LoginPresenter
@@ -28,4 +35,83 @@
// todo fail
}] accessToken:accessToken token:token];
}
///
/// @param type
- (void)thirdLoginWithType:(ThirdLoginType)type {
SSDKPlatformType platformType;
switch (type) {
case ThirdLoginType_QQ:
platformType = SSDKPlatformTypeQQ;
break;
case ThirdLoginType_WeChat:
platformType = SSDKPlatformTypeWechat;
break;
case ThirdLoginType_Apple:
platformType = SSDKPlatformTypeAppleAccount;
break;
default:
platformType = SSDKPlatformTypeQQ;
break;
}
[ShareSDK cancelAuthorize:platformType result:nil];
[ShareSDK getUserInfo:platformType onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
if (state == SSDKResponseStateSuccess) {///
ThirdUserInfo * userInfo = [[ThirdUserInfo alloc] init];
NSString * openid = @"";
NSString * access_token = user.credential.token.length > 0 ? user.credential.token : @"";
NSString * unionid = @"";
if (platformType == SSDKPlatformTypeQQ) { //QQ
// [[BaiduMobStat defaultStat]logEvent:@"login_qq_click" eventLabel:@"qq登录"];
openid = user.credential.rawData[@"openid"];
unionid = [user.credential rawData][@"unionid"];;
userInfo.userName = [user.credential rawData][@"nickname"];
userInfo.avatarUrl = [user.credential rawData][@"figureurl_qq_2"];
} else if (platformType == SSDKPlatformTypeWechat) { //
// [[BaiduMobStat defaultStat]logEvent:@"login_wx_click" eventLabel:@"微信登录"];
openid = user.credential.rawData[@"openid"];
unionid = [user.credential rawData][@"unionid"];
userInfo.userName = [user.credential rawData][@"nickname"];
userInfo.avatarUrl = [user.credential rawData][@"headimgurl"];
} else if (platformType == SSDKPlatformTypeAppleAccount) { //
openid = user.credential.rawData[@"openid"];
unionid = [user.credential rawData][@"unionid"];
NSString * familyName = [user.credential rawData][@"fullName"][@"familyName"];
NSString * givenName = [user.credential rawData][@"fullName"][@"givenName"];
userInfo.userName = [NSString stringWithFormat:@"%@%@", familyName, givenName];
}
[self thirdLOginWithopenID:openid andUnionID:unionid access_token:access_token andType:type];
} else if(state == SSDKResponseStateCancel) {///
[XCHUDTool hideHUD];
[[self getView] thirdLoginCancel];
} else if (state == SSDKResponseStateFail) {///
[XCHUDTool hideHUD];
if (error.description) {
[[self getView] thirdLoginFailth:error.description];
}
}
}];
}
- (void)thirdLOginWithopenID:(NSString *)openId
andUnionID:(NSString *)unionID
access_token:(NSString *)access_token
andType:(ThirdLoginType)type {
NSString * typeStr = [NSString stringWithFormat:@"%lu", type];
unionID = @"";
[Api loginWithThirdPartWithComplction:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[XCHUDTool hideHUD];
AccountModel * model = [AccountModel modelWithDictionary:data.data];
if (model != nil) {
[[AccountInfoStorage instance] saveAccountInfo:model];
[[self getView] thirdLoginSuccess];
} else {
[[self getView] thirdLoginFailth:@"登录失败"];
}
} fail:^(NSInteger code, NSString * _Nullable msg) {
} showLoading:YES] openid:openId unionid:unionID access_token:access_token type:typeStr];
}
@end

View File

@@ -12,6 +12,13 @@ NS_ASSUME_NONNULL_BEGIN
@protocol LoginProtocol <NSObject>
- (void)phoneQuickLoginSuccess;
///第三方登录取消
- (void)thirdLoginCancel;
///第三方登录失败
- (void)thirdLoginFailth:(NSString *)message;
///第三方登录成功
- (void)thirdLoginSuccess;
@end
NS_ASSUME_NONNULL_END

View File

@@ -11,6 +11,7 @@
#import <ReactiveObjC.h>
#import <YYText.h>
#import <NTESQuickPass/NTESQuickPass.h>
#import <AuthenticationServices/ASAuthorizationAppleIDButton.h>
///Tool
#import "UIImage+Utils.h"
#import "GCDHelper.h"
@@ -32,70 +33,6 @@ typedef NS_ENUM(NSUInteger, XYLoginType) {
XYLoginTypeUnicom = 3 //
};
typedef NS_ENUM(NSInteger,XYThirdLoginType) {
XYThirdLoginWechat = 1, //
XYThirdLoginQQ = 2, // QQ
XYThirdLoginPhoneNum = 3, //
XYThirdLoginApple = 5, // id
};
@interface LLButtonView : UIView
//icon
@property (nonatomic, strong) UIImageView *logoImageView;
//title
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation LLButtonView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initView];
[self initContrations];
}
return self;
}
- (void)initView {
[self addSubview:self.logoImageView];
[self addSubview:self.titleLabel];
}
- (void)initContrations {
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(36, 36));
make.centerX.left.mas_equalTo(self);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self);
make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(15);
}];
}
- (UIImageView *)logoImageView {
if (!_logoImageView) {
_logoImageView = [[UIImageView alloc] init];
_logoImageView.userInteractionEnabled = YES;
}
return _logoImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:11];
_titleLabel.textColor = [ThemeColor mainTextColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
@end
@interface LoginViewController () <LoginProtocol>
@property (nonatomic, strong) UIImageView *appIcon;
@@ -110,12 +47,14 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
@property (nonatomic, strong) UIStackView *stackView;
///
@property (nonatomic, strong) LLButtonView *qqButtonView;
@property (nonatomic, strong) UIButton *qqButtonView;
///wx
@property (nonatomic, strong) LLButtonView *wxButtonView;
@property (nonatomic, strong) UIButton *wxButtonView;
///qq
@property (nonatomic, strong) LLButtonView *phoneButtonView;
@property (nonatomic, strong) UIButton *phoneButtonView;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
@property (nonatomic, strong) ASAuthorizationAppleIDButton *appleButton;
#endif
/** */
@property (nonatomic, strong) UIButton *agreeButton;
/** */
@@ -132,11 +71,6 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
- (LoginPresenter *)createPresenter {
return [[LoginPresenter alloc] init];
}
- (void)phoneQuickLoginSuccess {
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
@@ -170,6 +104,10 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
[self.stackView addArrangedSubview:self.qqButtonView];
[self.stackView addArrangedSubview:self.phoneButtonView];
[self.stackView addArrangedSubview:self.wxButtonView];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
[self.stackView addArrangedSubview:self.appleButton];
#endif
}
@@ -210,7 +148,7 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.view).offset(-kSafeAreaBottomHeight - 60);
make.centerX.mas_equalTo(self.view);
make.height.mas_equalTo(65);
make.height.mas_equalTo(50);
}];
@@ -238,6 +176,12 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
make.left.mas_equalTo(8);
make.bottom.mas_equalTo(self.authBubbleView).mas_offset(-6);
}];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
[self.appleButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 50));
}];
#endif
}
- (void)setEvents {
@@ -249,6 +193,8 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
[self.qqButtonView addGestureRecognizer:qqTap];
UITapGestureRecognizer * wxTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickRecognizer:)];
[self.wxButtonView addGestureRecognizer:wxTap];
UITapGestureRecognizer * appleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickRecognizer:)];
[self.appleButton addGestureRecognizer:appleTap];
[[self.agreeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
self.agreeButton.selected = !self.agreeButton.selected;
@@ -281,12 +227,9 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
if ([view isEqual:self.phoneButtonView]) {
LoginPhoneViewController *inputPhoneVC = [[LoginPhoneViewController alloc] init];
[self.navigationController pushViewController:inputPhoneVC animated:YES];
} else if([view isEqual:self.qqButtonView]) {
[XCHUDTool showLoading];
// [GetCore(AuthCore) thirdLoginPlatform:SSDKPlatformTypeQQ];
} else if([view isEqual:self.wxButtonView]) {
[XCHUDTool showLoading];
// [GetCore(AuthCore) thirdLoginPlatform:SSDKPlatformTypeWechat];
} else{
ThirdLoginType type = view.tag - 1000;
[self.presenter thirdLoginWithType:type];
}
} else {
[UIView animateWithDuration:0.5 animations:^{
@@ -423,7 +366,25 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
[[NTESQuickLoginManager sharedInstance] setupModel:CMModel];
});
}
#pragma mark - LoginProtocol
- (void)phoneQuickLoginSuccess {
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)thirdLoginSuccess {
[self.navigationController popToRootViewControllerAnimated:YES];
[XCHUDTool showSuccessWithMessage:@"登录成功"];
}
- (void)thirdLoginCancel {
[XCHUDTool showSuccessWithMessage:@"取消登录"];
}
- (void)thirdLoginFailth:(NSString *)message {
[XCHUDTool showErrorWithMessage:message];
}
#pragma mark - Getters And Setters
- (UIImageView *)appIcon {
if (!_appIcon) {
_appIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_appIcon"]];
@@ -551,31 +512,45 @@ typedef NS_ENUM(NSInteger,XYThirdLoginType) {
return _stackView;
}
- (LLButtonView *)phoneButtonView {
- (UIButton *)phoneButtonView {
if (!_phoneButtonView) {
_phoneButtonView = [[LLButtonView alloc] init];
_phoneButtonView.logoImageView.image = [UIImage imageNamed:@"login_phone"];
_phoneButtonView.titleLabel.text = @"手机";
_phoneButtonView = [UIButton buttonWithType:UIButtonTypeCustom];
[_phoneButtonView setImage: [UIImage imageNamed:@"login_phone"] forState:UIControlStateNormal];
}
return _phoneButtonView;
}
- (LLButtonView *)qqButtonView {
- (UIButton *)qqButtonView {
if (!_qqButtonView) {
_qqButtonView = [[LLButtonView alloc] init];
_qqButtonView.logoImageView.image = [UIImage imageNamed:@"login_qq"];
_qqButtonView.titleLabel.text = @"QQ";
_qqButtonView = [UIButton buttonWithType:UIButtonTypeCustom];
[_qqButtonView setImage: [UIImage imageNamed:@"login_qq"] forState:UIControlStateNormal];
_qqButtonView.tag = 1000 + ThirdLoginType_QQ;
}
return _qqButtonView;
}
- (LLButtonView *)wxButtonView {
- (UIButton *)wxButtonView {
if (!_wxButtonView) {
_wxButtonView = [[LLButtonView alloc] init];
_wxButtonView.logoImageView.image = [UIImage imageNamed:@"login_wechat"];
_wxButtonView.titleLabel.text = @"微信";
_wxButtonView = [UIButton buttonWithType:UIButtonTypeCustom];
[_wxButtonView setImage: [UIImage imageNamed:@"login_wechat"] forState:UIControlStateNormal];
_wxButtonView.tag = 1000 + ThirdLoginType_WeChat;
}
return _wxButtonView;
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
- (ASAuthorizationAppleIDButton *)appleButton API_AVAILABLE(ios(13.0)){
if (!_appleButton) {
if (@available(iOS 13.0, *)) {
_appleButton = [[ASAuthorizationAppleIDButton alloc] initWithAuthorizationButtonType:ASAuthorizationAppleIDButtonTypeSignIn authorizationButtonStyle:ASAuthorizationAppleIDButtonStyleBlack];
} else {
// Fallback on earlier versions
}
_appleButton.cornerRadius = 25;
_appleButton.tag = 1000 + ThirdLoginType_Apple;
}
return _appleButton;
}
#endif
@end