123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // HttpUtils.m
- // UUTUtils
- //
- // Created by zhuge on 2017/12/23.
- // Copyright © 2017年 zhuge. All rights reserved.
- //
- #import "HttpUtils.h"
- #import "ProjectInfo_Server.h"
- #import "ZGWebUtils.h"
- #import "ZGJsonUtils.h"
- #import "ZGNetCircularProgressView.h"
- #import "UrlCrptyUtils.h"
- #import "AppDelegate.h"
- @implementation HttpUtils
- - (void)requestAdConfigs:(ProjectInfo_Server *)server atWindow:(NSWindow *)window {
- // if(true){
- // return;
- // }
- NSLog(@"获取网络广告配置中...");
- // 创建progress view
- NSRect winRect = window.frame;
- float x = 0;
- float y = 0;
- float w = winRect.size.width;
- float h = winRect.size.height;
- ZGNetCircularProgressView *progressView = [[ZGNetCircularProgressView alloc] initWithFrame:NSMakeRect(x, y, w, h)];
- [window.contentView addSubview:progressView];
-
- NSString *package = server.package;
- NSString *uuid = @"";
-
- NSDictionary *dic = @{
- @"sdkVersion": @(SdkVersion),
- @"adVersion": @(0),
- @"packname": package,
- @"uuid": uuid,
- };
- NSString *dataParams = [ZGJsonUtils dictionaryToString:dic];
- dataParams = [HttpUtils urlEncode:dataParams];
- NSString *url = [NSString stringWithFormat:@"http://rdwxtool.com/adsaccount/www/gateway.php?act=104&data=%@", dataParams];
- NSLog(@"url:%@",url);
- [ZGWebUtils getForUrl:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
- NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"%@", ret);
- NSDictionary *dic = [ZGJsonUtils stringToObject:ret];
- NSLog(@"%@", dic[@"data"]);
-
- NSString *dataStr = dic[@"data"][@"adJson"];
- if (dataStr != nil && ![dataStr isKindOfClass:[NSNull class]] && ![NSNull isEqual:dataStr] && ![@"" isEqual:dataStr]) {
- dataStr = [UrlCrptyUtils decrypt:dataStr];
- dic = [ZGJsonUtils stringToObject:dataStr];
- } else {
- dic = nil;
- }
-
-
- // dic = nil;
- // 从网络获取然后进行初始化
- [server performSelectorOnMainThread:@selector(initWithDic:) withObject:dic waitUntilDone:YES];
- [self performSelectorOnMainThread:@selector(onRequestFinished:) withObject:progressView waitUntilDone:YES];
- }];
- }
- - (void)saveAdConfigs:(NSString *)cfg forPackage:(NSString *)package atWindow:(NSWindow *)window {
- // 创建progress view
- NSRect winRect = window.frame;
- float x = 0;
- float y = 0;
- float w = winRect.size.width;
- float h = winRect.size.height;
- ZGNetCircularProgressView *progressView = [[ZGNetCircularProgressView alloc] initWithFrame:NSMakeRect(x, y, w, h)];
- [window.contentView addSubview:progressView];
-
- NSMutableDictionary *md = [NSMutableDictionary dictionaryWithCapacity:0];
- // cfg = @"zhuge test";
- md[@"packname"] = package;
- md[@"sdkVersion"] = @(SdkVersion);
- cfg = [UrlCrptyUtils encrypt:cfg];
- md[@"adJson"] = cfg;
- NSString *url = [NSString stringWithFormat:@"http://rdwxtool.com/adsaccount/www/gateway.php?act=204"];
- NSString *post = [NSString stringWithFormat:@"data=%@", [ZGJsonUtils dictionaryToString:md]];
- NSLog(@"%@&%@", url, post);
- NSData *data = [post dataUsingEncoding:NSUTF8StringEncoding];
- NSString *ret = [ZGWebUtils stringOfURLByPost:url postData:data];
- NSLog(@"%@", ret);
- // [ZGWebUtils getForUrl:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
- // NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- // NSLog(@"%@", ret);
- // [self performSelectorOnMainThread:@selector(onRequestFinished:) withObject:progressView waitUntilDone:YES];
- // }];
- [self onRequestFinished:progressView];
- }
- + (NSString *)urlEncode:(NSString *)str {
- NSString *encoded = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
- NULL,
- (CFStringRef)str,
- NULL,
- (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
- kCFStringEncodingUTF8 ));
-
- // NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"!*'\"();:@&=+$,/?%#[]% "];
- // NSString *encoded = [str stringByAddingPercentEncodingWithAllowedCharacters:set];
- return encoded;
- }
- - (void)onRequestFinished:(NSView *)view {
- [view removeFromSuperview];
- }
- @end
|