123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- //
- // LCHttpHelper.m
- // LiveChat
- //
- // Created by 张灿 on 2018/4/11.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "LCHttpHelper.h"
- #import "YOUPAIXRWalletVC.h"
- #import "AppDelegate.h"
- #import "LZAlertWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAIXRWalletVC.h"
- #import "YOUPAIHRRechargePayWindow.h"
- #import "YOUPAIBBMD5.h"
- #import <AppTrackingTransparency/AppTrackingTransparency.h>
- #import <AdSupport/AdSupport.h>
- static NSString *kSignature = @"QY";//@"TF";//@"AS";//@"QY"
- static NSString *kChannel = @"22";
- @implementation LCHttpHelper
- + (AFHTTPSessionManager *)shareManager{
- static AFHTTPSessionManager *manager = nil ;//1.声明一个空的静态的单例对象
- static dispatch_once_t onceToken; //2.声明一个静态的gcd的单次任务
- dispatch_once(&onceToken, ^{ //3.执行gcd单次任务:对对象进行初始化
- if (manager == nil) {
- manager = [AFHTTPSessionManager manager];
- }
- });
- return manager;
- }
- + (AFSecurityPolicy *)customSecurityPolicy
- {
- //先导入证书,找到证书的路径
- // NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"httpsRequest" ofType:@"cer"];
- // NSData *certData = [NSData dataWithContentsOfFile:cerPath];
-
- //AFSSLPinningModeCertificate 使用证书验证模式
- AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
- // [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
- //allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO
- //如果是需要验证自建证书,需要设置为YES
- securityPolicy.allowInvalidCertificates = YES;
-
- //validatesDomainName 是否需要验证域名,默认为YES;
- //假如证书的域名与你请求的域名不一致,需把该项设置为NO;如设成NO的话,即服务器使用其他可信任机构颁发的证书,也可以建立连接,这个非常危险,建议打开。
- //置为NO,主要用于这种情况:客户端请求的是子域名,而证书上的是另外一个域名。因为SSL证书上的域名是独立的,假如证书上注册的域名是www.google.com,那么mail.google.com是无法验证通过的;当然,有钱可以注册通配符的域名*.google.com,但这个还是比较贵的。
- //如置为NO,建议自己添加对应域名的校验逻辑。
- securityPolicy.validatesDomainName = NO;
- // NSSet *set = [[NSSet alloc] initWithObjects:certData, nil];
- // securityPolicy.pinnedCertificates = set;
-
- return securityPolicy;
- }
- + (NSURLSessionDataTask *)requestWithURLString:(NSString *)URLString
- parameters:(id)parameters
- needToken:(BOOL)needToken
- type:(HttpRequestType)type
- success:(void (^)(id responseObject))success
- failure:(void (^)(NSError *error))failure
- {
- if([URLString rangeOfString:@"app/config"].location != NSNotFound){
- NSLog(@"请求配置接口信息");
- }
-
- NSString * urlstr=[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,URLString];
-
- // NSLog(@"请求域名域名域名:%@",urlstr);
-
- NSString* encodedStr =[urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSString *bdId = [[NSBundle mainBundle] bundleIdentifier];
-
- NSMutableDictionary *parms = [NSMutableDictionary dictionaryWithDictionary:(NSDictionary *)parameters];
-
- // NSLog(@"%@",parms);
-
- AFHTTPSessionManager *manager = [self shareManager];
- manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",@"image/jpeg",@"image/gif", nil];
- manager.responseSerializer = [AFHTTPResponseSerializer serializer];
- [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
- manager.requestSerializer.timeoutInterval = 10.f;//超时时长
- [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
- //
- [manager.requestSerializer setValue:@"2" forHTTPHeaderField:@"source-id"];
- [manager.requestSerializer setValue:bdId forHTTPHeaderField:@"package-name"];
- [manager.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] forHTTPHeaderField:@"ver-code"];
- // if ([LCSaveData getWhiteVersion]) {
- // color = @"vqu-white";
- // }else{
- // color = @"vqu-black";
- // }
- // [manager.requestSerializer setValue:color forHTTPHeaderField:@"theme"];
- //企业签名还是TF签名
- [manager.requestSerializer setValue:kSignature forHTTPHeaderField:@"signature"];
- if (needToken) {
- //NSLog(@"getTokenString = %@",[LCSaveData getTokenString]);
- if ([LCSaveData getTokenString] != nil) {
- NSString* tokenStr = [NSString stringWithFormat:@"%@",[LCSaveData getTokenString]];
- [manager.requestSerializer setValue:tokenStr forHTTPHeaderField:@"token"];
- }else{
- [[NSNotificationCenter defaultCenter] postNotificationName:@"AbnormalLogout" object:nil userInfo:nil];
- //[ZCHUDHelper showTitle:@"登录状态过期,需重新登录" showtime:4];
- [LCTools changeRootToLogin];
- }
- }
- [manager.requestSerializer setValue:[LCTools getUUIDString] forHTTPHeaderField:@"oaid"];
- //机型
- [manager.requestSerializer setValue:[LCTools iphoneType] forHTTPHeaderField:@"phone-brand"];
- [manager.requestSerializer setValue:[[UIApplication sharedApplication] appVersion] forHTTPHeaderField:@"version"];
- NSString *chancelCode = [LCTools getchannelCode];
- if (chancelCode.length<=0) {
- [manager.requestSerializer setValue:kChannel forHTTPHeaderField:@"channel"];//渠道号
- }else{
- [manager.requestSerializer setValue:[LCTools getchannelCode] forHTTPHeaderField:@"channel"];//渠道号
- }
- //modify by leo
- [manager.requestSerializer setValue:[LCTools getUUIDString] forHTTPHeaderField:@"uuid"];
- [manager.requestSerializer setValue:[LCTools getNetworkType] forHTTPHeaderField:@"network-status"];
-
-
- [self md5Parms:parms andManager:manager];//参数md5加密
-
- //HTTPS SSL的验证,在此处调用上面的代码,给这个证书验证;
- [manager setSecurityPolicy:[self customSecurityPolicy]];
- LCLog(@"%@",manager.requestSerializer.HTTPRequestHeaders);
- switch (type) {
- case HttpRequestTypeGet:
- {
- return [manager GET:encodedStr parameters:parms progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- if (success) {
-
- responseObject = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- NSDictionary* dict = [LPSecureData getDictWithSecureString:(NSString*)responseObject];
- YMLog(@"**************************************************\n[✅]url:%@\n参数:%@ \n返回值:%@",encodedStr,parms,dict);
- success((id)dict);
- [self handelSussess:dict];
-
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- NSHTTPURLResponse * responses = (NSHTTPURLResponse *)task.response;
- NSData *errorData = [error.userInfo valueForKey:AFNetworkingOperationFailingURLResponseDataErrorKey];
- NSDictionary *erroInfo = errorData ? [NSJSONSerialization JSONObjectWithData:errorData options:NSJSONReadingMutableContainers error:nil] : @{};
- YMLog(@"**************************************************\n[❌]url:%@\n参数:%@ \n返回值:%@",encodedStr,parms,OCDictionaryIsEmpty(erroInfo) ? error : erroInfo);
- YMLog(@"\n#####请求错误Code#####\nstatusCode = %ld\n####################\ntask = %@\n", (long)responses.statusCode,task.currentRequest);
- [ZCHUDHelper showTitle:@"请检查网络连接"];
- if (failure) {
- failure(error);
- }
- }];
- }
- break;
- case HttpRequestTypePost:
- {
- return [manager POST:encodedStr parameters:parms progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- if (success) {
- // success(responseObject);
- // NSDictionary* dict = (NSDictionary*)responseObject;
- responseObject = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- NSString* string = [[NSString stringWithFormat:@"%@",responseObject] stringByReplacingOccurrencesOfString:@"签名验证通过\n" withString:@""];
- NSDictionary* dict = [LPSecureData getDictWithSecureString:(NSString*)string];
- YMLog(@"**************************************************\n[✅]url:%@\n参数:%@ \n返回值:%@\n原始值:%@",encodedStr,parms,dict,responseObject);
- success((id)dict);
- [self handelSussess:dict];
-
- }
- // [manager.session finishTasksAndInvalidate];
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- NSHTTPURLResponse * responses = (NSHTTPURLResponse *)task.response;
- NSData *errorData = [error.userInfo valueForKey:AFNetworkingOperationFailingURLResponseDataErrorKey];
- NSDictionary *erroInfo = errorData ? [NSJSONSerialization JSONObjectWithData:errorData options:NSJSONReadingMutableContainers error:nil] : @{};
- YMLog(@"**************************************************\n[❌]url:%@\n参数:%@ \n返回值:%@",encodedStr,parms,OCDictionaryIsEmpty(erroInfo) ? error : erroInfo);
- YMLog(@"\n#####请求错误Code#####\nstatusCode = %ld\n####################\ntask = %@\n", (long)responses.statusCode,task.currentRequest);
- #ifdef checkEnviTest
- [ZCHUDHelper showTitle:error.description showtime:10.0];
- #endif
- if (failure) {
- failure(error);
- }
- // [manager.session finishTasksAndInvalidate];
- }];
- }
- break;
- }
-
- }
- + (void)postImageArrayToSeverWithURLString:(NSString *)URLString
- imgArray:(NSArray<UIImage*> *)imgArray
- imgNameArray:(NSArray<NSString*>*)imgNameArray
- parmeters:(id)parmeters
- needToken:(BOOL)needToken
- success:(void (^)(id responseObject))success
- failure:(void (^)(NSError *error))failure{
-
-
- if([URLString rangeOfString:@"app/config"].location != NSNotFound){
- NSLog(@"请求配置接口信息");
- }
-
- NSString * urlstr=[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,URLString];
-
- NSString *encodedStr =[urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- NSMutableDictionary *parms = [NSMutableDictionary dictionaryWithDictionary:(NSDictionary *)parmeters];
-
- AFHTTPSessionManager *manager = [self shareManager];
- manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",@"image/jpeg",@"image/gif",@"multipart/form-data",nil];
- manager.responseSerializer = [AFHTTPResponseSerializer serializer];
- [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
- manager.requestSerializer.timeoutInterval = 600.f;//超时时长
- [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
-
- [manager.requestSerializer setValue:@"2" forHTTPHeaderField:@"source-id"];
- [manager.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] forHTTPHeaderField:@"ver-code"];
-
- //企业签名还是TF签名 QY
- [manager.requestSerializer setValue:kSignature forHTTPHeaderField:@"signature"];
-
- if (needToken) {
- NSString* tokenStr = [NSString stringWithFormat:@"%@",[LCSaveData getTokenString]];
- [manager.requestSerializer setValue:tokenStr forHTTPHeaderField:@"token"];
- }
- //机型
- [manager.requestSerializer setValue:[LCTools iphoneType] forHTTPHeaderField:@"phone-brand"];
- [manager.requestSerializer setValue:[[UIApplication sharedApplication] appVersion] forHTTPHeaderField:@"version"];
- NSString *chancelCode = [LCTools getchannelCode];
- if (chancelCode.length<=0) {
- [manager.requestSerializer setValue:kChannel forHTTPHeaderField:@"channel"];//渠道号
- }else{
- [manager.requestSerializer setValue:[LCTools getchannelCode] forHTTPHeaderField:@"channel"];//渠道号
- }
-
-
- [manager.requestSerializer setValue:[LCTools getUUIDString] forHTTPHeaderField:@"uuid"];
- [manager.requestSerializer setValue:[LCTools getNetworkType] forHTTPHeaderField:@"network-status"];
-
-
- [self md5Parms:parms andManager:manager];//参数md5加密
-
- //HTTPS SSL的验证,在此处调用上面的代码,给这个证书验证;
- [manager setSecurityPolicy:[self customSecurityPolicy]];
-
- [manager POST:encodedStr parameters:parms constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
- for (int i =0; i<imgArray.count; i++) {
- NSData *imageData = [UIImage zipNSDataWithImage:imgArray[i] maxFileSize:1024*1024];
- [formData appendPartWithFileData:imageData name:imgNameArray[i] fileName:@"xxxx.jpg" mimeType:@"image/jpeg"];
-
- }
- } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- if (success) {
- responseObject = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- NSDictionary* dict = [LPSecureData getDictWithSecureString:(NSString*)responseObject];
- YMLog(@"**************************************************\n[✅]url:%@\n参数:%@ \n返回值:%@",encodedStr,parms,dict);
- success((id)dict);
- [self handelSussess:dict];
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- NSHTTPURLResponse * responses = (NSHTTPURLResponse *)task.response;
- NSData *errorData = [error.userInfo valueForKey:AFNetworkingOperationFailingURLResponseDataErrorKey];
- NSDictionary *erroInfo = errorData ? [NSJSONSerialization JSONObjectWithData:errorData options:NSJSONReadingMutableContainers error:nil] : @{};
- YMLog(@"**************************************************\n[❌]url:%@\n参数:%@ \n返回值:%@",encodedStr,parms,OCDictionaryIsEmpty(erroInfo) ? error : erroInfo);
- YMLog(@"\n#####请求错误Code#####\nstatusCode = %ld\n####################\ntask = %@\n", (long)responses.statusCode,task.currentRequest);
- #ifdef checkEnviTest
- [ZCHUDHelper showTitle:error.description showtime:10.0];
- #endif
- if (failure) {
- failure(error);
- }
-
- }];
-
- }
- + (void)handelSussess:(NSDictionary*)dict{
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- NSString* msg = [dict objectForKey:@"message"];
- if (code==0) {
-
- }else if(code==1001){
- [[NSNotificationCenter defaultCenter] postNotificationName:@"AbnormalLogout" object:nil userInfo:nil];
- //[ZCHUDHelper showTitle:@"登录状态过期,需重新登录"];
- [LCTools changeRootToLogin];
- }else if(code==1002){
- [ZCHUDHelper showTitle:@"您的可用余额不足"];
- // LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"舍不得" handler:^(LZAlertAction *action) {
- //
- // }];
- // cancelAction.cornerRadius = 24.0f;
- // cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- // LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"去充值" handler:^(LZAlertAction *action) {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"InsufficientBalanceNotice" object:nil userInfo:nil];
- // YOUPAIHRRechargePayWindow *payWindow = [YOUPAIHRRechargePayWindow new];
- // payWindow.isTouchDismiss = NO;
- // [kAppDelegate.window.rootViewController TFPresentVC:payWindow completion:^{
- //
- // }];
-
- YMAccountBalanceViewModel *accountBalanceVM = [[YMAccountBalanceViewModel alloc]initWithParams:@{
- ParamsId:@([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id intValue])
- }];
- YMAccountBalanceRechargePopupView *customView = [[YMAccountBalanceRechargePopupView alloc]init];
- [customView ym_bindViewModel:accountBalanceVM];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
- popupView.positionStyle = YMPositionStyleBottom;
- popupView.isClickBgDismiss = YES;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.5;
- [popupView pop];
-
- @weakify(popupView)
- customView.dismissBlock = ^{
- @strongify(popupView)
- [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
- };
-
- // }];
- // confimAction.cornerRadius = 24.0f;
- // confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- // LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"您的可用余额不足,去充值" action:@[cancelAction,confimAction]];
- // alert.contentTextAlignment = NSTextAlignmentCenter;
- // [kAppDelegate.window.rootViewController TFPresentVC:alert completion:^{}];
- }else if(code==1003){
- [ZCHUDHelper showTitle:@"您的可用余额不足"];
- // LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"舍不得" handler:^(LZAlertAction *action) {
- //
- // }];
- // cancelAction.cornerRadius = 24.0f;
- // cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- // LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"去充值" handler:^(LZAlertAction *action) {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"InsufficientBalanceNotice" object:nil userInfo:nil];
-
- // YOUPAIHRRechargePayWindow *payWindow = [YOUPAIHRRechargePayWindow new];
- // payWindow.isTouchDismiss = NO;
- // [kAppDelegate.window.rootViewController TFPresentVC:payWindow completion:^{
- //
- // }];
-
- YMAccountBalanceViewModel *accountBalanceVM = [[YMAccountBalanceViewModel alloc]initWithParams:@{
- ParamsId:@([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id intValue])
- }];
- YMAccountBalanceRechargePopupView *customView = [[YMAccountBalanceRechargePopupView alloc]init];
- [customView ym_bindViewModel:accountBalanceVM];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
- popupView.positionStyle = YMPositionStyleBottom;
- popupView.isClickBgDismiss = YES;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.5;
- [popupView pop];
-
- @weakify(popupView)
- customView.dismissBlock = ^{
- @strongify(popupView)
- [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
- };
-
- // YOUPAIXRWalletVC* coinRecharge = [[YOUPAIXRWalletVC alloc]init];
- // [[ZCUtils getCurrentVC].navigationController pushViewController:coinRecharge animated:YES];
- // }];
- // confimAction.cornerRadius = 24.0f;
- // confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- // LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"您的钻石数量不足,去购买" action:@[cancelAction,confimAction]];
- // alert.contentTextAlignment = NSTextAlignmentCenter;
- // [kAppDelegate.window.rootViewController TFPresentVC:alert completion:^{}];
- }else{
-
- if ([msg isKindOfClass:[NSString class]]) {
- if(![msg isEqualToString:@""]){
- if (code>0) {
- [ZCHUDHelper showTitle:msg showtime:4.0];
- }else{
- [ZCHUDHelper showTitle:msg];
- }
- }
- }
- }
- }
- +(void)md5Parms:(NSDictionary *)parms andManager:(AFHTTPSessionManager *)manager
- {
- NSString *timeSp = [NSString stringWithFormat:@"%ld",[[LCTools getCurrentMillisecondTimestamp] integerValue] + [LCSaveData getTimeDifference]];//时间戳
- NSString *random = [LCTools randomNumberWithLength:6];
-
- NSArray *sortKeys = [[parms allKeys] sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
- return [obj1 compare: obj2 options:NSNumericSearch];
- }];
-
- // NSLog(@"sortKeys = %@",sortKeys);
-
-
- NSString *string;
- for (int i = 0; i < sortKeys.count; i++)
- {
- if (i == 0) {
- string = [NSString stringWithFormat:@"%@%@", sortKeys[i], parms[sortKeys[i]]];
- }else{
- string = [NSString stringWithFormat:@"%@%@%@",string,sortKeys[i], parms[sortKeys[i]]];
- }
- }
- // NSLog(@"string = %@",parms);
- //
- // NSLog(@"string = %@",string);
-
- NSString *signStr;
- if (sortKeys.count == 0) {
- signStr = [NSString stringWithFormat:@"%@%@%@%@",kYanQianKey,timeSp,random,[LCTools getUUIDString]];
- }else{
- signStr = [NSString stringWithFormat:@"%@%@%@%@%@",string,kYanQianKey,timeSp,random,[LCTools getUUIDString]];
- }
- NSLog(@"str = %@",signStr);
-
- // if ([LCSaveData getWhiteVersion]) {
- // [manager.requestSerializer setValue:@"1" forHTTPHeaderField:@"package-type"];//是否为baibao
- // }else{
- // [manager.requestSerializer setValue:@"0" forHTTPHeaderField:@"package-type"];//是否为baibao
- // }
- //
-
- [manager.requestSerializer setValue:[@([LCSaveData getWhiteVersion]) stringValue] forHTTPHeaderField:@"package-type"];//是否为baibao 1是
-
- [manager.requestSerializer setValue:timeSp forHTTPHeaderField:@"timestamp"];
- [manager.requestSerializer setValue:random forHTTPHeaderField:@"random"];
- [manager.requestSerializer setValue:[YOUPAIBBMD5 youpaifmd5To32bit:signStr] forHTTPHeaderField:@"sign"];
- if ([LCSaveData getWhiteVersion]) {
- [manager.requestSerializer setValue:@"vqu-white" forHTTPHeaderField:@"theme"];
- }else{
- [manager.requestSerializer setValue:@"vqu-white" forHTTPHeaderField:@"theme"];
- }
- if (@available(iOS 14, *)) {
- // iOS14及以上版本需要先请求权限
- [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
- // 获取到权限后,依然使用老方法获取idfa
- if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
- NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
- [manager.requestSerializer setValue:idfa forHTTPHeaderField:@"idfa"];
- NSLog(@"%@",idfa);
- } else {
- NSLog(@"请在设置-隐私-跟踪中允许App请求跟踪");
- }
- }];
- } else {
- // iOS14以下版本依然使用老方法
- // 判断在设置-隐私里用户是否打开了广告跟踪
- if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
- NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
- [manager.requestSerializer setValue:idfa forHTTPHeaderField:@"idfa"];
- NSLog(@"%@",idfa);
- } else {
- NSLog(@"请在设置-隐私-广告中打开广告跟踪功能");
- }
- }
-
- }
- @end
|