AppDelegate+XYShanYan.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. //
  2. // AppDelegate+XYShanYan.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2019/12/11.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "AppDelegate+XYShanYan.h"
  9. #import <CL_ShanYanSDK/CL_ShanYanSDK.h>
  10. #import "XYOtherLoginView.h"
  11. #import "XYLoginViewController.h"
  12. #import "XYSetupUserInfoViewController.h"
  13. #import <Bugly/Bugly.h>
  14. #import <CloudPushSDK/CloudPushSDK.h>
  15. #import "XYHeadlineRoomManage.h"
  16. #import "YQAnmationResourceMag.h"
  17. @implementation AppDelegate (XYShanYan)
  18. /*
  19. 创蓝闪验初始化
  20. */
  21. - (void)cl_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  22. // 非登录状态进行初始化
  23. NSString *appId = self.appConfigModel.channelConfig.oneKeyLogin.appId;
  24. [CLShanYanSDKManager initWithAppId:appId complete:^(CLCompleteResult * _Nonnull completeResult) {
  25. if (completeResult.error) {
  26. NSLog(@"闪验SDK 初始化失败:%@",completeResult.message);
  27. }else{
  28. NSLog(@"闪验SDK 初始化成功:%@",completeResult.message);
  29. }
  30. }];
  31. [CLShanYanSDKManager printConsoleEnable:NO];
  32. }
  33. /// 创建快捷登录页(一键登录)
  34. - (void)createQulickLoginPageVC {
  35. // 防止出现presentView
  36. // [self dismissViewController:^{
  37. //
  38. // }];
  39. if ([XYUserInfoManager nowUser]) {
  40. [self logoutHandleSuccess:^(BOOL success) {
  41. [self createQulickLoginPageVCLoading];
  42. }];
  43. }else {
  44. dispatch_async(dispatch_get_main_queue(), ^{
  45. [self createQulickLoginPageVCLoading];
  46. });
  47. }
  48. }
  49. - (void)createQulickLoginPageVCLoading {
  50. ///防止多次登录
  51. if (!self.tabbarVC) {
  52. return;
  53. }
  54. if (self.isLogin) {
  55. return;
  56. }
  57. NSString *appId = self.appConfigModel.channelConfig.oneKeyLogin.appId;
  58. if (StringIsEmpty(appId)) {
  59. // 跳转到其他登录界面
  60. [self createLoginPageVC];
  61. return;
  62. }
  63. // 获取预取号 在调取登录页之前调用
  64. [SVProgressHUD showWithStatus:@"加载中..."];
  65. [CLShanYanSDKManager preGetPhonenumber:^(CLCompleteResult * _Nonnull completeResult) {
  66. dispatch_async(dispatch_get_main_queue(), ^{
  67. // 隐藏loading操作
  68. [SVProgressHUD dismiss];
  69. });
  70. if (completeResult.error) {
  71. NSLog(@"%@f",completeResult.error.description);
  72. // 获取失败则说明不支持一键登录
  73. // 跳转到其他登录界面
  74. [self createLoginPageVC];
  75. }else{
  76. NSLog(@"%@",completeResult.yy_modelDescription);
  77. // 不建议调用后立即调用拉起授权页方法(此方法是异步)这里增加两秒的延迟
  78. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  79. // 获取成功则拉取一键登录登录页
  80. if ([XYUserInfoManager nowUser]) {
  81. [self logoutHandleSuccess:^(BOOL success) {
  82. [self qulickLogin];
  83. }];
  84. }else {
  85. [self qulickLogin];
  86. }
  87. });
  88. }
  89. }];
  90. }
  91. /// 创建其他登录方式页 (第三方和手机验证码登录)
  92. - (void)createLoginPageVC {
  93. dispatch_async(dispatch_get_main_queue(), ^{
  94. XYLoginViewController *loginVC = [XYLoginViewController new];
  95. BaseNavigationController *loginNav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
  96. [[ApplicationDelegate getCurrentController] presentViewController:loginNav animated:NO completion:nil];
  97. });
  98. }
  99. /// 拉取一键登录授权页面
  100. - (void)qulickLogin {
  101. CLUIConfigure * baseUIConfigure = [self configureInitUI];
  102. [CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
  103. dispatch_async(dispatch_get_main_queue(), ^{
  104. // 隐藏loading操作
  105. [SVProgressHUD dismiss];
  106. });
  107. if (completeResult.error) {
  108. NSLog(@"授权页拉起失败 error:%@",completeResult.error.description);
  109. //关闭授权页
  110. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  111. // 跳转到其他登录界面
  112. self.isLogin = NO;
  113. [self createLoginPageVC];
  114. }];
  115. }else{
  116. NSLog(@"授权页拉起成功");
  117. self.isLogin = YES;
  118. }
  119. } oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
  120. dispatch_async(dispatch_get_main_queue(), ^{
  121. // 隐藏loading操作
  122. [SVProgressHUD dismiss];
  123. });
  124. if (completeResult.error) {
  125. NSLog(@"一键登录失败 error:%@",completeResult.error.description);
  126. //提示:错误无需提示给用户,可以在用户无感知的状态下直接切换登录方式
  127. if (completeResult.code == 1011){
  128. //用户取消登录(点返回)
  129. //处理建议:如无特殊需求可不做处理,仅作为交互状态回调,此时已经回到当前用户自己的页面
  130. //点击sdk自带的返回,无论是否设置手动销毁,授权页面都会强制关闭
  131. } else{
  132. //处理建议:其他错误代码表示闪验通道无法继续,可以统一走开发者自己的其他登录方式,也可以对不同的错误单独处理
  133. //1003 一键登录获取token失败
  134. //其他 其他错误//
  135. }
  136. //关闭授权页
  137. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  138. // 跳转到其他登录界面
  139. self.isLogin = NO;
  140. [self createLoginPageVC];
  141. }];
  142. }else{
  143. kWEAKSELF
  144. NSLog(@"一键登录获取token成功");
  145. NSString *token = completeResult.data[@"token"];
  146. // 验证token
  147. [[XYUserAPIManager new] byOneKeyWithCert:token inviteCode:@"" successHandler:^(ZYLResponseModel *responseModel) {
  148. BOOL isCoolPeriod = [[AppDelegate sharedDelegate] isCoolPeriod:responseModel.data];
  149. [AppDelegate sharedDelegate].XYCoolPeriodAgainLogin = ^(BOOL success) {
  150. [weakSelf parseQuickLoginResponseModel:responseModel];
  151. };
  152. if (isCoolPeriod) {
  153. return;
  154. }
  155. [weakSelf parseQuickLoginResponseModel:responseModel];
  156. } failureHandler:^(NSError *error) {
  157. [SVProgressHUD dismiss];
  158. //关闭授权页
  159. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  160. // 跳转到其他登录界面
  161. self.isLogin = NO;
  162. [self createLoginPageVC];
  163. }];
  164. }];
  165. }
  166. }];
  167. }
  168. - (void)parseQuickLoginResponseModel:(ZYLResponseModel *)responseModel{
  169. if (responseModel.codeState) {
  170. NSString *refreshToken = responseModel.data[@"refreshToken"];
  171. // 判断是否绑定手机号
  172. if (StringIsEmpty(refreshToken)) {
  173. BOOL needProfile = [responseModel.data[@"needProfile"] boolValue];
  174. // 是否是新用户
  175. if (needProfile) {
  176. // 新用户则跳转到设置信息界面
  177. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  178. BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:XYSetupUserInfoViewController.new];
  179. [[ApplicationDelegate getCurrentController] presentViewController:nav animated:NO completion:nil];
  180. }];
  181. }else {
  182. [self loginHandleSuccess:^(BOOL success) {
  183. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  184. }];
  185. }];
  186. }
  187. }else {
  188. // 不为空说明未绑定手机号 跳转到绑定手机号逻辑
  189. //关闭授权页
  190. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  191. // 跳转到其他登录界面
  192. XYLoginViewController *loginVC = [XYLoginViewController new];
  193. loginVC.sendCodeType = XY_Phone_Verification_Code_type_Binding;
  194. loginVC.refreshToken = refreshToken;
  195. BaseNavigationController *loginNav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
  196. [[ApplicationDelegate getCurrentController] presentViewController:loginNav animated:NO completion:nil];
  197. }];
  198. }
  199. }else {
  200. [SVProgressHUD showInfoWithStatus:responseModel.message];
  201. }
  202. }
  203. /// 创建一键登录的UI配置文件
  204. - (CLUIConfigure *)configureInitUI {
  205. CLUIConfigure * baseUIConfigure = [CLUIConfigure new];
  206. UIViewController *currentVC = [self getCurrentController];
  207. UIView *currentView = currentVC.view;
  208. // currentVC 为拉起授权页时的当前页面控制器
  209. baseUIConfigure.viewController = currentVC;
  210. // 导航条
  211. baseUIConfigure.clNavigationBackgroundClear = @(YES);
  212. baseUIConfigure.clNavigationBottomLineHidden = @(YES);
  213. baseUIConfigure.clNavigationAttributesTitleText = [[NSAttributedString alloc] initWithString:kLocalizedString(@"登录/注册") attributes:@{NSFontAttributeName:Font_B(20)}];
  214. baseUIConfigure.clNavigationTintColor = Color_TextFont;
  215. baseUIConfigure.clNavigationBarTintColor = Color_White;
  216. // 返回按钮
  217. baseUIConfigure.clNavigationLeftControl = [UIBarButtonItem customItemWithTitle:@"" titleColor:Color_TextFont imageName:@"icon_back" target:self selector:@selector(loginCancelAction:) contentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
  218. baseUIConfigure.clNavigationBackBtnHidden = @(YES);
  219. // logo
  220. baseUIConfigure.clLogoImage = ImageNamed(@"icon_logo_114");
  221. baseUIConfigure.clLogoCornerRadius = @(2.0f);
  222. //运营商品牌标签
  223. baseUIConfigure.clSloganTextColor = Color_TextGray;
  224. baseUIConfigure.clSloganTextFont = Font(12);
  225. baseUIConfigure.clSlogaTextAlignment = @(NSTextAlignmentCenter);
  226. // 手机号显示控件
  227. baseUIConfigure.clPhoneNumberColor = Color_TextFont;
  228. baseUIConfigure.clPhoneNumberFont = Font_B(24);
  229. baseUIConfigure.clPhoneNumberTextAlignment = @(NSTextAlignmentCenter);
  230. // 一键登录按钮 控件
  231. baseUIConfigure.clLoginBtnText = kLocalizedString(@"一键登录");
  232. baseUIConfigure.clLoginBtnTextColor = Color_White;
  233. baseUIConfigure.clLoginBtnTextFont = Font_B(18);
  234. baseUIConfigure.clLoginBtnNormalBgImage = [UIImage gradientColorImageFromColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#9059FF")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(SCREEN_WIDTH - 80.0f, 48.0f)];
  235. baseUIConfigure.clLoginBtnCornerRadius = @(8.0f);
  236. // 协议条款
  237. baseUIConfigure.clAppPrivacyColor = @[Color_TextGray, Color_Blue];
  238. baseUIConfigure.clAppPrivacyTextFont = Font(12);
  239. baseUIConfigure.clAppPrivacyTextAlignment = @(NSTextAlignmentLeft);
  240. baseUIConfigure.clAppPrivacyFirst = @[kLocalizedString(@"《用户协议》"),[NSURL URLWithString:App_User_Url]];
  241. baseUIConfigure.clAppPrivacySecond = @[kLocalizedString(@"《隐私协议》"),[NSURL URLWithString:App_Privacy_Url]];
  242. baseUIConfigure.clAppPrivacyNormalDesTextFirst = kLocalizedString(@"登录即代表您已同意");
  243. baseUIConfigure.clAppPrivacyPunctuationMarks = @(YES);
  244. baseUIConfigure.clAppPrivacyNormalDesTextSecond = @"";
  245. baseUIConfigure.clAppPrivacyNormalDesTextThird = @"";
  246. baseUIConfigure.clAppPrivacyNormalDesTextFourth = @"";
  247. baseUIConfigure.clAppPrivacyNormalDesTextLast = @"";
  248. // 闪验SLOGAN
  249. baseUIConfigure.clShanYanSloganHidden = @(YES);
  250. // 协议页
  251. baseUIConfigure.clAppPrivacyWebBackBtnImage = [UIImage imageNamed:@"title_back"];
  252. //CheckBox
  253. baseUIConfigure.clCheckBoxHidden = @(NO);
  254. baseUIConfigure.clCheckBoxValue = @(NO);
  255. baseUIConfigure.clCheckBoxSize = [NSValue valueWithCGSize:CGSizeMake(30.0f, 30.0f)];
  256. baseUIConfigure.clCheckBoxImageEdgeInsets = [NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
  257. baseUIConfigure.clCheckBoxVerticalAlignmentToAppPrivacyTop = @(YES);
  258. // baseUIConfigure.clCheckBoxVerticalAlignmentToAppPrivacyCenterY = @(YES);
  259. baseUIConfigure.clCheckBoxCheckedImage = [UIImage imageNamed:@"login_sure"];
  260. baseUIConfigure.clCheckBoxUncheckedImage = [UIImage imageNamed:@"login_unsure"];
  261. // 控件布局设置
  262. CGFloat screenWidth_Portrait;
  263. CGFloat screenHeight_Portrait;
  264. CGFloat screenWidth_Landscape;
  265. CGFloat screenHeight_Landscape;
  266. UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
  267. if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
  268. screenWidth_Portrait = UIScreen.mainScreen.bounds.size.width;
  269. screenHeight_Portrait = UIScreen.mainScreen.bounds.size.height;
  270. screenWidth_Landscape = UIScreen.mainScreen.bounds.size.height;
  271. screenHeight_Landscape = UIScreen.mainScreen.bounds.size.width;
  272. }else{
  273. screenWidth_Portrait = UIScreen.mainScreen.bounds.size.height;
  274. screenHeight_Portrait = UIScreen.mainScreen.bounds.size.width;
  275. screenWidth_Landscape = UIScreen.mainScreen.bounds.size.width;
  276. screenHeight_Landscape = UIScreen.mainScreen.bounds.size.height;
  277. }
  278. //layout 布局
  279. //布局-竖屏
  280. CLOrientationLayOut * clOrientationLayOutPortrait = [CLOrientationLayOut new];
  281. //一键登录按钮居中
  282. clOrientationLayOutPortrait.clLayoutLoginBtnCenterY = @(0);
  283. clOrientationLayOutPortrait.clLayoutLoginBtnHeight = @(48.0f);
  284. clOrientationLayOutPortrait.clLayoutLoginBtnLeft = @(40.0f);
  285. clOrientationLayOutPortrait.clLayoutLoginBtnRight = @(-40.0f);
  286. clOrientationLayOutPortrait.clLayoutPhoneCenterY = @(clOrientationLayOutPortrait.clLayoutLoginBtnCenterY.floatValue-20.0f-clOrientationLayOutPortrait.clLayoutLoginBtnHeight.floatValue);
  287. clOrientationLayOutPortrait.clLayoutPhoneLeft = @(40.0f);
  288. clOrientationLayOutPortrait.clLayoutPhoneRight = @(-40.0f);
  289. clOrientationLayOutPortrait.clLayoutPhoneHeight = @(33.0f);
  290. clOrientationLayOutPortrait.clLayoutLogoWidth = @(80.0f);
  291. clOrientationLayOutPortrait.clLayoutLogoHeight = @(80.0f);
  292. clOrientationLayOutPortrait.clLayoutLogoCenterX = @(0);
  293. clOrientationLayOutPortrait.clLayoutLogoTop = @(40.0f+NAVGATION_HEIGHT);
  294. clOrientationLayOutPortrait.clLayoutSloganLeft = @(40.0f);
  295. clOrientationLayOutPortrait.clLayoutSloganRight = @(-40.0f);
  296. clOrientationLayOutPortrait.clLayoutSloganHeight = @(17.0f);
  297. clOrientationLayOutPortrait.clLayoutSloganTop = @(clOrientationLayOutPortrait.clLayoutLogoTop.floatValue+clOrientationLayOutPortrait.clLayoutLogoHeight.floatValue+10.0f);
  298. clOrientationLayOutPortrait.clLayoutAppPrivacyLeft = @(60.0f);
  299. clOrientationLayOutPortrait.clLayoutAppPrivacyRight = @(-40.0f);
  300. clOrientationLayOutPortrait.clLayoutAppPrivacyBottom = @(-(20.0f+HOME_INDICATOR_HEIGHT));
  301. //自定义控件 其他登录
  302. __weak typeof(self) weakSelf = self;
  303. baseUIConfigure.customAreaView = ^(UIView * _Nonnull customAreaView) {
  304. __strong typeof(weakSelf) strongSelf = weakSelf;
  305. /// 第三方数组
  306. NSMutableArray *otherLoginItemArray = [NSMutableArray new];
  307. ///是否安装微信
  308. if ([XYSocialRegisterHandler isWXAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_WX_Login])) {
  309. [otherLoginItemArray addObject:Wechat_icon];
  310. }
  311. ///是否安装QQ
  312. if ([XYSocialRegisterHandler isQQAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_QQ_Login])) {
  313. [otherLoginItemArray addObject:QQ_icon];
  314. }
  315. // 是否安装微博
  316. if ([XYSocialRegisterHandler isSinaAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_Sina_Login])) {
  317. [otherLoginItemArray addObject:Sina_icon];
  318. }
  319. [otherLoginItemArray addObject:Phone_icon];
  320. XYOtherLoginView *otherLoginView = [[XYOtherLoginView alloc] initWithFrame:CGRectMake(40.0f, SCREEN_HEIGHT/2 + 24.0f + 40.0f, SCREEN_WIDTH-40.0f*2, 113.0f)];
  321. [otherLoginView setupLoginTypeDataWithArray:otherLoginItemArray selectCallback:^(NSInteger index) {
  322. /// 0微信 1QQ 2微博 3手机验证码
  323. NSString *itemName = otherLoginItemArray[index];
  324. if ([itemName isEqualToString:Wechat_icon]) {
  325. [strongSelf wxLoginActionWithLoginType:XY_Login_type_Quick_Login];
  326. }else if ([itemName isEqualToString:Sina_icon]) {
  327. [strongSelf sinaLoginActionWithLoginType:XY_Login_type_Quick_Login];
  328. }else if ([itemName isEqualToString:QQ_icon]) {
  329. [strongSelf QQLoginActionWithLoginType:XY_Login_type_Quick_Login];
  330. }else if ([itemName isEqualToString:Phone_icon]) {
  331. [strongSelf phoneCodeLoginActionWithLoginType:XY_Login_type_Quick_Login];
  332. }
  333. }];
  334. [customAreaView addSubview:otherLoginView];
  335. };
  336. baseUIConfigure.clOrientationLayOutPortrait = clOrientationLayOutPortrait;
  337. return baseUIConfigure;
  338. }
  339. #pragma mark — LoginAction
  340. /// 取消登录
  341. - (void)loginCancelAction:(id)sender {
  342. NSLog(@"取消登录了");
  343. // 用户取消登录(授权页点击返回) 【处理建议:若无特殊需求可不做处理】
  344. // 关闭授权页
  345. self.isLogin = NO;
  346. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:nil];
  347. }
  348. /// 微信登录
  349. - (void)wxLoginActionWithLoginType:(XY_Login_type)loginType {
  350. NSLog(@"微信登录");
  351. [[XYSocialRegisterHandler sharedInstance] wechatLogin:@"snsapi_userinfo" state:@"123" completion:^(BOOL success, id _Nonnull info) {
  352. if (success) {
  353. NSLog(@"微信授权成功code:%@", info)
  354. ///判断是否在闪验的授权页
  355. if (loginType == XY_Login_type_Quick_Login) {
  356. /// 在快捷登录界面(一键登录)
  357. [self byThirdPartyOAuthWithLoginType:XY_Login_type_WX_Login code:info];
  358. }else {
  359. /// 在其他登录界面 发送通知回调
  360. [NotificationCenter postNotificationName:WECHAT_LOGIN_SUCCESS_NOTIFICATION object:@{@"code":info}];
  361. }
  362. }
  363. }];
  364. }
  365. /// qq登录
  366. - (void)QQLoginActionWithLoginType:(XY_Login_type)loginType {
  367. NSLog(@"QQ登录");
  368. [[XYSocialRegisterHandler sharedInstance] qqLoginCompletion:^(BOOL success, id _Nonnull info) {
  369. if (success) {
  370. NSLog(@"qq授权成功code:%@", info);
  371. ///判断是否在闪验的授权页
  372. if (loginType == XY_Login_type_Quick_Login) {
  373. /// 在快捷登录界面(一键登录)
  374. [self byThirdPartyOAuthWithLoginType:XY_Login_type_QQ_Login code:info];
  375. }else {
  376. /// 在其他登录界面 发送通知回调
  377. [NotificationCenter postNotificationName:QQ_LOGIN_SUCCESS_NOTIFICATION object:@{@"code":info}];
  378. }
  379. }
  380. }];
  381. }
  382. /// 新浪微博登录
  383. - (void)sinaLoginActionWithLoginType:(XY_Login_type)loginType {
  384. NSLog(@"微博登录");
  385. [[XYSocialRegisterHandler sharedInstance] sinaLoginCompletion:^(BOOL success, id _Nonnull info) {
  386. if (success) {
  387. NSLog(@"qq授权成功code:%@", info);
  388. ///判断是否在闪验的授权页
  389. if (loginType == XY_Login_type_Quick_Login) {
  390. /// 在快捷登录界面(一键登录)
  391. [self byThirdPartyOAuthWithLoginType:XY_Login_type_Sina_Login code:info];
  392. }else {
  393. /// 在其他登录界面 发送通知回调
  394. [NotificationCenter postNotificationName:SINA_LOGIN_SUCCESS_NOTIFICATION object:@{@"code":info}];
  395. }
  396. }
  397. }];
  398. }
  399. /// 手机号验证码登录
  400. - (void)phoneCodeLoginActionWithLoginType:(XY_Login_type)loginType {
  401. NSLog(@"验证码登录");
  402. //关闭授权页
  403. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  404. // 跳转到其他登录界面
  405. [self createLoginPageVC];
  406. }];
  407. }
  408. - (void)byThirdPartyOAuthWithLoginType:(XY_Login_type)loginType code:(NSString *)code {
  409. kWEAKSELF
  410. [[XYUserAPIManager new] byThirdPartyOAuthWithType:loginType code:code inviteCode:@"" successHandler:^(ZYLResponseModel *responseModel) {
  411. BOOL isCoolPeriod = [[AppDelegate sharedDelegate] isCoolPeriod:responseModel.data];
  412. [AppDelegate sharedDelegate].XYCoolPeriodAgainLogin = ^(BOOL success) {
  413. [weakSelf parseThirdLoginResponseModel:responseModel];
  414. };
  415. if (isCoolPeriod) {
  416. return;
  417. }
  418. [weakSelf parseThirdLoginResponseModel:responseModel];
  419. } failureHandler:^(NSError *error) {
  420. [SVProgressHUD showInfoWithStatus:error.domain];
  421. }];
  422. }
  423. - (void)parseThirdLoginResponseModel:(ZYLResponseModel *)responseModel{
  424. kWEAKSELF
  425. if (responseModel.codeState) {
  426. NSString *refreshToken = responseModel.data[@"refreshToken"];
  427. // 判断是否绑定手机号
  428. if (StringIsEmpty(refreshToken)) {
  429. BOOL needProfile = [responseModel.data[@"needProfile"] boolValue];
  430. // 是否是新用户
  431. if (needProfile) {
  432. // 新用户则跳转到设置信息界面
  433. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  434. BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:XYSetupUserInfoViewController.new];
  435. [[ApplicationDelegate getCurrentController] presentViewController:nav animated:NO completion:nil];
  436. }];
  437. }else {
  438. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  439. [weakSelf loginHandleSuccess:nil];
  440. }];
  441. }
  442. }else {
  443. // 不为空说明未绑定手机号 跳转到绑定手机号逻辑
  444. //关闭授权页
  445. [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
  446. // 跳转到其他登录界面
  447. XYLoginViewController *loginVC = [XYLoginViewController new];
  448. loginVC.sendCodeType = XY_Phone_Verification_Code_type_Binding;
  449. loginVC.refreshToken = refreshToken;
  450. BaseNavigationController *loginNav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
  451. [[ApplicationDelegate getCurrentController] presentViewController:loginNav animated:NO completion:nil];
  452. }];
  453. }
  454. }else {
  455. [SVProgressHUD showInfoWithStatus:responseModel.message];
  456. }
  457. }
  458. /// 登录成功后,先获取详细个人信息,然后登录第三方
  459. - (void)loginHandleSuccess:(void(^ _Nullable)(BOOL success))block {
  460. // 1.获取详细个人信息
  461. [[XYUserInfoManager sharedInstance] updataUserInfoSuccess:^(BOOL isSuccess) {
  462. NSLog(@"1.获取详细个人信息返回");
  463. [Bugly setUserIdentifier:[XYUserInfoManager nowUser].userNo];//Bugly用户标示
  464. // 2.获取数据登录第三方
  465. [self loginReqeustData:^(BOOL success) {
  466. NSLog(@"2.获取数据登录第三方返回");
  467. // 3.发送登录通知
  468. [NotificationCenter postNotificationName:USER_LOGIN_STATUS_NOTIFICATION object:nil];
  469. //登录成功获取通知权限
  470. UIApplication *ap = [UIApplication sharedApplication];
  471. [self registerAPNS:ap];
  472. !block?:block(YES);
  473. }];
  474. }];
  475. }
  476. - (void)loginReqeustData:(void(^)(BOOL success))block {
  477. dispatch_group_t group = dispatch_group_create();
  478. dispatch_queue_t queue = dispatch_queue_create("login.data", DISPATCH_QUEUE_SERIAL);
  479. dispatch_group_enter(group);
  480. dispatch_async(queue, ^{
  481. // 登录im
  482. [[XYIMBaseManager sharedInstance] im_loginWithToken:[XYUserInfoManager nowUser].rtmToken complete:^(BOOL success) {
  483. dispatch_group_leave(group);
  484. }];
  485. });
  486. NSString *deviceId = [CloudPushSDK getDeviceId];
  487. if (StringIsNotEmpty(deviceId)) {
  488. dispatch_group_enter(group);
  489. dispatch_async(queue, ^{
  490. // 推送注册设备
  491. [[XYConfigAPIManager new] registerDeviceWithDeviceId:deviceId successHandler:^(ZYLResponseModel *responseModel) {
  492. dispatch_group_leave(group);
  493. } failureHandler:^(ZYLNetworkError *error) {
  494. dispatch_group_leave(group);
  495. }];
  496. });
  497. }
  498. dispatch_group_notify(group, queue, ^{
  499. dispatch_async(dispatch_get_main_queue(), ^{
  500. [[YQAnmationResourceMag sharedInstance] bagGetGiftList];
  501. !block?:block(YES);
  502. });
  503. });
  504. }
  505. /// 退出登录
  506. - (void)logoutHandleSuccess:(void(^ _Nullable)(BOOL success))block {
  507. // 1.修改本地登录状态
  508. User *nowUser = [DataBase nowUser];
  509. nowUser.loginStatus = 0;
  510. [DataBase commitDataBase];
  511. [[XYUserInfoManager sharedInstance] userLogoutBlock:nil];
  512. // 动态、派单未读数量重置
  513. [[XYIMUnReadCountManager sharedInstance] reset];
  514. // 2.IM退出
  515. if ([XYChatRoomManager sharedInstance].isChatRooming) {
  516. [[XYChatRoomManager sharedInstance] closeChatRoomBlock:^{
  517. [[XYIMBaseManager sharedInstance] im_logoutComplete:^(BOOL success) {
  518. // 2.2发送刷新UI通知
  519. [NotificationCenter postNotificationName:USER_LOGIN_STATUS_NOTIFICATION object:nil];
  520. [[self getCurrentController].navigationController popToRootViewControllerAnimated:NO];
  521. !block?:block(YES);
  522. }];
  523. }];
  524. }else {
  525. [[XYIMBaseManager sharedInstance] im_logoutComplete:^(BOOL success) {
  526. // 2.2发送刷新UI通知
  527. [NotificationCenter postNotificationName:USER_LOGIN_STATUS_NOTIFICATION object:nil];
  528. [[self getCurrentController].navigationController popToRootViewControllerAnimated:NO];
  529. !block?:block(YES);
  530. }];
  531. }
  532. // 3.隐藏tabbar消息提示
  533. [ApplicationDelegate.tabbarVC.tabBarController.tabBar hideBadgeOnItemIndex:(ApplicationDelegate.tabbarVC.tabBarController.viewControllers.count-2)];
  534. // 4.删除NSUserDefaults保存的信息
  535. if ([XYLiveManger shareInstance].AppLogoutBlock) {
  536. [XYLiveManger shareInstance].AppLogoutBlock(YES);
  537. }
  538. // 6.推送解绑账号
  539. [ApplicationDelegate push_unbindAccount:^(BOOL succes) {
  540. }];
  541. [Bugly setUserIdentifier:@"1000000"];//Bugly默认用户标示,统计进入首页之前的crash
  542. }
  543. @end