123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- //
- // RQCycleScrollView.m
- // jiaPei
- //
- // Created by 张嵘 on 2021/6/24.
- // Copyright © 2021 JCZ. All rights reserved.
- //
- #import "RQCycleScrollView.h"
- #import "WXApiManager.h"
- #import "WechatAuthSDK.h"
- @interface RQCycleScrollView () <SDCycleScrollViewDelegate, WXApiManagerDelegate, WechatAuthAPIDelegate>
- @property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView;
- @property (nonatomic, readwrite, strong) NSMutableArray *newImageURLStringsGroup;
- @property (nonatomic, readwrite, strong) NSMutableArray *newDataArr;
- @end
- @implementation RQCycleScrollView
- #pragma mark - PublicMethods
- - (instancetype)initWithFrame:(CGRect)frame dataArr:(NSArray *)dataArr {
- self = [super initWithFrame:frame];
- if (self) {
- [self addSubview:self.cycleScrollView];
- self.cycleScrollView.size = self.size;
- [self dataProcessWithDataArr:dataArr];
- [WXApiManager sharedManager].delegate = self;
- }
- return self;
- }
- - (void)updateDataArr:(NSArray *)dataArr {
- [self dataProcessWithDataArr:dataArr];
- }
- #pragma mark - PrivateMethods
- - (void)dataProcessWithDataArr:(NSArray *)dataArr {
- @weakify(self)
- if (self.newDataArr.count > 0) {
- [self.newDataArr removeAllObjects];
- }
- [self.newDataArr addObjectsFromArray:dataArr];
- [[self.newDataArr.rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSDictionary *dic) {
- @strongify(self)
- [self.newImageURLStringsGroup addObject:dic[@"IMG"]];
- } completed:^{
- @strongify(self)
- if (self.newImageURLStringsGroup.count >= 1) {
- [self.newImageURLStringsGroup insertObject:@"RQ-AD" atIndex:1];
- } else {
- [self.newImageURLStringsGroup addObject:@"RQ-AD"];
- }
- self.cycleScrollView.imageURLStringsGroup = self.newImageURLStringsGroup;
- }];
-
- }
- #pragma mark - SDCycleScrollViewDelegate
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
- if (self.newDataArr.count >= 1) {
- if (index == 1) return;
- } else {
- if (index >= self.newDataArr.count) return;
- }
- NSLog(@"---点击了第%ld张图片----%@", (long)index, self.newDataArr[index][@"LOCATION"]);
-
- NSDictionary *dic = self.newDataArr[index];
- [RQ_SHARE_FUNCTION saveObjectWithObject:dic ForKey:@"currentSelectDic"];
-
- NSString *skipType = dic[@"OPENTYPE"];
- if ([skipType isEqualToString:@"1"]) {
- [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:dic[@"URL"]];
- }else{
- if ([dic[@"ADTYPE"] isEqualToString:@"2"]) {
- [RQ_SHARE_FUNCTION miniwithUserName:dic[@"URL"] path:dic[@"AI_XCX_URL"]? : @""];
- } else if ([dic[@"ADTYPE"] isEqualToString:@"1"]) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]] options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:nil];
- } else if ([dic[@"ADTYPE"] isEqualToString:@"3"]) {
- // [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
- // NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
- // }];
- // return;
- WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
- req.scene = 1;
- req.templateId = @"1iZwYeI2QtSXZ3rTRkQ42wgRkd7NSINzem8R-LvtHYw";
- req.reserved = @"";
- [WXApi sendReq:req completion:nil];
- }
- }
-
- }
- #pragma mark - WXApiManagerDelegate
- - (void)managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *)response {
- NSDictionary *currentSelectDic = [RQ_SHARE_FUNCTION getObjectWithKey:@"currentSelectDic"];
- NSMutableArray *arr = [NSMutableArray array];
-
- [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"StudentoutID"];
- [jiaPeiManager requestAnythingWithURL:@"getToken" array:arr data:nil completion:^(NSDictionary *dic) {
- if ([dic[@"code"] intValue] == 0) {
- [jiaPeiManager requestAnythingWithURL:[NSString stringWithFormat:@"https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=%@",dic[@"body"]] array:@[
- @{@"touser" : response.openId? : @""},
- @{@"template_id" : response.templateId? : @""},
- @{@"url" : currentSelectDic[@"URL"]? : @"https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzk0MTI1ODAyMA==#wechat_redirect"},
- @{@"scene" : [NSNumber numberWithInt:response.scene]},
- @{@"title" : currentSelectDic[@"TITLE"]? : @"消息"},
- @{@"data" : @{@"content":@{@"color":@"#173177",@"value":currentSelectDic[@"AI_CONTENT"]? : @"点击关注公众号"}}}
- ].mutableCopy data:nil completion:^(NSDictionary *dict) {
- if ([dict[@"errcode"] integerValue] == 0) {
- dispatch_async(dispatch_get_main_queue(), ^{
- ShowMsg(@"成功");
- });
- } else {
- ShowMsg(@"失败");
- }
- }];
- } else {
- ShowMsg(@"获取token失败");
- }
- }];
- }
- #pragma mark - LazyLoad
- - (SDCycleScrollView *)cycleScrollView {
- if (!_cycleScrollView) {
- _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SHARE_FUNCTION.RQADViewHeight) delegate:self placeholderImage:[UIImage imageNamed:@"subject_main_banner"]];
- _cycleScrollView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
- _cycleScrollView.autoScrollTimeInterval = 10;
- _cycleScrollView.backgroundColor = UIColor.whiteColor;
- }
- return _cycleScrollView;
- }
- - (NSMutableArray *)newImageURLStringsGroup {
- if (!_newImageURLStringsGroup) {
- _newImageURLStringsGroup = [NSMutableArray array];
- }
- return _newImageURLStringsGroup;
- }
- - (NSMutableArray *)newDataArr {
- if (!_newDataArr) {
- _newDataArr = [NSMutableArray array];
- }
- return _newDataArr;
- }
- @end
|