-(void)getHomeurl:(NSString *)url
{
NSMutableDictionary *param = [NSMutableDictionary dictionary];
if ([url isEqualToString:KgetHomePageV20]){
[param setValue:KmemberId forKey:@"memberId"];
// [param setValue:@"4" forKey:@"advertisementSize"];
// [param setValue:@"3" forKey:@"recommendationSize"];
[param setValue:@"9" forKey:@"shotSize"];
[param setValue:KAPPID forKey:@"appId"];
[param setValue:KappSecret forKey:@"appSecret"];
[param setValue:[CommonTools getTimeScamp] forKey:@"timestamp"];
//加密规则:sign=md5(app_id + lon+lat + time + key)
[param setValue:[CommonTools tokenmd5StringFromArray:@[[NSString stringWithFormat:@"memberId%@",param[@"memberId"]],[NSString stringWithFormat:@"shotSize%@",param[@"shotSize"]],[NSString stringWithFormat:@"appId%@",param[@"appId"]],[NSString stringWithFormat:@"appSecret%@",param[@"appSecret"]],[NSString stringWithFormat:@"timestamp%@",param[@"timestamp"]]]] forKey:@"digest"];
}else if ([url isEqualToString:KISUntreatedInfoV17]){
NSString *requestTime;
if ([[UserModel sharedInstance].oldDate length] > 0 ) {
requestTime = [UserModel sharedInstance].oldDate;
}else{
requestTime = @"0";
}
[param removeAllObjects];
[param setValue:KmemberId forKey:@"memberId"];
[param setValue:requestTime forKey:@"lastDynamicId"];
[param setValue:KAPPID forKey:@"appId"];
[param setValue:KappSecret forKey:@"appSecret"];
[param setValue:[CommonTools getTimeScamp] forKey:@"timestamp"];
[param setValue:[CommonTools tokenmd5StringFromArray:@[[NSString stringWithFormat:@"memberId%@",param[@"memberId"]],[NSString stringWithFormat:@"lastDynamicId%@",param[@"lastDynamicId"]],[NSString stringWithFormat:@"appId%@",param[@"appId"]],[NSString stringWithFormat:@"appSecret%@",param[@"appSecret"]],[NSString stringWithFormat:@"timestamp%@",param[@"timestamp"]]]] forKey:@"digest"];
}
else{
param = nil;
}
[HTTPRequestTool sendGetAFRequest:url withParameters:param withSuccess:^(id message) {
NSDictionary *tempArr = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:nil];
DSLog(@"我的首页数据tempArr = %@",tempArr);
// /**
if ([url isEqualToString:KgetHomePageV20]){
[_homeVideoArr removeAllObjects];
[_homeDyArr removeAllObjects];
[_homeAdArr removeAllObjects];
for (NSDictionary * tempDic in tempArr[@"myShots"] ) {
MorevideoNewModel *moreVDModel = [[MorevideoNewModel alloc]init];
[moreVDModel setValuesForKeysWithDictionary:tempDic];
[_homeVideoArr addObject:moreVDModel];
}
for (NSDictionary *temDic in tempArr[@"golfDynamics"]) {
golfDynamicsModel *golfModel = [[golfDynamicsModel alloc]init];
[golfModel setValuesForKeysWithDictionary:temDic];
[_homeDyArr addObject:golfModel];
}
for (NSDictionary *temDic in tempArr[@"advertisements"]) {
advertisementsModel * adModel = [[advertisementsModel alloc]init];
[adModel setValuesForKeysWithDictionary:temDic];
[_homeAdArr addObject:adModel];
}
NSLog(@"从网络中获取数据 --- 缓存到本地");
[[JXTCacher cacher] setObject:_homeVideoArr // save data to local disk and cache
forKey:@"myShots"
userId:@"myShots01"
useArchive:YES
setted:^(JXTCacher *cacher, CacheError error) {
}];
[[JXTCacher cacher] setObject:_homeDyArr // save data to local disk and cache
forKey:@"golfDynamics"
userId:@"golfDynamics01"
useArchive:YES
setted:^(JXTCacher *cacher, CacheError error) {
}];
[[JXTCacher cacher] setObject:_homeAdArr // save data to local disk and cache
forKey:@"advertisements"
userId:@"advertisements01"
useArchive:YES
setted:^(JXTCacher *cacher, CacheError error) {
}];
[self.homeCollectionView reloadData];
}else if ([url isEqualToString:KISUntreatedInfoV17]){
DSLog(@"----------returnCode--------%@",tempArr[@"returnCode"]);
if ([tempArr[@"returnCode"] isEqualToString:@"29"] || [tempArr[@"returnCode"] isEqualToString:@"31"]) {
[[NSNotificationCenter defaultCenter]postNotificationName:@"TokenFail" object:nil];
}
// NSString *oldDateStr = [messageBody.regDate stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
// [UserModel sharedInstance].oldDate = oldDateStr;
ISUntreatedInfoModel *isModel = [[ISUntreatedInfoModel alloc]init];
[isModel setValuesForKeysWithDictionary:tempArr];
//通讯录
if (isModel.ISUntreatedFriendInfo > 0) {
[UserModel sharedInstance].ISUntreatedFriendInfo = [NSString stringWithFormat:@"%d",isModel.ISUntreatedFriendInfo];
UIViewController *cvc = [[UIViewController alloc]init];
cvc.view.tag = 4;
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:cvc,@"RedDot", nil];
NSNotification *notification = [NSNotification notificationWithName:@"RedDot" object:nil userInfo:dict];
[[NSNotificationCenter defaultCenter]postNotification:notification];
}else{
UIViewController *cvc = [[UIViewController alloc]init];
cvc.view.tag = 3;
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:cvc,@"RedDot", nil];
NSNotification *notification = [NSNotification notificationWithName:@"RedDot" object:nil userInfo:dict];
[[NSNotificationCenter defaultCenter]postNotification:notification];
}
//动态
if (isModel.ISNewDynamic > 0) {
UIViewController *cvc = [[UIViewController alloc]init];
cvc.view.tag = 1;
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:cvc,@"RedDot", nil];
NSNotification *notification = [NSNotification notificationWithName:@"RedDot" object:nil userInfo:dict];
[[NSNotificationCenter defaultCenter]postNotification:notification];
}else{
UIViewController *cvc = [[UIViewController alloc]init];
cvc.view.tag = 0;
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:cvc,@"RedDot", nil];
NSNotification *notification = [NSNotification notificationWithName:@"RedDot" object:nil userInfo:dict];
[[NSNotificationCenter defaultCenter]postNotification:notification];
}
}
} andWithFail:^(id message) {
NSLog(@"error = %@",message);
}];
}
-(void)loadData
{
[[JXTCacher cacher] objectForKey:@"myShots" userId:@"myShots01" achive:^(JXTCacher *cacher, id obj, CacheError error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (obj && error == 0) { //local or cache have data
_homeVideoArr = obj;
NSLog(@"从缓存中获取数据");
[self.homeCollectionView reloadData];
}
else { // local and cache have no data
[self getHomeurl:KGetHomePage];
NSLog(@"从网络中获取数据");
}
});
}];
[[JXTCacher cacher] objectForKey:@"golfDynamics" userId:@"golfDynamics01" achive:^(JXTCacher *cacher, id obj, CacheError error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (obj && error == 0) { //local or cache have data
_homeDyArr = obj;
NSLog(@"从缓存中获取数据");
[self.homeCollectionView reloadData];
}
});
}];
[[JXTCacher cacher] objectForKey:@"advertisements" userId:@"advertisements01" achive:^(JXTCacher *cacher, id obj, CacheError error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (obj && error == 0) { //local or cache have data
_homeAdArr = obj;
NSLog(@"从缓存中获取数据");
[self.homeCollectionView reloadData];
}
});
}];
}