// // ASNetTools.m // Asteria // // Created by iOS on 2023/11/25. // #import "ASNetTools.h" #import @interface ASNetTools () @property (nonatomic, copy) NSString *currentToken; @property (nonatomic, strong) MKNetworkEngine *engine; @property (nonatomic, strong) MKNetworkEngine *msgEngine; @property (nonatomic, strong) NSMutableDictionary *defuatParam; @end @implementation ASNetTools + (instancetype)shared { static id sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (instancetype)init { self = [super init]; if (self) { [self updateEngine]; self.defuatParam = [NSMutableDictionary dictionary]; } return self; } - (void)setDefualtParam:(NSDictionary *)defualt { self.defuatParam = [[NSMutableDictionary alloc] initWithDictionary:defualt]; } - (void)updateDefualtParam:(NSDictionary *)newData { for (NSString *key in newData.allKeys) { self.defuatParam[key] = newData[key]; } } - (void)updateEngine { NSString *token = [DataUtil loginToken]; if (!token) { token = @""; } self.currentToken = token; self.engine = [[MKNetworkEngine alloc] initWithHostName:HostPath customHeaderFields:@{ @"Authorization":token, @"powerby": @"longyitec", @"Content-Type": @"application/json;charset=utf-8" }]; self.msgEngine = [[MKNetworkEngine alloc] initWithHostName:MsgHostPath customHeaderFields:@{ @"Authorization":token, @"powerby": @"longyitec", @"Content-Type": @"application/json;charset=utf-8" }]; } - (void)checkToken { NSString *token = [DataUtil loginToken]; if (!token) { token = @""; } if (![token isEqualToString:self.currentToken]) { [self updateEngine]; } } // MARK: - message Api // post请求 - (void)postMsgWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.msgEngine operationWithPath:path params:tempDic httpMethod:@"POST" ssl:isSSL]; [op setPostDataEncoding:MKNKPostDataEncodingTypeJSON]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Get-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *code = [NSString stringWithFormat:@"%@", result[@"code"]]; id data = result[@"data"]; if ([code isEqualToString:@"200"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(code, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"code"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.msgEngine enqueueOperation:op]; // }); } // formData的post请求 - (void)formDataMsg_postWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.msgEngine operationWithPath:path params:tempDic httpMethod:@"POST" ssl:isSSL]; ///form-data 的请求格式 NSData *data = [NSJSONSerialization dataWithJSONObject:param options:NSJSONWritingPrettyPrinted error:nil]; for (NSString *key in param.allKeys) { // 循环拿到所有参数进行拼接 // NSString * searchStr = [param[key] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSString * searchStr = param[key]; NSData *data =[searchStr dataUsingEncoding:NSUTF8StringEncoding]; [op addData:data forKey:key]; } __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Get-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *code = [NSString stringWithFormat:@"%@", result[@"code"]]; id data = result[@"data"]; if ([code isEqualToString:@"200"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(code, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"code"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.msgEngine enqueueOperation:op]; // }); } // get 请求 - (void)getMsgWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.msgEngine operationWithPath:path params:tempDic httpMethod:@"GET" ssl:isSSL]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Get-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *code = [NSString stringWithFormat:@"%@", result[@"code"]]; id data = result[@"data"]; if ([code isEqualToString:@"200"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(code, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"code"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; [self.msgEngine enqueueOperation:op]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ // }); } // put 请求 - (void)putMsgWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; //#if (DEBUG) // isSSL = false; //#endif [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.msgEngine operationWithPath:path params:tempDic httpMethod:@"PUT" ssl:isSSL]; [op setPostDataEncoding:MKNKPostDataEncodingTypeJSON]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Get-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *code = [NSString stringWithFormat:@"%@", result[@"code"]]; id data = result[@"data"]; if ([code isEqualToString:@"200"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(code, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"code"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.msgEngine enqueueOperation:op]; // }); } // del 请求 - (void)delMsgWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; //#if (DEBUG) // isSSL = false; //#endif [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.msgEngine operationWithPath:path params:tempDic httpMethod:@"DELETE" ssl:isSSL]; [op setPostDataEncoding:MKNKPostDataEncodingTypeJSON]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Get-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *code = [NSString stringWithFormat:@"%@", result[@"code"]]; id data = result[@"data"]; if ([code isEqualToString:@"200"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(code, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"code"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.msgEngine enqueueOperation:op]; // }); } // MARK: - api V1 // post请求 - (void)postWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.engine operationWithPath:path params:tempDic httpMethod:@"POST" ssl:isSSL]; [op setPostDataEncoding:MKNKPostDataEncodingTypeJSON]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = [NSString stringWithFormat:@"%@", result[@"status"]]; id data = result[@"data"]; if ([status isEqualToString:@"1"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(status, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"status"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.engine enqueueOperation:op]; // });d } // formData的post请求 - (void)formData_postWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.engine operationWithPath:path params:tempDic httpMethod:@"POST" ssl:isSSL]; ///form-data 的请求格式 NSData *data = [NSJSONSerialization dataWithJSONObject:param options:NSJSONWritingPrettyPrinted error:nil]; for (NSString *key in param.allKeys) { // 循环拿到所有参数进行拼接 // NSString * searchStr = [param[key] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSString * searchStr = param[key]; NSData *data =[searchStr dataUsingEncoding:NSUTF8StringEncoding]; [op addData:data forKey:key]; } __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---post-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = [NSString stringWithFormat:@"%@", result[@"status"]]; id data = result[@"data"]; if ([status isEqualToString:@"1"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(status, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"status"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.engine enqueueOperation:op]; }); } // get 请求 - (void)getWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.engine operationWithPath:path params:tempDic httpMethod:@"GET" ssl:isSSL]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Get-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = [NSString stringWithFormat:@"%@", result[@"status"]]; id data = result[@"data"]; if ([status isEqualToString:@"1"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(status, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"status"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; [self.engine enqueueOperation:op]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ // }); } // put 请求 - (void)putWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; //#if (DEBUG) // isSSL = false; //#endif [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.engine operationWithPath:path params:tempDic httpMethod:@"PUT" ssl:isSSL]; [op setPostDataEncoding:MKNKPostDataEncodingTypeJSON]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; NSLog(@"---Put-----url:\n%@\n-----data:\n%@\n--",path, temp); if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = [NSString stringWithFormat:@"%@", result[@"status"]]; id data = result[@"data"]; if ([status isEqualToString:@"1"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(status, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"status"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.engine enqueueOperation:op]; // }); } // del 请求 - (void)delWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { BOOL isSSL = true; //#if (DEBUG) // isSSL = false; //#endif [self checkToken]; NSMutableDictionary *tempDic = [[NSMutableDictionary alloc] initWithDictionary:self.defuatParam]; [tempDic addEntriesFromDictionary:param]; MKNetworkOperation *op = [self.engine operationWithPath:path params:tempDic httpMethod:@"DELETE" ssl:isSSL]; [op setPostDataEncoding:MKNKPostDataEncodingTypeJSON]; __weak typeof(self) weakSelf = self; [op onCompletion:^(MKNetworkOperation *completedOperation) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = [NSString stringWithFormat:@"%@", result[@"status"]]; id data = result[@"data"]; if ([status isEqualToString:@"1"]) { success(data); } else { NSString *msg = result[@"msg"]; faild(status, msg); } } }); } onError:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *json = [op responseJSON]; id temp = [json mj_JSONObject]; if ([temp isKindOfClass:[NSDictionary class]]) { NSDictionary *result = (NSDictionary *)temp; NSString *status = result[@"status"]; NSString *msg = result[@"msg"]; if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(status, msg); return; } faild(status, msg); return; } if (error.code == 401) { [DataUtil setLoginToken:@""]; [weakSelf updateEngine]; faild(@"-1", @"Plase Login"); return; } faild([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription); }); }]; // dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ [self.engine enqueueOperation:op]; // }); } // MARK: - debug + (void)debugRegist { NSDictionary *param = @{ @"customer": @{ @"email": @"abc123456789@qq.com", @"firstname": @"ujrbcf", @"lastname": @"serwt", @"dob": @"2023/10/20" }, @"password": @"A123456a", @"extension_attributes" : @{ @"is_subscribed": @(true) } }; [ASNetTools.shared postWithPath:registerUrl param:param success:^(id _Nonnull result) { NSLog(@"----url:%@-----result:%@------", registerUrl, result); } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"----url:%@-----code:%@----msg:%@--", registerUrl, code, msg); }]; } + (void)login { NSDictionary *param = @{ @"username" :@"abc123456789@qq.com",//@"Britneyngwafa@gmail.com",// @"password":@"A123456a",//@"1qazXSW@123",// }; [ASNetTools.shared postWithPath:loginUrl param:param success:^(id _Nonnull result) { NSString *token = [NSString stringWithFormat:@"Bearer %@", result]; [DataUtil setLoginToken:token]; [ASNetTools.shared updateEngine]; [ASUserInfoManager.shared getInfo]; NSLog(@"----url:%@-----result:%@------", loginUrl, result); } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"----url:%@-----code:%@----msg:%@--", loginUrl, code, msg); }]; } +(void)xxx_loginWithParam:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild { [ASNetTools.shared postWithPath:loginUrl param:param success:^(id _Nonnull result) { NSString *token = [NSString stringWithFormat:@"Bearer %@", result]; [DataUtil setLoginToken:token]; [ASNetTools.shared updateEngine]; [ASUserInfoManager.shared getInfo]; success(result); NSLog(@"----url:%@-----result:%@------", loginUrl, result); } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"----url:%@-----code:%@----msg:%@--", loginUrl, code, msg); faild(code,msg); }]; } ///获取广告位优惠卷列表 +(void)reqNet_getAdvCoupons{ [ASNetTools.shared getWithPath:BaseRequestrUrl(@"advCoupons") param:@{} success:^(id _Nonnull result) { [ASNetTools shared].xxx_couponAry = result; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { }]; } -(NSMutableArray *)xxx_couponAry{ if(!_xxx_couponAry){ _xxx_couponAry = [[NSMutableArray alloc]init]; } return _xxx_couponAry; } @end