// // HttpRequest.m // zhuxun // // Created by 张建伟 on 15/4/7. // Copyright (c) 2015年 张建伟. All rights reserved. // #import "HttpRequest.h" //#import "LoginAPI.h" //#import "AuthAPI.h" #import "NSMutableDictionary+MuiltKeyValue.h" #define CloudStorageURL @"http://192.168.16.181:9123"//开发测试_云盘_API地址 //#define CloudStorageURL @"http://netdisk.cloud.wswin.cn:9123"//生产环境_云盘_API地址 #define CloudStorageDownUpUrl @"http://192.168.16.181"//开发测试_云盘_上传下载地址 //#define CloudStorageDownUpUrl @"http://netdisk.cloud.wswin.cn:9120"//生产环境_云盘_上传下载地址 @implementation HttpRequest + (instancetype)sharedManager { static HttpRequest *shared_manager = nil; static dispatch_once_t pred; dispatch_once(&pred, ^{ shared_manager = [[HttpRequest alloc] init]; }); return shared_manager; } #pragma mark Login - (void)request_Login_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block{ [[HttpClient sharedJsonClient] requestJsonDataWithPath:@"" withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { //获取数据 id resultData = [data valueForKeyPath:@"data"]; // if (resultData) { // User *curLoginUser = [NSObject objectOfClass:@"User" fromJSON:resultData]; // if (curLoginUser) { // [Login doLogin:resultData]; // } // block(curLoginUser, nil); // }else{ // block(nil, error); // } }]; } //--ok #warning 安全改造后以下代码无用############################################## -(void)postLoginParams:(NSDictionary *)params complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v1/user/login"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStoragePostLoginWithParams:(NSDictionary *)params complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/login"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (![resultData isKindOfClass:[NSNull class]]) { NSString *auth = resultData[@"authorization"]; if (auth) { [userDefaults setObject:auth forKey:@"authorization"]; } } NSString * key = [userDefaults objectForKey:@"authorization"]; if (!key) { [userDefaults setObject:@"eHhqOkEwQTQ3NUNGNDU0Q0Y5QTA2OTc5MDM0MDk4MTY3QjlF" forKey:@"authorization"]; } if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetFilesWithPid:(NSString *)pid searchKey:(NSString *)key ext:(NSString *)ext complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; if (pid) { [dict setObject:pid forKey:@"pid"]; } if (key) { [dict setObject:key forKey:@"key"]; } if (ext) { [dict setObject:ext forKey:@"ext"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Get andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetRecycledFilesWithComplete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item/recycle"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageFileDeleteWithItemIDs:(NSArray *)fileIDs deleteLevel:(NSInteger)deleteLevel complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item/delete"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; if (fileIDs) { [dict setObject:fileIDs forKey:@"item_ids"]; } if (deleteLevel) { [dict setObject:@(deleteLevel) forKey:@"is_remove"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetAllFolderWithPid:(NSString *)pid excludeIds:(NSArray *)excludeIds complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = [NSString stringWithFormat:@"/v2/api/item/%@/folder",pid]; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; if (excludeIds) { [dict setObject:excludeIds forKey:@"item_ids"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetAllChildsWithPids:(NSArray *)pids complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item/childs"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; if (pids) { [dict setObject:pids forKey:@"ids"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageFileReNameWithNewName:(NSString *)name fileID:(NSString *)itemID complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item/rename"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; if (name) { [dict setObject:name forKey:@"name"]; } if (itemID) { [dict setObject:itemID forKey:@"_id"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageCreateNewFileFolderWithFolderName:(NSString *)folderName pid:(NSString *)pid delflag:(NSString *)delflag complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@1 forKey:@"isdir"]; if (folderName) { [dict setObject:folderName forKey:@"name"]; } if (pid) { [dict setObject:pid forKey:@"pid"]; } if (delflag) { [dict setObject:delflag forKey:@"delflag"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageCheckFileNameIsExitWithPid:(NSString *)pid fileName:(NSString *)fileName isdir:(BOOL)isdir ext:(NSString *)ext complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item/check_rename"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:pid forKey:@"pid"]; [dict setObject:fileName forKey:@"name"]; [dict setObject:@(isdir) forKey:@"isdir"]; if (ext) { [dict setObject:ext forKey:@"ext"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageCreateNewFileWithFileName:(NSString *)fileName md5:(NSString *)md5 pid:(NSString *)pid delflag:(NSString *)delflag ext:(NSString *)ext size:(NSNumber*)size complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/item"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@0 forKey:@"isdir"]; if (fileName) { [dict setObject:fileName forKey:@"name"]; } if (pid) { [dict setObject:pid forKey:@"pid"]; }else{ [dict setObject:@"0" forKey:@"pid"]; } if (delflag) { [dict setObject:delflag forKey:@"delflag"]; } // if (md5) { [dict setObject:md5 forKey:@"md5"]; } if (ext) { [dict setObject:ext forKey:@"ext"]; } if (size) { [dict setObject:size forKey:@"size"]; } [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } -(void)cloudStorageMoveFilesToOtherPid:(NSString *)pid needMoveFiles:(NSArray *)csfiles complete:(void (^)(BOOL, id, NSError *))complete { NSString *path = [NSString stringWithFormat:@"/v2/api/item/move_file/to/%@",pid]; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:csfiles forKey:@"item_ids"]; [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageCopyFilesToOtherPid:(NSString *)pid needCopyFiles:(NSArray *)csfiles complete:(void (^)(BOOL, id, NSError *))complete{ NSString *path = [NSString stringWithFormat:@"/v2/api/item/copy_file/to/%@",pid]; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:csfiles forKey:@"item_ids"]; [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"data"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetFileDownloadURLWithMD5:(NSString *)md5 complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = [NSString stringWithFormat:@"/api/download/%@",md5]; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageDownUpUrl,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; // [dict setObject:md5 forKey:@"md5"]; [[HttpClient sharedJsonClient] cloudStorageDownUpJsonDataWithPath:fullPath withParams:dict withMethodType:Get andBlock:^(id data, NSError *error) { if (data) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetFileUploadURLWithMD5:(NSString *)md5 complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = [NSString stringWithFormat:@"/api/upload/%@/%@",@"tcp",md5]; // NSString *path = @"/api/upload"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageDownUpUrl,path]; // NSMutableDictionary *dict = [NSMutableDictionary dictionary]; // [dict setObject:md5 forKey:@"md5"]; // [dict setObject:@"tcp" forKey:@"type"]; [[HttpClient sharedJsonClient] cloudStorageDownUpJsonDataWithPath:fullPath withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) { if (data) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageCreateShareFiles:(NSArray *)filesdic WithReceivers:(NSArray*)receivers complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/share"; NSString *fullPath = [NSString stringWithFormat:@"%@%@",CloudStorageURL,path]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; NSMutableString *mstr = [NSMutableString string]; NSMutableArray *item_ids = [NSMutableArray array]; [dict setObject:receivers forKey:@"users"];//移动端没有部门 直接用户多选 for (NSDictionary *sdic in filesdic) { NSString *name = [sdic objectForKey:@"name"]; NSString *item_id = [sdic objectForKey:@"id"]; [mstr appendString:name]; [item_ids addObject:item_id]; } NSDictionary *share_file =@{@"name":mstr, @"item_ids":item_ids}; [dict setObject:share_file forKey:@"share_file"]; [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:dict withMethodType:Post andBlock:^(id data, NSError *error) { if (data) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } - (void)cloudStorageGetShareFiles:(NSString *)shareID complete:(void (^)(BOOL success, id data, NSError *error)) complete { NSString *path = @"/v2/api/share/package/"; NSString *fullPath = [NSString stringWithFormat:@"%@%@%@",CloudStorageURL,path,shareID]; [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:fullPath withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) { if (data) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } #pragma mark --- 云盘相关结束 // ////获取群组通信和存储信息 --ok //-(void)getGroupParams:(NSDictionary *)params complete:(void (^)(BOOL success, id data, NSError *error)) complete //{ // // NSString *path = @"/v1/servers"; // NSString *aPath = [NSString stringWithFormat:@"http://%@:%@%@",[userDefaults objectForKey:USERDEFAULT_GROUP_HOST],[userDefaults objectForKey:USERDEFAULT_GROUP_PORT],path]; //#warning 2016-06-28 中心服务器地址有问题?? // [[HttpClient sharedJsonClient] cloudStorageRequestJsonDataWithPath:aPath withParams:params withMethodType:Get andBlock:^(id data, NSError *error) { // // // /* // { // "socket": { // "host": "120.26.126.129", // "port": 6714, // "id": "120.26.126.129:6714", // "online": 4, // "type": "mix", // "ver": "3.2.0" // }, // "storage": { // "host": "120.26.126.129", // "port": 6713 // } // } // */ // // complete(data?1:0,data,error); // // }]; //} // //--ok -(void)postDeviceInfo:(NSDictionary *)params complete:(void (^)(BOOL, id, NSError *))complete{ NSString *path = @"/v1/device/perfect"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKey:@"message"]; if (resultData) { complete(YES,data,nil); }else{ complete(NO,nil,error); } }]; } //--ok -(void)request_resetUnreadCount_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/zhuxunserver/devices/resetUnreadCount"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { // User *curLoginUser = [NSObject objectOfClass:@"User" fromJSON:resultData]; // if (curLoginUser) { // [Login doLogin:resultData]; // } // block(curLoginUser, nil); }else{ // block(nil, error); } }]; } //--ok -(void)search_users_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/zhuxunserver/branchs/searchUsers"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; //@"branchs/searchUsers" [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { //获取数据 id resultData = [data valueForKeyPath:@"data"]; //如果数据存在 if (resultData) { //获取对象数组 // NSArray *items = [resultData valueForKeyPath:@"items"]; //将数组传递出去 block(resultData, nil); }else{ block(nil, error); } }]; } //-ok #warning mark - - users/getUserDetail -(void)request_userDetail_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/zhuxunserver/users/getUserDetail"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData, nil); }else{ block(nil, error); } }]; } //请求用户状态--废弃 -(void)request_userState_WithParams:(id)params andBlock:(void (^)(id, NSError *))block{ // NSString *StrUrl = @"http://120.26.126.129:30001/zhuxunserver/users/getUserStates"; /zhuxunserver/ NSString *path = @"/zhuxunserver/users/getUserStates"; NSString *aPath =[NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] postRequestToUrl:aPath netWorkMethod:Post aPath:aPath WithParams:params complete:^(BOOL successed, NSDictionary *result) { id resultData = [result valueForKeyPath:@"data"]; // NSLog(@"resultData: %@",resultData); // if (result) { block(resultData,nil); // } }]; } //请求多用户状态 -(void)request_UserDetailListWith:(id)params andBlock:(void(^)(id data,NSError *error))block { NSString *path = @"/v1/users/detailList"; NSString *aPath =[NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (error) { //提示 return ; } id result = data[@"data"]; if (!result) { return; } block(result,nil); }]; } //--废弃 -(void)request_Branches_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { //客户端的数据请求 类型为 post params: -1 NSString *path = @"/zhuxunserver/branchs/getBranchsByParentID"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData, nil); }else{ block(nil, error); } }]; } //通过传入的参数 'params' ,向服务器获取所有的分支机构--ok -(void)request_allChildOfBranch_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/zhuxunserver/branchs/getAllChildrenByParentID"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData, nil); }else{ block(nil, error); } }]; } //--ok -(void)upload_headImage_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { NSString *path = @"/zhuxunserver/users/uploadHeadImage"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData, nil); }else{ block(nil, error); } }]; } //同步通讯录 使用数据请求--ok -(void)request_personalAddrbook_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { NSString *path = @"/zhuxunserver/addressBooks/sync"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { //取数据 data id resultData = [data valueForKeyPath:@"data"]; //如果有数据,就block回调数据 if (resultData) { block(resultData, nil); }else{ block(nil, error); } }]; } //--ok -(void)request_sendSMS_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { NSString *path = @"/zhuxunserver/sms/sendCode"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; //原来的是 sms/sendCode [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { NSLog(@"resultData: %@",resultData); block(resultData, nil); }else{ block(nil, error); } }]; } //--ok -(void)request_authSMS_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { NSString *path = @"/zhuxunserver/sms/authCode"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; LOG(@"\n\nappHost: %@\n\n",APP_HOST); [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData, nil); }else{ block(nil, error); } }]; } //请求通知公告提醒--ok -(void)request_NoticeOffline_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { NSString *path = @"/zx/notice/offline"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData,nil); }else{ block(nil,error); } }]; } -(void) request_with:(NetworkMethod)method andUrl:(NSString *)url andPrams:(id)params andBlock:(void (^)(id))block { [[HttpClient sharedJsonClient] requestJsonDataWithPath:url withParams:params withMethodType:method andBlock:^(id data, NSError *error) { if(error){ // 提示 return; } id resultData = [data valueForKeyPath:@"data"]; block(resultData); }]; } //获取离线消息--废弃 -(void)request_MsgOffLine_WithParams:(id)params andBlock:(void (^)(id, NSError *))block { NSString *path = @"/v1/msg/offline"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id resultData = [data valueForKeyPath:@"data"]; if (resultData) { block(resultData,nil); }else{ block(nil,error); } }]; } //获取历史消息--废弃 -(void)request_HistoryMessage_WithParams:(id)params andBlock:(void(^)(id data ,NSError *error))block { //history NSString *path = @"/v1/msg/sync"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if(error){ //用户提示; return; } NSLog(@"%@",data[@"message"]); BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } //获取发送者离线同步消息 /v1/msg/offlinesync 自己在PC发送的消息 -(void)request_MsgOffLinesync_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/v1/msg/offlinesync"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if(error){ //用户提示; return; } NSLog(@"%@",data[@"message"]); BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } /** * 统一获取离线消息--废弃 * * @param params * @param block */ -(void)request_MsgOffLinesMsgsParams:(id)params andBlock:(void (^)(id data, NSError *error))block { /* 参数说明: String target -必填项,目标用户,格式:CID+serverID-loginName String uuid -可选项,请求唯一标识 参数格式: { target : "0578+serverID-loginName", uuid:"" */ NSString *path = @"/v1/msg/offlineFull"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if(error){ //用户提示; return; } NSLog(@"%@",data[@"message"]); BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } /** * 离线消息获取并反馈成功接口--废弃 * * @param params * @param block */ -(void)request_MsgOffLinesMsgsReceiveResponse:(id)params andBlock:(void (^)(id data, NSError *error))block { /* 参数说明: Array uuids -必填项,拉取的数据唯一标识uuid数组,示例:['111','222'] String target -可选项,目标用户,格式:CID+serverID-loginName String uuid -可选项,请求唯一标识 参数格式: { uuids:['111','222'], target : "0578+serverID-loginName", uuid:"" } */ NSString *path = @"/v1/msg/receivedFull"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if(error){ //用户提示; return; } NSLog(@"%@",data[@"message"]); BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } /** * 用户最近联系人列表(只含有未读消息)--ok * * @param params id * @param block return */ - (void)request_UnReadMsgListWithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/v1/user/unread"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if(error){ //用户提示; return; } NSLog(@"%@",data[@"message"]); BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } /** * 获取单人聊天历史纪录--ok * * @param params id * @param block return */ //- (void)request_SingleUnReadMsgsWithParams:(id)params andBlock:(void (^)(id data, NSError *error))block //{ // NSString *path = @"/v1/msg/offlineSimple"; // NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; // //对params中的参数进行二次校验,符合继续不符合return;@"0578+(null)" // if ([[params objectForKey:@"target"] isEqualToString:[NSString stringWithFormat:@"%@+(null)",[userDefaults objectForKey:USERDEFAULT_ContentServer]]] ) { // return; // } // [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { // if(error){ // //用户提示; // return; // } // NSLog(@"%@",data[@"message"]); // BOOL success = data[@"success"]; // id result = nil; // if (success) { // result = data[@"data"]; // // } // block(result,nil); // }]; //} /** * 获取单人聊天历史纪录成功的反馈--废弃 * * @param params id 参数说明: String current -必填项,当前用户,格式:CID+serverID-loginName String target -必填项,目标用户,格式:CID+serverID-loginName String|int time -必填项,拉取的消息中最新的消息时间戳,Number类型 String uuid -可选项,请求唯一标识 参数格式:{ current:"CID+serverID-loginName", target:"CID+serverID-loginName", time:123455678.45, uuid:"" } * @param block return */ - (void)request_SingleUnReadMsgsResponseWithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/v1/msg/receivedSimple"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if(error){ //用户提示; return; } NSLog(@"%@",data[@"message"]); BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } //获取单对单历史消息--废弃 -(void)request_chatObjectHistory_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/zhuxunserver/v2/msg/history"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (error) { return ; } BOOL success = data[@"success"]; id result = nil; if (success) { result = data[@"data"]; } block(result,nil); }]; } -(void)public_Request_With_MethodType:(RequestMethod)method path:(NSString *)path params:(id)params andBlock:(void (^) (id data, NSError *error))block{ NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (!error) { id resultData = [data valueForKey:@"data"]; block(data,nil); }else{ block(nil,error); } }]; } //拉取设备比对--ok -(void)request_User_lastDevice_WithParams:(id)params andBlock:(void(^)(id data, NSError *error))block{ NSString *path = @"/v1/user/lastDevice"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { BOOL success = [data[@"success"] boolValue]; if (success) { block(data,nil); }else{ if (error) { block(nil,error); } } }]; } //微助手自带短信--ok -(void)request_SendSMS_NoLocalWithParams:(id)params andBlock:(void (^)(id data, NSError *error))block { NSString *path = @"/zhuxunserver/sms/send"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { BOOL success = data[@"success"]; if (success) { block(data,nil); }else{ block(nil,error); } }]; } //删除用户聊天信息--ok -(void)request_deleteCurrentChatMessagesWithParams:(id)params andBlock:(void (^)(id data,NSError *error))block { NSString *path = @"/v1/msg/delete"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } //注销登录 -- 0k - (void)logout_withParams:(id)params andBlock:(void (^)(id data,NSError *error))block { NSString *path = @"/v1/user/logout"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } //获取我的客服 - (void)getMyCustomerServicerwithParams:(id)params andBlock:(void (^)(id data,NSError *error))block { NSString *path = @"/v1/customerService"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Get andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } // 获取我的常用联系人 - (void)getMyFrequentContactswithParams:(id)params andBlock:(void (^)(id data,NSError *error))block { ///v1/frequentContact NSString *path = @"/v1/frequentContact"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Get andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } // 添加我的常用联系人 - (void)addMyFrequentContactswithParams:(id)params andBlock:(void (^)(id data,NSError *error))block { NSString *path = @"/v1/frequentContact"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } // 删除我的常用联系人 - (void)deleteMyFrequentContactswithParams:(id)params andBlock:(void (^)(id data,NSError *error))block { NSString *path = @"/v1/frequentContact"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Delete andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } //获取顶级部门成员--OK - (void)postTopDepartmentMembers:(id)params andBlock:(void (^)(id data,NSError *error))block { NSString *path = @"/zhuxunserver/branchs/getMyTopBranch"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { if (error) { block(nil,error); }else{ block(data,nil); } }]; } //==========socket.io 模拟的http //通过传入的请求服务器命令和 sender 获取离线同步消息 -(void)request_isSync_WithParams:(id)params andBlock:(void (^)(id, NSError *))block{ NSString *path = @"/zhuxunserver.chat.message.sync"; NSString *aPath = [NSString stringWithFormat:@"%@%@",APP_HOST,path]; [[HttpClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Post andBlock:^(id data, NSError *error) { id result = [data valueForKey:@"data"]; if (result) { block(result,nil); }else{ block(nil,error); } }]; } //-(void)request_login_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block //{ // LoginAPI *loginAPI = [LoginAPI new]; // [loginAPI requestWithObject:params Completion:^(id response, NSError *error) { // // //登录信息回调 // block(response, nil); // // }]; //} //通过用户的登录名和密码等 认证用户并获取离线消息 //-(void)request_auth_WithParams:(id)params andBlock:(void (^)(id data, NSError *error))block //{ // AuthAPI *loginApi = [[AuthAPI alloc]init]; // loginApi.noNeedSendAgain = YES; // //将获取的离线消息数据回调 // [loginApi requestWithObject:params Completion:^(id response, NSError *error) { //// if (error) { //// return ; //// } // //Error Domain=请求超时 Code=1001 "(null)" // block(response, error); // }]; //} -(BOOL)isNull:(NSDictionary*) data{ return (!data || [data isKindOfClass:[NSNull class]]); } -(void)alertWithMessage:(NSString *)msg { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alertView show]; } @end