自动领取红包流程分析
1.首先是获取直播列表(采用定时10秒刷新一次)
2.检测列表中是否有红包 -----> 如果有就保存起来
3.开启定时任务,每秒查询是否有可领取红包 -----> 如果有就直接领取
目录
开始代码
获取直播列表(10秒/次)
获取直播列表 Call
检查直播间是否有红包 Call (并保存)
查询红包列表是否可领取(1秒/次)
查询红包列表是否可领取 Call(并打开)
打开直播红包 Call
+(void)yyyyyyyyyyyyy
{
if(![xddCode sharedInstance].isbOpenZDZB){
[xddCode sharedInstance].isbOpenZDZB = YES;
}else{
[UIView xx_makeBottomToast:@"已开启过了 直播"];
return;
}
//开始子线程
dispatch_async(dispatch_get_global_queue(0, 0), ^{
while (1==1) {
NSLog(@"正在自动获取直播列表%d次",1);
//获取直播列表
dispatch_async(dispatch_get_main_queue(), ^{
[self getZBlist];//获取直播列表Call
});
[NSThread sleepForTimeInterval:10];
}
});//end 子线程
}
+(void)getZBlist{
//3条
NSString*url =@"https://webcast.amemv.com/webcast/feed/?cate_id=0&channel_id=21&content_type=0&req_type=0&show_location=0&style=3&sub_channel_id=0&sub_type=live_merge&tab_id=1&type=live&version_code=10.8.0&pass-region=0&js_sdk_version=1.60.0.7&pass-route=0&webcast_sdk_version=1490&app_name=aweme&vid=C8A909E5-93B8-42D9-A5D5-A08837C7A5A7&app_version=10.8.0&language=zh-Hans-CN&device_id=70838725526&channel=App%20Store&mcc_mnc=46001&aid=1128&effect_sdk_version=6.6.0&screen_width=414&openudid=6a25c6406978cbd05928fb03732716a39a0d04e3&cdid=59542D4F-CEB8-46FA-831C-410B2ED0E559&os_api=18&webcast_language=zh&ac=WIFI&os_version=12.3.1&webcast_locale=zh-Hans_CN&device_platform=iphone&build_number=108013&iid=8440917271405&device_type=iPhone%20XS%20Max&is_vcd=1&idfa=6B369BA0-9628-44D0-8491-FD101C292057";
// 12条
url = @"https://webcast.amemv.com/webcast/feed/?cate_id=0&channel_id=21&content_type=0&req_type=0&show_location=0&style=2&sub_channel_id=0&sub_type=live_merge&tab_id=1&type=live&version_code=10.8.0&pass-region=0&js_sdk_version=1.60.0.7&pass-route=0&webcast_sdk_version=1490&app_name=aweme&vid=CC8E166D-34AB-424A-8EA9-DE0AFC223AF8&app_version=10.8.0&language=zh-Hans-CN&device_id=70854743357&channel=App%20Store&mcc_mnc=46004&aid=1128&effect_sdk_version=6.6.0&screen_width=810&openudid=4ae728e375c1adb5f462d043017363fa981e22d7&cdid=632ED61F-EAE0-47DC-A0B5-0F4951F9A075&os_api=18&webcast_language=zh&ac=WIFI&os_version=13.3&webcast_locale=zh-Hans_CN&device_platform=ipad&build_number=108013&iid=3737984599082238&device_type=iPad7,12&is_vcd=1&idfa=FD639131-0F34-4331-965B-B5B6F67DA31C";
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"refresh",@"action",
@"enter_auto_feed_draw_refresh",@"req_from",
nil];
// a __NSFrozenDictionaryM *
[NSClassFromString(@"AWENetworkService") _requestWithURLString:url params:params method:@"GET" needCommonParams:false header:nil modelClass:nil targetAttributes:nil requestSerializer:nil responseSerializer:nil responseBlock:nil enableCache:false completionBlock:^(NSDictionary *m, NSError*err) {
NSLog(@"获取直播数据=%@",m);
if(err){
NSString*msg = @"获取直播数据失败";
dispatch_async(dispatch_get_main_queue(), ^{
[UIView xx_makeBottomToast:msg];
[xddTools sharedInstance].isGuanzZhuErr = YES;
});
}else{
NSArray* dataArr = m[@"data"];
for (NSDictionary *dic in dataArr) {
NSString*id_str = dic[@"data"][@"id_str"];// @"id_str" : @"6833438820730407680"
[self ishongbao:id_str];//检查直播间是否有红包
}
dispatch_async(dispatch_get_main_queue(), ^{
[UIView xx_makeBottomToast:@"获取直播数据成功"];
});
}
}];
}
+(void)ishongbao:(NSString*)room_id{
NSString*url = @"";
url = @"https://webcast.amemv.com/webcast/luckybox/box/list/?aid=1128";
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
room_id,@"room_id",
nil];
//[0] (null) "room_id" : 6833440747308452612
[NSClassFromString(@"AWENetworkService") _requestWithURLString:url params:params method:@"GET" needCommonParams:false header:nil modelClass:nil targetAttributes:nil requestSerializer:nil responseSerializer:nil responseBlock:nil enableCache:false completionBlock:^(NSDictionary *m, NSError*err) {
NSLog(@"获取直播红包=%@",m);
if(err){
NSString*msg = @"获取直播红包失败";
dispatch_async(dispatch_get_main_queue(), ^{
[UIView xx_makeBottomToast:msg];
[xddTools sharedInstance].isGuanzZhuErr = YES;
});
}else{
int hbcount = 0;
NSArray* dataArr = m[@"data"];
long now = [m[@"extra"][@"now"] longLongValue];
long nowMy = [[NSString stringWithFormat:@"%ld000",(long)[[NSDate date] timeIntervalSince1970]] longLongValue];
//红包类型
//room_id [3] (null) @"business_type" : (long)700 混合
for (NSDictionary *dic in dataArr) {
NSString*send_time = dic[@"send_time"];
NSString*box_type = dic[@"box_type"];
NSString*box_id = dic[@"box_id"];
NSString*delay_time = dic[@"delay_time"];
NSString*title = dic[@"title"];
NSString*diamond_count = dic[@"diamond_count"];
// [0] (null) @"style" : (long)0
// [1] (null) @"is_official" : NO
// [2] (null) @"description_list" : @"2 elements"
// [3] (null) @"business_type" : (long)700
// [4] (null) @"send_time" : (long)1591036244000
// [5] (null) @"box_status" : (long)0
// [6] (null) @"display_duration" : (long)0
// [7] (null) @"box_id" : (long)6833430664709229319
// [8] (null) @"flat_duration" : (long)0
// [9] (null) @"priority" : (long)0
// [10] (null) @"title" : @"礼物红包"
// [11] (null) @"box_type" : (long)1
// [12] (null) @"delay_time" : (long)300
// [13] (null) @"unpack_type" : (long)0
// [14] (null) @"rush_condition" : (long)0
// [15] (null) @"large" : NO
// [16] (null) @"user" : 86 key/value pairs
// [17] (null) @"diamond_count" : (long)20
HongbDB * f = [HongbDB creatWithDic:dic room_id:room_id];
[f bg_saveOrUpdate];//保存到数据库,红包信息
}
if(dataArr && dataArr.count > 0){
NSString*showMsg = [NSString stringWithFormat:@"直播间ID:%@,红包数:%lu",room_id,(unsigned long)dataArr.count];
dispatch_async(dispatch_get_main_queue(), ^{
[UIView xx_makeBottomToast:showMsg];
});
}
}
}];
}
+(void)xxxxxxxxx
{
if(![xddCode sharedInstance].isbOpenZDHB){
[xddCode sharedInstance].isbOpenZDHB = YES;
}else{
[UIView xx_makeBottomToast:@"已开启过了 红包"];
return;
}
//开始子线程
dispatch_async(dispatch_get_global_queue(0, 0), ^{
while (1==1) {
NSLog(@"正在自动领取红包%d次",1);
//正在自动领取列表
dispatch_async(dispatch_get_main_queue(), ^{
[self HBFind];//查询红包类别,并自动领取
});
[NSThread sleepForTimeInterval:1];
}
});//end 子线程
}
+(void)HBFind
{
// [0] (null) "send_time" : 1591037464000
// [1] (null) "box_type" : 1
// [2] (null) "box_id" : 6833407923390302988
// [3] (null) "room_id" : "6833369141693713167"
// [4] (null) "delay_time" : 300
//查询所有红包数据.
NSArray * finfAlls = [HongbDB bg_findAll:@"HongbDB"];
NSString *timeSp = [NSString stringWithFormat:@"%ld000",(long)[[NSDate date] timeIntervalSince1970]];
long now = [timeSp longLongValue];
for(HongbDB *fd in finfAlls)
{
long send_time = [fd send_time];
long box_type = [fd box_type];
long box_id = [fd box_id];
NSString* room_id = [fd room_id];
long delay_time = [fd delay_time];
long opentime = send_time + (delay_time*1000);
NSString* title = [fd title];
//是否可领取红包
if(now >= opentime ){
//打开红包
[self HBopeng:room_id send_time:send_time box_type:box_type box_id:box_id delay_time:delay_time];
}
NSLog(@"%@ 红包ID:%ld,时间:%ld",title,box_id,send_time);
}
}
+(void)HBopeng:(NSString*)room_id send_time:(long)send_time box_type:(long)box_type box_id:(long)box_id delay_time:(long)delay_time{
// [0] (null) "send_time" : 1591037464000
// [1] (null) "box_type" : 1
// [2] (null) "box_id" : 6833407923390302988
// [3] (null) "room_id" : "6833369141693713167"
// [4] (null) "delay_time" : 300
NSString*url = @"https://webcast.amemv.com/webcast/luckybox/rush/?version_code=10.8.0&pass-region=0&js_sdk_version=1.60.0.7&pass-route=0&webcast_sdk_version=1490&app_name=aweme&vid=C8A909E5-93B8-42D9-A5D5-A08837C7A5A7&app_version=10.8.0&language=zh-Hans-CN&device_id=70838725526&channel=App%20Store&mcc_mnc=46001&aid=1128&effect_sdk_version=6.6.0&screen_width=414&openudid=6a25c6406978cbd05928fb03732716a39a0d04e3&cdid=59542D4F-CEB8-46FA-831C-410B2ED0E559&os_api=18&webcast_language=zh&ac=WIFI&os_version=12.3.1&webcast_locale=zh-Hans_CN&device_platform=iphone&build_number=108013&iid=8440917271405&device_type=iPhone%20XS%20Max&is_vcd=1&idfa=6B369BA0-9628-44D0-8491-FD101C292057";
url = @"https://webcast.amemv.com/webcast/luckybox/rush/?version_code=10.8.0&pass-region=0&js_sdk_version=1.60.0.7&pass-route=0&webcast_sdk_version=1490&app_name=aweme&vid=CC8E166D-34AB-424A-8EA9-DE0AFC223AF8&app_version=10.8.0&language=zh-Hans-CN&device_id=70854743357&channel=App%20Store&mcc_mnc=46004&aid=1128&effect_sdk_version=6.6.0&screen_width=810&openudid=4ae728e375c1adb5f462d043017363fa981e22d7&cdid=632ED61F-EAE0-47DC-A0B5-0F4951F9A075&os_api=18&webcast_language=zh&ac=WIFI&os_version=13.3&webcast_locale=zh-Hans_CN&device_platform=ipad&build_number=108013&iid=3737984599082238&device_type=iPad7,12&is_vcd=1&idfa=FD639131-0F34-4331-965B-B5B6F67DA31C";
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@(send_time),@"send_time",
@(box_type),@"box_type",
@(box_id),@"box_id",
room_id,@"room_id",
@(delay_time),@"delay_time",
nil];
[NSClassFromString(@"AWENetworkService") _requestWithURLString:url params:params method:@"POST" needCommonParams:false header:nil modelClass:nil targetAttributes:nil requestSerializer:nil responseSerializer:nil responseBlock:nil enableCache:false completionBlock:^(NSDictionary *m, NSError*err) {
NSLog(@"打开红包数据=%@",m);
if(err){
NSString*msg = @"打开红包失败";
dispatch_async(dispatch_get_main_queue(), ^{
[UIView xx_makeBottomToast:msg];
[xddTools sharedInstance].isGuanzZhuErr = YES;
});
}else{
NSDictionary* dataDic = m[@"data"];
if(dataDic[@"box_type"]){
NSString* where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"box_id"),bg_sqlValue(@(box_id))];
[HongbDB bg_delete:@"HongbDB" where:where];//删除红包ID数据库
}
// [0] (null) @"description" : @""
// [1] (null) @"gift_id" : (long)0
// [2] (null) @"rush_spam" : (long)0
// [3] (null) @"rush_too_often" : (long)0
// [4] (null) @"expired" : NO
// [5] (null) @"succeed" : NO
// [6] (null) @"box_type" : (long)1
// [7] (null) @"text" : @""
// [8] (null) @"cash_count" : (long)0
// [9] (null) @"rush_too_much" : (long)0
// [10] (null) @"gift_name" : @""
// [11] (null) @"diamond_count" : (long)0
// [0] (null) @"description" : @""
// [1] (null) @"gift_id" : (long)0
// [2] (null) @"rush_spam" : (long)1
// [3] (null) @"rush_too_often" : (long)0
// [4] (null) @"expired" : NO
// [5] (null) @"succeed" : NO
// [6] (null) @"box_type" : (long)1
// [7] (null) @"text" : @""
// [8] (null) @"cash_count" : (long)0
// [9] (null) @"rush_too_much" : (long)0
// [10] (null) @"gift_name" : @""
// [11] (null) @"diamond_count" : (long)0
}
}];
}