diff --git a/Podfile b/Podfile index b67456d2..b1b5b81f 100644 --- a/Podfile +++ b/Podfile @@ -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 diff --git a/Podfile.lock b/Podfile.lock index 49f5cb3c..9d277c46 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -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 diff --git a/xplan-ios.xcodeproj/project.pbxproj b/xplan-ios.xcodeproj/project.pbxproj index 2509e4a5..95fd2ce3 100644 --- a/xplan-ios.xcodeproj/project.pbxproj +++ b/xplan-ios.xcodeproj/project.pbxproj @@ -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 = ""; }; E81C279F26EEF83D0031E639 /* XPHtmlUrl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPHtmlUrl.m; sourceTree = ""; }; E81C27A126EF23370031E639 /* XPEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPEnum.h; sourceTree = ""; }; + E81C27A926EF2D920031E639 /* ThirdUserInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ThirdUserInfo.h; sourceTree = ""; }; + E81C27AA26EF2D920031E639 /* ThirdUserInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ThirdUserInfo.m; sourceTree = ""; }; + E81C27AC26EF39AB0031E639 /* AppDelegate+ThirdConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AppDelegate+ThirdConfig.h"; sourceTree = ""; }; + E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "AppDelegate+ThirdConfig.m"; sourceTree = ""; }; E872308726E89BE000B90D4F /* LoginPhoneViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginPhoneViewController.h; sourceTree = ""; }; E872308826E89BE000B90D4F /* LoginPhoneViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginPhoneViewController.m; sourceTree = ""; }; E872308B26E89DAA00B90D4F /* LoginInputView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginInputView.h; sourceTree = ""; }; @@ -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 = ""; }; + E81C27AF26EF39B00031E639 /* Appdelegate */ = { + isa = PBXGroup; + children = ( + 189DD52C26DE255300AB55B1 /* AppDelegate.h */, + 189DD52D26DE255300AB55B1 /* AppDelegate.m */, + E81C27AC26EF39AB0031E639 /* AppDelegate+ThirdConfig.h */, + E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */, + ); + path = Appdelegate; + sourceTree = ""; + }; 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 = ""; @@ -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 */, diff --git a/xplan-ios/Appdelegate/AppDelegate+ThirdConfig.h b/xplan-ios/Appdelegate/AppDelegate+ThirdConfig.h new file mode 100644 index 00000000..5a7fbf4e --- /dev/null +++ b/xplan-ios/Appdelegate/AppDelegate+ThirdConfig.h @@ -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 diff --git a/xplan-ios/Appdelegate/AppDelegate+ThirdConfig.m b/xplan-ios/Appdelegate/AppDelegate+ThirdConfig.m new file mode 100644 index 00000000..ccfc53dd --- /dev/null +++ b/xplan-ios/Appdelegate/AppDelegate+ThirdConfig.m @@ -0,0 +1,32 @@ +// +// AppDelegate+ThirdConfig.m +// xplan-ios +// +// Created by 冯硕 on 2021/9/13. +// + +#import "AppDelegate+ThirdConfig.h" +///Third +#import +///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 diff --git a/xplan-ios/AppDelegate.h b/xplan-ios/Appdelegate/AppDelegate.h similarity index 100% rename from xplan-ios/AppDelegate.h rename to xplan-ios/Appdelegate/AppDelegate.h diff --git a/xplan-ios/AppDelegate.m b/xplan-ios/Appdelegate/AppDelegate.m similarity index 89% rename from xplan-ios/AppDelegate.m rename to xplan-ios/Appdelegate/AppDelegate.m index 69545887..1f69a39d 100644 --- a/xplan-ios/AppDelegate.m +++ b/xplan-ios/Appdelegate/AppDelegate.m @@ -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; } diff --git a/xplan-ios/Base/MVP/Model/AccountInfoStorage.h b/xplan-ios/Base/MVP/Model/AccountInfoStorage.h index 8c60a8d7..ed06958d 100644 --- a/xplan-ios/Base/MVP/Model/AccountInfoStorage.h +++ b/xplan-ios/Base/MVP/Model/AccountInfoStorage.h @@ -7,9 +7,10 @@ // #import -#import "AccountModel.h" -@interface AccountInfoStorage : NSObject +@class AccountModel; +@interface AccountInfoStorage : NSObject +@property (nonatomic, strong, readonly) AccountModel *accountModel; + (instancetype)instance; - (instancetype)init NS_UNAVAILABLE; diff --git a/xplan-ios/Base/MVP/Model/AccountInfoStorage.m b/xplan-ios/Base/MVP/Model/AccountInfoStorage.m index a49f0500..d4d8ee6e 100644 --- a/xplan-ios/Base/MVP/Model/AccountInfoStorage.m +++ b/xplan-ios/Base/MVP/Model/AccountInfoStorage.m @@ -9,6 +9,7 @@ #define kDataKey @"accountInfo" #import "AccountInfoStorage.h" +#import "AccountModel.h" @interface AccountInfoStorage() diff --git a/xplan-ios/Global/XPConstant.h b/xplan-ios/Global/XPConstant.h index c0ed68f6..1809e5b0 100644 --- a/xplan-ios/Global/XPConstant.h +++ b/xplan-ios/Global/XPConstant.h @@ -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 类型 diff --git a/xplan-ios/Global/XPConstant.m b/xplan-ios/Global/XPConstant.m index 979d1b6a..bded59f4 100644 --- a/xplan-ios/Global/XPConstant.m +++ b/xplan-ios/Global/XPConstant.m @@ -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)]; diff --git a/xplan-ios/Global/XPEnum.h b/xplan-ios/Global/XPEnum.h index 706e100b..2e3c7881 100644 --- a/xplan-ios/Global/XPEnum.h +++ b/xplan-ios/Global/XPEnum.h @@ -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 */ diff --git a/xplan-ios/Info.plist b/xplan-ios/Info.plist index e720c1bf..9d63329e 100644 --- a/xplan-ios/Info.plist +++ b/xplan-ios/Info.plist @@ -18,10 +18,48 @@ $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString $(MARKETING_VERSION) + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + tencent101937205 + + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + wx3f0462eb7eccd64f + + + CFBundleVersion 1 LSRequiresIPhoneOS + MOBAppKey + m327090efb1260 + MOBAppSecret + 85b767077fd991853329d54fbbaee19c + LSApplicationQueriesSchemes + + weixin + wechat + weixinULAPI + mqq + mqqapi + mqqwpa + mqqopensdkapiV2 + mqqopensdkapiV3 + wtloginmqq2 + mqzone + mqqOpensdkSSoLogin + mqqopensdkminiapp + NSAppTransportSecurity NSAllowsArbitraryLoads diff --git a/xplan-ios/Main/Login/Api/Api+Login.h b/xplan-ios/Main/Login/Api/Api+Login.h index 6f2e9362..5e551786 100644 --- a/xplan-ios/Main/Login/Api/Api+Login.h +++ b/xplan-ios/Main/Login/Api/Api+Login.h @@ -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 diff --git a/xplan-ios/Main/Login/Api/Api+Login.m b/xplan-ios/Main/Login/Api/Api+Login.m index e606bb80..8047b49d 100644 --- a/xplan-ios/Main/Login/Api/Api+Login.m +++ b/xplan-ios/Main/Login/Api/Api+Login.m @@ -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 diff --git a/xplan-ios/Main/Login/Model/ThirdUserInfo.h b/xplan-ios/Main/Login/Model/ThirdUserInfo.h new file mode 100644 index 00000000..7bc96da8 --- /dev/null +++ b/xplan-ios/Main/Login/Model/ThirdUserInfo.h @@ -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 diff --git a/xplan-ios/Main/Login/Model/ThirdUserInfo.m b/xplan-ios/Main/Login/Model/ThirdUserInfo.m new file mode 100644 index 00000000..aa9ad4df --- /dev/null +++ b/xplan-ios/Main/Login/Model/ThirdUserInfo.m @@ -0,0 +1,12 @@ +// +// ThirdUserInfo.m +// xplan-ios +// +// Created by 冯硕 on 2021/9/13. +//保存第三方请求的 用户信息 + +#import "ThirdUserInfo.h" + +@implementation ThirdUserInfo + +@end diff --git a/xplan-ios/Main/Login/Presenter/LoginPresenter.h b/xplan-ios/Main/Login/Presenter/LoginPresenter.h index e385d156..a61f0c54 100644 --- a/xplan-ios/Main/Login/Presenter/LoginPresenter.h +++ b/xplan-ios/Main/Login/Presenter/LoginPresenter.h @@ -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 diff --git a/xplan-ios/Main/Login/Presenter/LoginPresenter.m b/xplan-ios/Main/Login/Presenter/LoginPresenter.m index 4b77d45f..1f726c09 100644 --- a/xplan-ios/Main/Login/Presenter/LoginPresenter.m +++ b/xplan-ios/Main/Login/Presenter/LoginPresenter.m @@ -6,13 +6,20 @@ // #import "LoginPresenter.h" -///第三方 +///Third #import -#import "LoginProtocol.h" +#import +///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 diff --git a/xplan-ios/Main/Login/Protocol/LoginProtocol.h b/xplan-ios/Main/Login/Protocol/LoginProtocol.h index a0979275..489e8968 100644 --- a/xplan-ios/Main/Login/Protocol/LoginProtocol.h +++ b/xplan-ios/Main/Login/Protocol/LoginProtocol.h @@ -12,6 +12,13 @@ NS_ASSUME_NONNULL_BEGIN @protocol LoginProtocol - (void)phoneQuickLoginSuccess; + +///第三方登录取消 +- (void)thirdLoginCancel; +///第三方登录失败 +- (void)thirdLoginFailth:(NSString *)message; +///第三方登录成功 +- (void)thirdLoginSuccess; @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Login/View/LoginViewController.m b/xplan-ios/Main/Login/View/LoginViewController.m index 11dd9351..4214162d 100644 --- a/xplan-ios/Main/Login/View/LoginViewController.m +++ b/xplan-ios/Main/Login/View/LoginViewController.m @@ -11,6 +11,7 @@ #import #import #import +#import ///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 () @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