admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
//  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