Nenhuma Descrição

LFWSendCodeRequest.m 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // LFWSendCodeRequest.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LFWSendCodeRequest.h"
  9. @implementation LFWSendCodeRequest
  10. + (void)post:(NSString *)url params:(id)params success:(void(^)(id json))success failure:(void(^)(NSError *error))failure {
  11. // 1.创建请求管理者
  12. AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
  13. mgr.requestSerializer = [AFHTTPRequestSerializer serializer]; // 解析为data
  14. mgr.responseSerializer=[AFHTTPResponseSerializer serializer];
  15. mgr.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",nil];
  16. mgr.requestSerializer.timeoutInterval = 15;
  17. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  18. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  19. [mgr.requestSerializer setValue:app_Version forHTTPHeaderField:@"version"];
  20. // 2.发送请求
  21. [mgr POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  22. id responseDict =[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
  23. if ([responseDict[@"errno"] isEqualToString:@"0"]) {
  24. if (!responseDict[@"rst"]) {
  25. success(@{});
  26. }else{
  27. [SVProgressHUD showSuccessWithStatus:@"发送成功"];
  28. success(responseDict[@"rst"]);
  29. }
  30. }else{
  31. if ([responseDict[@"errno"] isEqualToString:@"1005"]) {
  32. [SVProgressHUD showErrorWithStatus:@"请输入合法的手机号"];
  33. }else if ([responseDict[@"errno"] isEqualToString:@"1007"]){
  34. [SVProgressHUD showErrorWithStatus:@"签名不合法 "];
  35. }else if ([responseDict[@"errno"] isEqualToString:@"1008"]){
  36. [SVProgressHUD showErrorWithStatus:@"请求时间不合法 "];
  37. }else{
  38. NSString *errorStr = responseDict[@"err"];
  39. if (errorStr) {
  40. return ;
  41. }
  42. [SVProgressHUD showErrorWithStatus:@"发送失败"];
  43. }
  44. NSError *error = nil;
  45. failure(error);
  46. }
  47. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  48. if (failure) {
  49. failure(error);
  50. }
  51. }];
  52. }
  53. @end