/**
*景点详情
**/
+(void)creationScenicDetailWithScenic_id:(NSString *)scenic_id AndCallBack:(Callback) callback AndScallback:(Callback)scallback{
//设置请求的URL
NSString *path=[NSString stringWithFormat:@"%@%@",URL_PREFIX,ScenicDtail_URL];
//用字典存储需传给后台的参数
NSDictionary *params;
@try {
params=@{@"user_id":[UserInfo uid],@"token":[UserInfo token],@"scenic_id":scenic_id};
}
@catch (NSException *exception) {
scallback(YL_ERROR);
}
@finally {
}
//创建返回的数据(数组形式)
NSMutableArray *backArray=[NSMutableArray new];
//创建请求管理者
AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
//设置序列化器(使用二进制数据序列化),依靠设置序列化器来自动识别、解析返回的数据。默认使用的就是json解析,可以不用设置序列化器
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
//发送请求(此处是POST请求)
[manager POST:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *err;
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&err];
if (err) {
scallback(WL_Error);
}
else {
//打印路径、传给后台的参数、及后台的返回值
NSLog(@"%@...%@...景点详情...%@",path,params,dict);
NSString *status=[dict objectForKey:@"error"];
if ([status isEqualToString:@"0000"]) {
@try {
//遍历datas的每个参数
for (NSDictionary *dic1 in dict[@"datas"]) {
//创建模型,将模型赋值
ScenicDetailModel *model=[ScenicDetailModel new];
model.free_refund=[dic1 objectForKey:@"free_refund"];
model.sale_num=[dic1 objectForKey:@"sale_num"];
model.scenic_mobile=[dic1 objectForKey:@"scenic_mobile"];
model.scenic_address=[dic1 objectForKey:@"scenic_address"];
model.scenic_describe=[dic1 objectForKey:@"scenic_describe"];
//把model的数据加到数组中
[backArray addObject:model];
}
//返回返回值:backArray
callback (backArray);
}
@catch (NSException *exception) {
scallback(YL_ERROR);
return ;
}
@finally {
}
}
else
{
scallback([dict objectForKey:@"information"]);
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
scallback(WL_Error);
NSLog(@"景点详情错误-->%@",[error localizedDescription]);
}];
}