//
|
// WeiKouNetWorkRequest.m
|
// advertisement
|
//
|
// Created by weikou on 16/4/20.
|
// Copyright © 2016年 yuxingmin.com. All rights reserved.
|
//
|
|
#import "WeiKouNetWorkRequest.h"
|
#import <AdSupport/AdSupport.h>
|
#define WeiKouAdUrl @"http://ad.yeshitv.com:8090/ad/api/banner"
|
|
|
@implementation WeiKouNetWorkRequest
|
+ (WeiKouNetWorkRequest *)sharedManager
|
{
|
static WeiKouNetWorkRequest *sharedInstance = nil;
|
static dispatch_once_t predicate;
|
dispatch_once(&predicate, ^{
|
sharedInstance = [[self alloc] init];
|
});
|
return sharedInstance;
|
}
|
|
/**
|
* 请求广告
|
*/
|
-(void)requestDataWithMethod:(NSString*)method withDevice:(NSString *)device withPlatform:(NSString *)platform withDeviceName:(NSString *)devicename withWidth:(NSString *)width withHeight:(NSString *)height withKw:(NSString *)kw withKey:(NSString *)key returnBlock:(NetWorkBlock)block;
|
{
|
NSString *url = [NSString stringWithFormat:@"%@",WeiKouAdUrl];
|
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
|
[dic setObject:method forKey:@"method"];
|
[dic setObject:device forKey:@"device"];
|
[dic setObject:platform forKey:@"platform"];
|
[dic setObject:devicename forKey:@"devicename"];
|
[dic setObject:width forKey:@"width"];
|
[dic setObject:height forKey:@"height"];
|
[dic setObject:kw forKey:@"kw"];
|
[dic setObject:key forKey:@"key"];
|
NSLog(@"请求输入参数************************************** %@",dic);
|
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
|
[manager GET:url parameters:dic progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
}success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
|
|
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
|
if ([[dic objectForKey:@"code"] integerValue]==0) {
|
block(true,dic,nil);
|
}
|
else
|
{
|
block(false,dic,[NSString stringWithFormat:@"code = %@",dic[@"code"]]);
|
}
|
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
block(false,nil,[error localizedDescription]);
|
}];
|
|
}
|
/**
|
* 上传结果
|
*/
|
-(void)upLoadDataWithMethod:(NSString*)method withKey:(NSString *)key withContentid:(NSNumber *)contentid withType:(NSNumber *)type withDevice:(NSString *)device returnBlock:(NetWorkBlock)block;
|
{
|
NSString *url = [NSString stringWithFormat:@"%@",WeiKouAdUrl];
|
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
|
[dic setObject:method forKey:@"method"];//reportad
|
[dic setObject:key forKey:@"key"];
|
[dic setObject:contentid forKey:@"contentid"];
|
[dic setObject:type forKey:@"type"];
|
if (device) {
|
[dic setObject:device forKey:@"device"];
|
}
|
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
|
[manager GET:url parameters:dic progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
}success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
|
|
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
|
if ([[dic objectForKey:@"code"] integerValue]==0) {
|
block(true,dic,nil);
|
}
|
else
|
{
|
block(false,dic,[NSString stringWithFormat:@"code = %@",dic[@"code"]]);
|
}
|
|
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
|
block(false,nil,[error localizedDescription]);
|
}];
|
|
}
|
|
@end
|