BlackDoorManager+click.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // BlackDoorManager+click.m
  3. // SikeyComm
  4. //
  5. // Created by 刘振兴 on 2025/2/25.
  6. // Copyright © 2025 BaH Cy. All rights reserved.
  7. //
  8. #import "BlackDoorManager+click.h"
  9. #import "BlackDoorManager+data.h"
  10. #define KEY_BDM_USERCLICK_HEADER @"@BDM*"
  11. #define KEY_BDM_CLICK_TAG 1234567890
  12. #define BDM_BUTTON_CLICK_SIZE 90
  13. #define BDM_BUTTON_SERVER_SIZE_WIDTH 120
  14. #define BDM_BUTTON_SERVER_SIZE_HEIGHT 50
  15. #define TIME_INTERVAL_MAX 8
  16. #define BDM_CLICK_ORDER @"323"
  17. @implementation BlackDoorManager (click)
  18. + (void)addBlackDoorButtons:(UIView*)supperView {
  19. for (NSInteger i = 1; i <= 4; i++) {
  20. UIButton* button = [[UIButton alloc] init];
  21. button.tag = KEY_BDM_CLICK_TAG + i;
  22. [button setBackgroundColor:[UIColor clearColor]];
  23. [supperView addSubview:button];
  24. CGFloat x = ((i == 1) || (i == 3))? 0 : (BDM_SCREEN_WIDTH - BDM_BUTTON_CLICK_SIZE);
  25. CGFloat y = ((i == 1) || (i == 2))? 60 : (BDM_SCREEN_HEIGHT - BDM_BUTTON_CLICK_SIZE) - 40;
  26. [button setFrame:CGRectMake(x, y, BDM_BUTTON_CLICK_SIZE, BDM_BUTTON_CLICK_SIZE)];
  27. [button addTarget:self action:@selector(blButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  28. }
  29. }
  30. + (void)blButtonClick:(UIButton*)button {
  31. NSInteger index = button.tag % KEY_BDM_CLICK_TAG ;
  32. NSLog(@"BlackDoorManager: index:%ld", (long)index);
  33. [self blButtonClickEx:index supperView:[button superview]];
  34. }
  35. + (void)blButtonClickEx:(NSInteger)index supperView:(UIView*)supperView {
  36. switch (index) {
  37. case 1: {
  38. //清空点击消息
  39. [self clearUserClickInfo];
  40. NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
  41. NSString *info = [NSString stringWithFormat:@"%@_%@_",KEY_BDM_USERCLICK_HEADER, @(timestamp)];
  42. [self setUserClickInfo:info];
  43. break;
  44. }
  45. case 2:
  46. case 3: {
  47. //点击信息不全
  48. NSString* info = [self getUserClickInfo];
  49. NSArray* array = [info componentsSeparatedByString:@"_"];
  50. if (array.count < 2) {
  51. [self showTosat:@"请重新点击(跳点)" supperView:supperView];
  52. [self clearUserClickInfo];
  53. break;
  54. }
  55. //验证头字串不对
  56. NSString* header = array[0];
  57. if (![header isEqualToString:KEY_BDM_USERCLICK_HEADER]) {
  58. [self showTosat:@"请重新点击(校验错误)" supperView:supperView];
  59. [self clearUserClickInfo];
  60. break;
  61. }
  62. [self setUserClickInfo:[NSString stringWithFormat:@"%@%@", info, @(index)]];
  63. break;
  64. }
  65. case 4: {
  66. //点击信息不全
  67. NSString* info = [self getUserClickInfo];
  68. NSArray* array = [info componentsSeparatedByString:@"_"];
  69. if (array.count < 3) {
  70. [self showTosat:@"请重新点击(跳点)" supperView:supperView];
  71. [self clearUserClickInfo];
  72. break;
  73. }
  74. //验证头字串不对
  75. NSString* header = array[0];
  76. if (![header isEqualToString:KEY_BDM_USERCLICK_HEADER]) {
  77. [self showTosat:@"请重新点击(校验错误)" supperView:supperView];
  78. [self clearUserClickInfo];
  79. break;
  80. }
  81. //点击超时
  82. NSTimeInterval beginTime = [array[1] integerValue];
  83. NSTimeInterval nowTime = [[NSDate date] timeIntervalSince1970];
  84. if (nowTime > beginTime && (nowTime - beginTime > TIME_INTERVAL_MAX)) {
  85. [self showTosat:[NSString stringWithFormat:@"请重新点击(%d秒超时)", TIME_INTERVAL_MAX] supperView:supperView];
  86. [self clearUserClickInfo];
  87. break;
  88. }
  89. //点击顺序不对
  90. NSString* order = array[2];
  91. if (![order isEqualToString:BDM_CLICK_ORDER]) {
  92. [self showTosat:@"请重新点击(顺序不对)" supperView:supperView];
  93. [self clearUserClickInfo];
  94. break;
  95. }
  96. //验证通过
  97. [self showBlackDoorView:supperView];
  98. break;
  99. }
  100. default:
  101. break;
  102. }
  103. }
  104. //验证通过
  105. + (void)showBlackDoorView:(UIView*)supperView {
  106. BlackDoorManager* view = [[BlackDoorManager alloc] initWithFrame:supperView.bounds];
  107. [supperView addSubview:view];
  108. }
  109. + (void)showTosat:(NSString *)strMsg supperView:(UIView*)supperView {
  110. NSInteger serverType = [ServerManager getServerType];
  111. if (serverType == 0)
  112. return;
  113. [EasyTextView showText:strMsg];
  114. }
  115. @end