|
@@ -13,6 +13,7 @@
|
|
@property (nonatomic, copy) NSString *currentToken;
|
|
@property (nonatomic, copy) NSString *currentToken;
|
|
|
|
|
|
@property (nonatomic, strong) MKNetworkEngine *engine;
|
|
@property (nonatomic, strong) MKNetworkEngine *engine;
|
|
|
|
+@property (nonatomic, strong) MKNetworkEngine *msgEngine;
|
|
@property (nonatomic, strong) NSMutableDictionary *defuatParam;
|
|
@property (nonatomic, strong) NSMutableDictionary *defuatParam;
|
|
|
|
|
|
@end
|
|
@end
|
|
@@ -59,6 +60,11 @@
|
|
@"powerby": @"longyitec",
|
|
@"powerby": @"longyitec",
|
|
@"Content-Type": @"application/json;charset=utf-8"
|
|
@"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"
|
|
|
|
+ }];
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -73,6 +79,316 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 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请求
|
|
// post请求
|
|
- (void)postWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild {
|
|
- (void)postWithPath:(NSString *)path param:(NSDictionary *)param success:(void(^)(id))success faild:(void(^)(NSString *code, NSString *msg))faild {
|
|
BOOL isSSL = true;
|
|
BOOL isSSL = true;
|
|
@@ -380,7 +696,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+// MARK: - debug
|
|
+ (void)debugRegist {
|
|
+ (void)debugRegist {
|
|
NSDictionary *param = @{
|
|
NSDictionary *param = @{
|
|
@"customer": @{
|
|
@"customer": @{
|