KSNetworkingManager.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. //
  2. // KSNetworkingManager.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "KSNetworkingManager.h"
  8. #import "KeyChainTools.h"
  9. #import "LoginViewController.h"
  10. #import "AppDelegate.h"
  11. #import <RongIMKit/RongIMKit.h>
  12. #import "JPUSHService.h"
  13. #import "RCConnectionManager.h"
  14. #import "CustomNavViewController.h"
  15. @implementation KSNetworkingManager
  16. + (void)configRequestHeader {
  17. if (![NSString isEmptyString:UserDefault(TokenKey)]) {
  18. [[VoNetworking sharedManager] configHttpHeader:@{@"Authorization":[NSString stringWithFormat:@"%@ %@", UserDefault(Token_type), UserDefault(TokenKey)]}];
  19. }
  20. }
  21. + (void)configRequestFormHeaderWithToken:(NSString *)token {
  22. if (![NSString isEmptyString:token]) {
  23. [[VoNetworking sharedManager] configHttpHeader:@{@"Authorization":[NSString stringWithFormat:@"%@ %@", UserDefault(Token_type), token], @"Content-Type":@"application/x-www-form-urlencoded"}];
  24. }
  25. else if (![NSString isEmptyString:UserDefault(TokenKey)]) {
  26. [[VoNetworking sharedManager] configHttpHeader:@{@"Authorization":[NSString stringWithFormat:@"%@ %@", UserDefault(Token_type), UserDefault(TokenKey)], @"Content-Type":@"application/x-www-form-urlencoded"}];
  27. }
  28. else {
  29. [[VoNetworking sharedManager] configHttpHeader:@{@"Content-Type":@"application/x-www-form-urlencoded"}];
  30. }
  31. }
  32. + (void)clearRequestHeader {
  33. [[VoNetworking sharedManager] removeHeaderKey];
  34. }
  35. // 设置表单提交方式
  36. + (void)configRequestMethodForm {
  37. [VoNetworking sharedManager].httpSessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
  38. [self configRequestFormHeaderWithToken:nil];
  39. }
  40. + (void)configRequestMethodFormWithToken:(NSString *)token {
  41. [VoNetworking sharedManager].httpSessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
  42. [self configRequestFormHeaderWithToken:token];
  43. }
  44. // 设置json提交方式
  45. + (void)configRequestMethodJSON {
  46. [VoNetworking sharedManager].httpSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  47. [self configRequestHeader];
  48. }
  49. + (NSString *)returnNoContainGroupId:(NSString *)groupId {
  50. if (![NSString isEmptyString:groupId]) {
  51. if ([groupId containsString:@"S"] || [groupId containsString:@"I"]) {
  52. groupId = [groupId substringFromIndex:1];
  53. }
  54. }
  55. return groupId;
  56. }
  57. /**
  58. * 封装网络请求
  59. */
  60. + (void)request:(NSString *)post andWithUrl:(NSString *)myUrl and:(id)parm success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  61. __block NSDictionary *dic;
  62. #pragma mark ----- 签名
  63. // parm = [NSString signToMD5:parm];
  64. NSLog(@"%@",[parm mj_JSONString]);
  65. // post
  66. if ([post isEqualToString:KS_POST]) {
  67. [[VoNetworking sharedManager] postWithUrl:myUrl refreshRequest:YES cache:NO params:parm progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
  68. NSLog(@"%lld--%lld",bytesRead,totalBytes);
  69. } successBlock:^(id response) {
  70. dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
  71. if ([dic integerValueForKey:@"code"] == 403) { // token验证失败
  72. [self logOutWithType:YES];
  73. return ;
  74. }
  75. else if ([dic integerValueForKey:@"code"] == 401) {
  76. [self logOutWithType:NO];
  77. return ;
  78. }
  79. success(dic);
  80. return ;
  81. } failBlock:^(NSError *error) {
  82. NSLog(@"%@",error.description);
  83. faliure(error);
  84. if (error.code == -1001) {
  85. [self showMessage:@"网络请求超时"];
  86. }
  87. else if (error.code != -999) {
  88. [self showMessage:@"网络或服务器错误,请重试"];
  89. }
  90. }];
  91. }
  92. // get
  93. else {
  94. [[VoNetworking sharedManager] getWithUrl:myUrl refreshRequest:YES cache:NO params:parm progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
  95. NSLog(@"%lld--%lld",bytesRead,totalBytes);
  96. } successBlock:^(id response) {
  97. dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
  98. if ([dic integerValueForKey:@"code"] == 403) { // token验证失败
  99. [self logOutWithType:YES];
  100. return;
  101. }
  102. else if ([dic integerValueForKey:@"code"] == 401) {
  103. [self logOutWithType:NO];
  104. return;
  105. }
  106. success(dic);
  107. return ;
  108. } failBlock:^(NSError *error) {
  109. NSLog(@"%@",error.description);
  110. faliure(error);
  111. if (error.code == -1001) {
  112. [self showMessage:@"网络请求超时"];
  113. }
  114. else if (error.code != -999) {
  115. [self showMessage:@"网络或服务器错误,请重试"];
  116. }
  117. }];
  118. }
  119. }
  120. + (void)logOutWithType:(BOOL)isDisable {
  121. // 移除所有的loadView
  122. [[VoNetworking sharedManager] cancleAllRequest];
  123. [MBProgressHUD hideHUD];
  124. if (isDisable) {
  125. [self showMessage:@"登录过期,请重新登录"];
  126. }
  127. else {
  128. [self showMessage:@"未认证"];
  129. }
  130. [self logoutAction];
  131. }
  132. + (void)logoutAction {
  133. [self clearRequestHeader];
  134. // 取消推送别名
  135. [JPUSHService deleteAlias:nil seq:0];
  136. // 清除数据信息
  137. UserDefaultRemoveObjectForKey(TokenKey);
  138. UserDefaultRemoveObjectForKey(RongTokenKey);
  139. [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
  140. [RCConnectionManager shareManager].isNeedJoin = NO;
  141. [RCConnectionManager shareManager].isNeedShowMessage = NO;
  142. [[RCIM sharedRCIM] logout];
  143. // 回到登录界面
  144. UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
  145. if ([vc.presentedViewController isKindOfClass:NSClassFromString(@"NewClassroomViewController")]) {
  146. [[NSNotificationCenter defaultCenter] postNotificationName:@"classroomLogout" object:nil];
  147. }
  148. else if ([vc isKindOfClass:[UITabBarController class]]) {
  149. UITabBarController *tab = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
  150. CustomNavViewController *ctrl = (CustomNavViewController *)tab.selectedViewController;
  151. [ctrl popToRootViewControllerAnimated:NO];
  152. LoginViewController *logonVC = [[LoginViewController alloc] init];
  153. CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:logonVC];
  154. navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
  155. [tab.selectedViewController presentViewController:navCtrl animated:YES completion:nil];
  156. }
  157. }
  158. // 提示信息
  159. + (void)showMessage:(NSString *)message {
  160. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication].windows lastObject] animated:YES];
  161. hud.removeFromSuperViewOnHide =YES;
  162. hud.mode = MBProgressHUDModeText;
  163. hud.label.text = message;
  164. hud.minSize = CGSizeMake(132.f, 60.0f);
  165. hud.label.textColor = [UIColor whiteColor];
  166. hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
  167. hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
  168. [hud hideAnimated:YES afterDelay:2];
  169. }
  170. // 多文件上传
  171. + (void)uploadMultiFileWithFileArray:(NSArray *)datas
  172. andWithUrl:(NSString *)myUrl
  173. parameters:(NSDictionary *)parameters
  174. type:(NSString *)type
  175. name:(NSString *)name
  176. mimeType:(NSString *)mimeType
  177. progress:(void(^)(NSProgress * _Nonnull uploadProgress))progress
  178. success:(void(^)(NSMutableArray *dics))success
  179. faliure:(void(^)(NSError *error))faliure {
  180. __block NSMutableArray *dics = [NSMutableArray array];
  181. [[VoNetworking sharedManager] uploadMultFileWithUrl:myUrl parameters:parameters fileDatas:datas type:type name:name mimeType:mimeType progressBlock:^(int64_t bytesWritten, int64_t totalBytes) {
  182. } successBlock:^(NSArray *responses) {
  183. for (id response in responses) {
  184. NSDictionary *subDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
  185. [dics addObject:subDic];
  186. }
  187. success(dics);
  188. } failBlock:^(NSArray *errors) {
  189. [self showMessage:@"网络或服务器错误,请重试"];
  190. faliure([errors lastObject]);
  191. }];
  192. }
  193. // 单文件上传
  194. + (void)uploadFileWithFileData:(NSData *)data
  195. andWithUrl:(NSString *)myUrl
  196. parameters:(NSDictionary *)parameters
  197. type:(NSString *)type
  198. name:(NSString *)name
  199. mimeType:(NSString *)mimeType
  200. progress:(void(^)(int64_t bytesWritten,
  201. int64_t totalBytes))progress
  202. success:(void(^)(NSDictionary *dic))success
  203. faliure:(void(^)(NSError *error))faliure {
  204. __block NSDictionary *dic;
  205. [[VoNetworking sharedManager] uploadFileWithUrl:myUrl parameters:parameters fileData:data type:type name:name mimeType:mimeType progressBlock:^(int64_t bytesWritten, int64_t totalBytes) {
  206. if (progress) {
  207. progress(bytesWritten, totalBytes);
  208. }
  209. } successBlock:^(id response) {
  210. dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
  211. success(dic);
  212. return ;
  213. } failBlock:^(NSError *error) {
  214. faliure(error);
  215. [self showMessage:@"网络或服务器错误,请重试"];
  216. }];
  217. }
  218. // 下载
  219. + (void)downloadTaskWithUrl:(NSString *)myUrl
  220. progress:(void(^)(int64_t bytesRead, int64_t totalBytes))progress
  221. success:(void(^)(NSURL *fileUrl))success
  222. faliure:(void(^)(NSError *error))faliure {
  223. [self clearRequestHeader];
  224. [[VoNetworking sharedManager] downloadWithUrl:myUrl progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
  225. if (progress) {
  226. progress(bytesRead, totalBytes);
  227. }
  228. } successBlock:^(NSURL * _Nullable url) {
  229. [self configRequestHeader];
  230. if (success) {
  231. success(url);
  232. }
  233. } failBlock:^(NSError * _Nonnull error) {
  234. if (faliure) {
  235. faliure(error);
  236. }
  237. [self showMessage:@"网络或服务器错误,请重试"];
  238. [self configRequestHeader];
  239. }];
  240. }
  241. // 多文件下载
  242. + (void)mutilDownTaskWithUrl:(NSArray *)urlArray
  243. progress:(void(^)(int64_t bytesRead, int64_t totalBytes))progress
  244. successBlock:(void(^)(NSMutableArray *dics))success
  245. failBlock:(void(^)(NSError *error))faliure {
  246. [self clearRequestHeader];
  247. [[VoNetworking sharedManager] downloadMutilFileWithUrl:urlArray progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
  248. } successBlock:^(NSArray * _Nonnull responses) {
  249. [self configRequestHeader];
  250. NSMutableArray *result = [NSMutableArray arrayWithArray:responses];
  251. success(result);
  252. } failBlock:^(NSArray * _Nonnull errors) {
  253. [self showMessage:@"网络或服务器错误,请重试"];
  254. [self configRequestHeader];
  255. faliure([errors lastObject]);
  256. }];
  257. }
  258. #pragma mark ---- 图片上传
  259. /**
  260. 图片上传
  261. @param post post
  262. @param pics 图片的数组
  263. @param success 成功
  264. @param faliure 失败
  265. */
  266. + (void)multiImageUpload:(NSString *)post imgDataArray:(NSArray *)pics success:(void(^)(NSArray *dics))success faliure:(void(^)(NSError *error))faliure {
  267. NSString* url = [NSString stringWithFormat:@"%@%@",hostURL,@"/api-student/uploadFile"];
  268. NSString *type = [UIImage typeForImageData:[pics lastObject]];
  269. [self uploadMultiFileWithFileArray:pics andWithUrl:url parameters:nil type:type name:@"file" mimeType:[NSString stringWithFormat:@"Image/%@",type] progress:nil success:success faliure:faliure];
  270. }
  271. #pragma mark ----- 视频文件上传
  272. /**
  273. 视频文件上传
  274. @param post post
  275. @param fileData 文件data
  276. @param progress 进度
  277. @param success 成功
  278. @param faliure 失败
  279. */
  280. + (void)videoFileUpload:(NSString *)post fileData:(NSData *)fileData progress:(void(^)(int64_t bytesWritten,int64_t totalBytes))progress success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure; {
  281. [self configRequestMethodJSON];
  282. NSString* url = [NSString stringWithFormat:@"%@%@",hostURL,@"/api-student/uploadFile"];
  283. [self uploadFileWithFileData:fileData andWithUrl:url parameters:nil type:@".mp4" name:@"file" mimeType:[NSString stringWithFormat:@"Image/.mp4"] progress:progress success:success faliure:faliure];
  284. }
  285. #pragma mark ---- 文件下载
  286. + (void)downloadFileRequestWithFileUrl:(NSString *)url progress:(void (^)(int64_t, int64_t))progress success:(void (^)(NSURL * _Nonnull))success faliure:(void (^)(NSError * _Nonnull))faliure {
  287. [self downloadTaskWithUrl:url progress:progress success:success faliure:faliure];
  288. }
  289. + (void)mutiDownloadFileRequest:(NSArray *)fileUrl progress:(void (^)(int64_t, int64_t))progress success:(void (^)(NSArray * _Nonnull))success faliure:(void (^)(NSError * _Nonnull))faliure {
  290. [self mutilDownTaskWithUrl:fileUrl progress:progress successBlock:success failBlock:faliure];
  291. }
  292. #pragma mark ----- 登录相关
  293. + (void)LoginRequest:(NSString *)post phone:(NSString *)phone password:(NSString *)password success:(void (^)(NSDictionary * _Nonnull))success faliure:(void (^)(NSError * _Nonnull))faliure {
  294. [self configRequestMethodForm];
  295. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  296. [parm setValue:@"student" forKey:@"clientId"];
  297. [parm setValue:@"student" forKey:@"clientSecret"];
  298. [parm setValue:phone forKey:@"username"];
  299. [parm setValue:password forKey:@"password"];
  300. [parm setValue:[KeyChainTools getUUID] forKey:@"deviceNum"];
  301. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL,@"/api-auth/usernameLogin"];
  302. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  303. }
  304. // /api-auth/smsLogin
  305. /**
  306. 验证码登录/注册
  307. @param post post
  308. @param phone 手机号
  309. @param smsCode 验证码
  310. @param success 成功
  311. @param faliure 失败
  312. */
  313. + (void)smsLoginRequest:(NSString *)post phone:(NSString *)phone smsCode:(NSString *)smsCode success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  314. [self configRequestMethodForm];
  315. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  316. [parm setValue:@"student" forKey:@"clientId"];
  317. [parm setValue:@"student" forKey:@"clientSecret"];
  318. [parm setValue:phone forKey:@"phone"];
  319. [parm setValue:smsCode forKey:@"smsCode"];
  320. [parm setValue:@"IOS" forKey:@"channel"];
  321. [parm setValue:@"true" forKey:@"isSurportRegister"];
  322. [parm setValue:[KeyChainTools getUUID] forKey:@"deviceNum"];
  323. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL,@"/api-auth/smsLogin"];
  324. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  325. }
  326. // /api-auth/refreshToken
  327. /**
  328. 刷新token的逻辑
  329. @param post post
  330. @param success 成功
  331. @param faliure 失败
  332. */
  333. + (void)refreshTokenRequest:(NSString *)post success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  334. [self configRequestMethodForm];
  335. [self clearRequestHeader];
  336. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  337. [parm setValue:@"student" forKey:@"clientId"];
  338. [parm setValue:@"student" forKey:@"clientSecret"];
  339. [parm setValue:UserDefault(RefreshToken) forKey:@"refreshToken"];
  340. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/refreshToken"];
  341. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  342. }
  343. // /api-auth/checkToken
  344. /// 校验token是否有效
  345. /// @param get get
  346. /// @param success 成功
  347. /// @param faliure 失败
  348. + (void)checkTokenRequest:(NSString *)get success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  349. [self configRequestMethodForm];
  350. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/checkToken"];
  351. [self request:get andWithUrl:url and:nil success:success faliure:faliure];
  352. }
  353. // 接口地址 /api-auth/user/setUsernameAndPassword
  354. /**
  355. 设置密码
  356. @param post post
  357. @param username 用户名
  358. @param password 密码
  359. @param token token
  360. @param success 成功
  361. @param faliure 失败
  362. */
  363. + (void)setPasswordRequest:(NSString *)post username:(NSString *)username password:(NSString *)password token:(NSString *)token success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  364. [self configRequestMethodFormWithToken:token];
  365. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  366. [parm setValue:username forKey:@"username"];
  367. [parm setValue:password forKey:@"password"];
  368. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/user/setUsernameAndPassword"];
  369. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  370. }
  371. // /api-auth/user/updatePassword
  372. /**
  373. 修改密码
  374. @param post post
  375. @param authCode 验证码
  376. @param mobile 手机号
  377. @param newPassword 新密码
  378. @param success 成功
  379. @param faliure 失败
  380. */
  381. + (void)updatePasswordRequest:(NSString *)post authCode:(NSString *)authCode mobile:(NSString *)mobile newPassword:(NSString *)newPassword success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  382. [self configRequestMethodForm];
  383. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  384. [parm setValue:mobile forKey:@"mobile"];
  385. [parm setValue:authCode forKey:@"authCode"];
  386. [parm setValue:newPassword forKey:@"newPassword"];
  387. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/user/updatePassword"];
  388. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  389. }
  390. // /api-auth/user/checkUser
  391. /// 用户信息校验
  392. /// @param get get
  393. /// @param phone 手机号
  394. /// @param password 密码
  395. /// @param success 成功
  396. /// @param faliure 失败
  397. + (void)checkUserRequest:(NSString *)get phone:(NSString *)phone password:(NSString *)password success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  398. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/user/checkUser"];
  399. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  400. [parm setValue:phone forKey:@"phone"];
  401. [parm setValue:password forKey:@"password"];
  402. [self request:get andWithUrl:url and:parm success:success faliure:faliure];
  403. }
  404. // /api-auth/user/updatePhone
  405. /// 修改手机号
  406. /// @param post post
  407. /// @param oldPhone 旧手机号
  408. /// @param authCode 验证码
  409. /// @param newPhone 新手机号码
  410. /// @param success 成功
  411. /// @param faliure 失败
  412. + (void)updatePhoneRequest:(NSString *)post oldPhone:(NSString *)oldPhone authCode:(NSString *)authCode newPhone:(NSString *)newPhone success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  413. [self configRequestMethodForm];
  414. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/user/updatePhone"];
  415. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  416. [parm setValue:oldPhone forKey:@"oldPhone"];
  417. [parm setValue:authCode forKey:@"authCode"];
  418. [parm setValue:newPhone forKey:@"newPhone"];
  419. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  420. }
  421. // /api-auth/user/refreshImToken
  422. /// 刷新IM token
  423. /// @param post post
  424. /// @param success 成功
  425. /// @param faliure 失败
  426. + (void)refreshImTokenRequest:(NSString *)post success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  427. [self configRequestMethodForm];
  428. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/user/refreshImToken"];
  429. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  430. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  431. }
  432. // /api-auth/exit
  433. /**
  434. 退出登录
  435. @param post 请求
  436. @param success 成功
  437. @param faliure 失败
  438. */
  439. + (void)logoutRequest:(NSString *)post success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  440. [self configRequestMethodForm];
  441. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  442. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/exit"];
  443. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  444. }
  445. // /api-student/subject/subjectSelect
  446. /// 声部信息查询 (树状列表)
  447. /// @param get get
  448. /// @param success 成功
  449. /// @param faliure 失败
  450. + (void)studentQuerySubject:(NSString *)get success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  451. NSString *url = [NSString stringWithFormat:@"%@%@", hostURL, @"/api-student/subject/subjectSelect"];
  452. [self request:get andWithUrl:url and:nil success:success faliure:faliure];
  453. }
  454. // /api-student/student/setSubject
  455. /// 设置声部
  456. /// @param get get
  457. /// @param subjectIds 声部id
  458. /// @param success 成功
  459. /// @param faliure 失败
  460. + (void)studentSetSubject:(NSString *)get subjectIds:(NSString *)subjectIds success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  461. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/student/setSubject"];
  462. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  463. [parm setValue:subjectIds forKey:@"subjectIds"];
  464. [self request:get andWithUrl:url and:parm success:success faliure:faliure];
  465. }
  466. #pragma mark ---- 验证码服务
  467. // /api-student/code/sendSms
  468. /**
  469. 发送短信验证码
  470. @param post post
  471. @param mobile 手机号码
  472. @param success 成功
  473. @param faliure 失败
  474. */
  475. + (void)sendSmsRequest:(NSString *)post mobile:(NSString *)mobile success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  476. [self configRequestMethodForm];
  477. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  478. [parm setValue:mobile forKey:@"mobile"];
  479. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/code/sendSmsCode"];
  480. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  481. }
  482. // /api-student/code/verifyImageCode
  483. /**
  484. 图形验证码校验
  485. @param post post
  486. @param phone 手机号
  487. @param code 验证码
  488. @param success 成功
  489. @param faliure 失败
  490. */
  491. + (void)verifyLoginImageRequest:(NSString *)post phone:(NSString *)phone code:(NSString *)code success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  492. [self configRequestMethodForm];
  493. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  494. [parm setValue:phone forKey:@"phone"];
  495. [parm setValue:code forKey:@"code"];
  496. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/code/verifyImageCode"];
  497. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  498. }
  499. #pragma mark ----- 查询用户信息
  500. // /api-auth/queryUserInfo
  501. /**
  502. 获取个人信息
  503. @param get get
  504. @param success 成功
  505. @param faliure 失败
  506. */
  507. + (void)queryUserInfo:(NSString *)get success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  508. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/api/queryUserInfo"];
  509. [self request:get andWithUrl:url and:nil success:success faliure:faliure];
  510. }
  511. // /api-student/Student/queryUserInfo
  512. /// 查询学生信息
  513. /// @param get get
  514. /// @param success 成功
  515. /// @param faliure 失败
  516. + (void)queryStudentInfoRequest:(NSString *)get success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  517. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/student/queryUserInfo"];
  518. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  519. [self request:get andWithUrl:url and:parm success:success faliure:faliure];
  520. }
  521. // /api-auth/user/submitSetDetail
  522. /// 修改用户信息
  523. /// @param post post
  524. /// @param avatal 头像
  525. /// @param gender 性别
  526. /// @param username 昵称
  527. /// @param success 成功
  528. /// @param faliure 失败
  529. + (void)modifyUserMessage:(NSString *)post avatal:(NSString *)avatal gender:(NSString *)gender username:(NSString *)username success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  530. [self configRequestMethodJSON];
  531. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-auth/user/submitSetDetail"];
  532. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  533. [parm setValue:avatal forKey:@"avatar"];
  534. [parm setValue:gender forKey:@"gender"];
  535. [parm setValue:username forKey:@"username"];
  536. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  537. }
  538. #pragma mark -------- 群组服务
  539. // /api-student/imUserFriend/queryAll
  540. /// 查询好友列表
  541. /// @param post post
  542. /// @param search 搜索
  543. /// @param success 成功
  544. /// @param faliure 失败
  545. + (void)imUserFriendRequest:(NSString *)post search:(NSString *)search success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  546. [self configRequestMethodJSON];
  547. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/imUserFriend/queryAll"];
  548. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  549. [parm setValue:search forKey:@"search"];
  550. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  551. }
  552. // /api-student/imGroup/queryAll
  553. /// 查询老师群组列表
  554. /// @param post post
  555. /// @param search 搜索
  556. /// @param success 成功
  557. /// @param faliure 失败
  558. + (void)imGroupQueryPage:(NSString *)post search:(NSString *)search success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  559. [self configRequestMethodJSON];
  560. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/imGroup/queryAll"];
  561. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  562. [parm setValue:search forKey:@"search"];
  563. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  564. }
  565. // /api-student/imGroup/getDetail/{groupId}
  566. /// 获取群信息
  567. /// @param post post
  568. /// @param groupId 群id
  569. /// @param success 成功
  570. /// @param faliure 失败
  571. + (void)queryGroupDetail:(NSString *)post groupId:(NSString *)groupId success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  572. [self configRequestMethodJSON];
  573. NSString *url = [NSString stringWithFormat:@"%@%@/%@",hostURL, @"/api-student/imGroup/getDetail",groupId];
  574. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  575. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  576. }
  577. // 获取群成员列表
  578. // /api-student/imGroupMember/queryAll
  579. /// 查询群成员列表
  580. /// @param post post
  581. /// @param groupId 群id
  582. /// @param success 成功
  583. /// @param faliure 失败
  584. + (void)imGroupMemberAllRequest:(NSString *)post groupId:(NSString *)groupId success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  585. [self configRequestMethodJSON];
  586. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/imGroupMember/queryAll"];
  587. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  588. [parm setValue:groupId forKey:@"groupId"];
  589. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  590. }
  591. // 查询群成员
  592. // /api-student/imGroupMember/getUserDetail
  593. /// 查询群成员信息
  594. /// @param post post
  595. /// @param groupId 群id
  596. /// @param userId 用户id
  597. /// @param success 成功
  598. /// @param faliure 失败
  599. + (void)imGroupMemberQueryUser:(NSString *)post groupId:(NSString *)groupId userId:(NSString *)userId success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  600. [self configRequestMethodJSON];
  601. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/imGroupMember/getUserDetail"];
  602. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  603. [parm setValue:groupId forKey:@"groupId"];
  604. [parm setValue:userId forKey:@"userId"];
  605. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  606. }
  607. // 获取IM好友详情
  608. // /api-student/imUserFriend/getDetail/{userId}
  609. /// 获取好友详情
  610. /// @param post post
  611. /// @param userId 用户id
  612. /// @param success 成功
  613. /// @param faliure 失败
  614. + (void)imUserFriendQueryDetail:(NSString *)post userId:(NSString *)userId success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  615. [self configRequestMethodJSON];
  616. NSString *url = [NSString stringWithFormat:@"%@%@/%@",hostURL, @"/api-student/imUserFriend/getDetail",userId];
  617. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  618. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  619. }
  620. // /api-student/imGroupMemberAudit/queryPage
  621. /// 申请入群列表
  622. /// @param post post
  623. /// @param groupId 群id
  624. /// @param success 成功
  625. /// @param faliure 失败
  626. + (void)imGroupMemberAuditListRequest:(NSString *)post groupId:(NSString *)groupId success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  627. [self configRequestMethodJSON];
  628. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/imGroupMemberAudit/queryPage"];
  629. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  630. [parm setValue:groupId forKey:@"groupId"];
  631. [parm setValue:@(1) forKey:@"page"];
  632. [parm setValue:@(200) forKey:@"rows"];
  633. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  634. }
  635. #pragma mark ---- 群公告
  636. // /api-student/imGroupNotice/queryPage
  637. /// 群公告列表查询
  638. /// @param post post
  639. /// @param groupId 群组id
  640. /// @param page 分页
  641. /// @param rows 条数
  642. /// @param success 成功
  643. /// @param faliure 失败
  644. + (void)queryNoticeListRequest:(NSString *)post groupId:(NSString *)groupId page:(NSString *)page rows:(NSString *)rows success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  645. [self configRequestMethodJSON];
  646. NSString *url = [NSString stringWithFormat:@"%@%@",hostURL, @"/api-student/imGroupNotice/queryPage"];
  647. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  648. [parm setValue:groupId forKey:@"groupId"];
  649. [parm setValue:page forKey:@"page"];
  650. [parm setValue:rows forKey:@"rows"];
  651. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  652. }
  653. #pragma mark ----- 直播相关
  654. // 进入直播房间
  655. // /api-student/liveRoom/joinRoom
  656. /// 进入房间
  657. /// @param get get
  658. /// @param roomUid 直播房间号
  659. /// @param success 成功
  660. /// @param faliure 失败
  661. + (void)liveRoomJoinRoomRequest:(NSString *)get roomUid:(NSString *)roomUid success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  662. NSString *url = [NSString stringWithFormat:@"%@%@", hostURL, @"/api-student/liveRoom/joinRoom"];
  663. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  664. [parm setValue:roomUid forKey:@"roomUid"];
  665. [parm setValue:UserDefault(UIDKey) forKey:@"userId"];
  666. [self request:get andWithUrl:url and:parm success:success faliure:faliure];
  667. }
  668. // 退出直播间通知
  669. // /api-student/liveRoom/syncUserStatus
  670. /// 退出直播间
  671. /// @param post post json
  672. /// @param success 成功
  673. /// @param faliure 失败
  674. + (void)LiveroomQuit:(NSString *)post success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  675. [self configRequestMethodJSON];
  676. NSString *url = [NSString stringWithFormat:@"%@%@", SEALCLASSHOST, @"/api-student/liveRoom/syncUserStatus"];
  677. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  678. [parm setValue:@"iOS" forKey:@"os"];
  679. [parm setValue:@"3" forKey:@"status"];
  680. [parm setValue:UserDefault(UIDKey) forKey:@"userid"];
  681. [self request:post andWithUrl:url and:@[parm] success:success faliure:faliure];
  682. }
  683. #pragma mark ----- 课表
  684. // /api-student/courseSchedule/queryCourseScheduleStudent
  685. /// 课表日历
  686. /// @param post post
  687. /// @param classMonth 月份
  688. /// @param success 成功
  689. /// @param faliure 失败
  690. + (void)queryCourseSchedule:(NSString *)post classMonth:(NSString *)classMonth success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  691. [self configRequestMethodJSON];
  692. NSString *url = [NSString stringWithFormat:@"%@%@", hostURL, @"/api-student/courseSchedule/queryCourseScheduleStudent"];
  693. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  694. [parm setValue:classMonth forKey:@"classMonth"];
  695. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  696. }
  697. // /api-student/courseSchedule/queryCourseUser
  698. /// 查询日期课程
  699. /// @param post post
  700. /// @param classDate 日期
  701. /// @param success 成功
  702. /// @param faliure 失败
  703. + (void)queryCourseForDay:(NSString *)post classDate:(NSString *)classDate success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
  704. [self configRequestMethodJSON];
  705. NSString *url = [NSString stringWithFormat:@"%@%@", hostURL, @"/api-student/courseSchedule/queryCourseUser"];
  706. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  707. [parm setValue:classDate forKey:@"classDate"];
  708. [self request:post andWithUrl:url and:parm success:success faliure:faliure];
  709. }
  710. @end