RQCycleScrollView.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // RQCycleScrollView.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2021/6/24.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import "RQCycleScrollView.h"
  9. #import "WXApiManager.h"
  10. #import "WechatAuthSDK.h"
  11. @interface RQCycleScrollView () <SDCycleScrollViewDelegate, WXApiManagerDelegate, WechatAuthAPIDelegate>
  12. @property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView;
  13. @property (nonatomic, readwrite, strong) NSMutableArray *newImageURLStringsGroup;
  14. @property (nonatomic, readwrite, strong) NSMutableArray *newDataArr;
  15. @end
  16. @implementation RQCycleScrollView
  17. #pragma mark - PublicMethods
  18. - (instancetype)initWithFrame:(CGRect)frame dataArr:(NSArray *)dataArr {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self addSubview:self.cycleScrollView];
  22. self.cycleScrollView.size = self.size;
  23. [self dataProcessWithDataArr:dataArr];
  24. [WXApiManager sharedManager].delegate = self;
  25. }
  26. return self;
  27. }
  28. - (void)updateDataArr:(NSArray *)dataArr {
  29. [self dataProcessWithDataArr:dataArr];
  30. }
  31. #pragma mark - PrivateMethods
  32. - (void)dataProcessWithDataArr:(NSArray *)dataArr {
  33. @weakify(self)
  34. if (self.newDataArr.count > 0) {
  35. [self.newDataArr removeAllObjects];
  36. }
  37. [self.newDataArr addObjectsFromArray:dataArr];
  38. [[self.newDataArr.rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSDictionary *dic) {
  39. @strongify(self)
  40. [self.newImageURLStringsGroup addObject:dic[@"IMG"]];
  41. } completed:^{
  42. @strongify(self)
  43. if (self.newImageURLStringsGroup.count >= 1) {
  44. [self.newImageURLStringsGroup insertObject:@"RQ-AD" atIndex:1];
  45. } else {
  46. [self.newImageURLStringsGroup addObject:@"RQ-AD"];
  47. }
  48. self.cycleScrollView.imageURLStringsGroup = self.newImageURLStringsGroup;
  49. }];
  50. }
  51. #pragma mark - SDCycleScrollViewDelegate
  52. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  53. if (self.newDataArr.count >= 1) {
  54. if (index == 1) return;
  55. } else {
  56. if (index >= self.newDataArr.count) return;
  57. }
  58. NSLog(@"---点击了第%ld张图片----%@", (long)index, self.newDataArr[index][@"LOCATION"]);
  59. NSDictionary *dic = self.newDataArr[index];
  60. [RQ_SHARE_FUNCTION saveObjectWithObject:dic ForKey:@"currentSelectDic"];
  61. NSString *skipType = dic[@"OPENTYPE"];
  62. if ([skipType isEqualToString:@"1"]) {
  63. [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:dic[@"URL"]];
  64. }else{
  65. if ([dic[@"ADTYPE"] isEqualToString:@"2"]) {
  66. [RQ_SHARE_FUNCTION miniwithUserName:dic[@"URL"] path:dic[@"AI_XCX_URL"]? : @""];
  67. } else if ([dic[@"ADTYPE"] isEqualToString:@"1"]) {
  68. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]] options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:nil];
  69. } else if ([dic[@"ADTYPE"] isEqualToString:@"3"]) {
  70. // [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
  71. // NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
  72. // }];
  73. // return;
  74. WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
  75. req.scene = 1;
  76. req.templateId = @"1iZwYeI2QtSXZ3rTRkQ42wgRkd7NSINzem8R-LvtHYw";
  77. req.reserved = @"";
  78. [WXApi sendReq:req completion:nil];
  79. }
  80. }
  81. }
  82. #pragma mark - WXApiManagerDelegate
  83. - (void)managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *)response {
  84. NSDictionary *currentSelectDic = [RQ_SHARE_FUNCTION getObjectWithKey:@"currentSelectDic"];
  85. NSMutableArray *arr = [NSMutableArray array];
  86. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"StudentoutID"];
  87. [jiaPeiManager requestAnythingWithURL:@"getToken" array:arr data:nil completion:^(NSDictionary *dic) {
  88. if ([dic[@"code"] intValue] == 0) {
  89. [jiaPeiManager requestAnythingWithURL:[NSString stringWithFormat:@"https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=%@",dic[@"body"]] array:@[
  90. @{@"touser" : response.openId? : @""},
  91. @{@"template_id" : response.templateId? : @""},
  92. @{@"url" : currentSelectDic[@"URL"]? : @"https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzk0MTI1ODAyMA==#wechat_redirect"},
  93. @{@"scene" : [NSNumber numberWithInt:response.scene]},
  94. @{@"title" : currentSelectDic[@"TITLE"]? : @"消息"},
  95. @{@"data" : @{@"content":@{@"color":@"#173177",@"value":currentSelectDic[@"AI_CONTENT"]? : @"点击关注公众号"}}}
  96. ].mutableCopy data:nil completion:^(NSDictionary *dict) {
  97. if ([dict[@"errcode"] integerValue] == 0) {
  98. dispatch_async(dispatch_get_main_queue(), ^{
  99. ShowMsg(@"成功");
  100. });
  101. } else {
  102. ShowMsg(@"失败");
  103. }
  104. }];
  105. } else {
  106. ShowMsg(@"获取token失败");
  107. }
  108. }];
  109. }
  110. #pragma mark - LazyLoad
  111. - (SDCycleScrollView *)cycleScrollView {
  112. if (!_cycleScrollView) {
  113. _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SHARE_FUNCTION.RQADViewHeight) delegate:self placeholderImage:[UIImage imageNamed:@"subject_main_banner"]];
  114. _cycleScrollView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
  115. _cycleScrollView.autoScrollTimeInterval = 10;
  116. _cycleScrollView.backgroundColor = UIColor.whiteColor;
  117. }
  118. return _cycleScrollView;
  119. }
  120. - (NSMutableArray *)newImageURLStringsGroup {
  121. if (!_newImageURLStringsGroup) {
  122. _newImageURLStringsGroup = [NSMutableArray array];
  123. }
  124. return _newImageURLStringsGroup;
  125. }
  126. - (NSMutableArray *)newDataArr {
  127. if (!_newDataArr) {
  128. _newDataArr = [NSMutableArray array];
  129. }
  130. return _newDataArr;
  131. }
  132. @end