XSHttpTool.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // XSHttpTool.h
  3. //
  4. // Created by xiaos on 14/11/10.
  5. // Copyright © 2015年 com.xsdota. All rights reserved.
  6. //
  7. #import "AFNetworking.h"
  8. /** 设置主体API */
  9. static NSString *const HOST_ADDRESS = @"http://localhost:7888/Phalapi/Public/Demo";
  10. /** 设置API后的特定字符 */
  11. static NSString *const EXTRA_STR = @"?service=";
  12. /** 缓存保存时间 */
  13. static NSTimeInterval const TIMEOUT = 30;
  14. static NSTimeInterval const JSON_CACHE_DURATION = 3 * 24 * 60 * 60;
  15. static NSTimeInterval const IMAGE_CACHE_DURATION = 3 * 24 * 60 * 60;
  16. /** 成功失败进度的闭包 */
  17. typedef void(^successBlock)(id responseObject);
  18. typedef void(^failureBlock)(NSError *error);
  19. typedef void(^progressBlock)(float uploadPercent);
  20. @interface XSHttpTool : NSObject
  21. + (AFHTTPRequestOperationManager *)sharedManager;
  22. #pragma mark - GET
  23. #pragma mark 普通GET请求
  24. + (void)GET:(NSString *)requestKey
  25. param:(NSDictionary *)param
  26. success:(successBlock)success
  27. failure:(failureBlock)failure;
  28. #pragma mark 带缓存的GET请求 用于不常更新的数据
  29. + (void)GETCache:(NSString *)requestKey
  30. param:(NSDictionary *)param
  31. success:(successBlock)success
  32. failure:(failureBlock)failure;
  33. #pragma mark - POST
  34. #pragma mark 普通POST请求
  35. + (void)POST:(NSString *)requestKey
  36. param:(NSDictionary *)param
  37. success:(successBlock)success
  38. failure:(failureBlock)failure;
  39. #pragma mark 上传文件POST请求
  40. + (void)UpLoadData:(NSData *)data
  41. to:(NSString *)requestKey
  42. withParamName:(NSString *)paramName
  43. fileName:(NSString *)fileName
  44. mimeType:(NSString *)type
  45. param:(NSDictionary *)param
  46. success:(successBlock)success
  47. failure:(failureBlock)failure
  48. uploadProgress:(progressBlock)uploadProgress;
  49. #pragma mark 上传多图的POST请求
  50. /**
  51. * 上传带图片的内容,允许多张图片上传(URL)POST
  52. *
  53. * @param url 网络请求地址
  54. * @param images 要上传的图片数组(注意数组内容需是图片)
  55. * @param parameter 图片数组对应的参数
  56. * @param parameters 其他参数字典@
  57. * @param ratio 图片的压缩比例(0.0~1.0之间)
  58. * @param succeedBlock 成功的回调
  59. * @param failedBlock 失败的回调
  60. * @param uploadProgressBlock 上传进度的回调
  61. */
  62. + (void)upLoadImages:(NSArray *)images
  63. to:(NSString *)requestKey
  64. withParamName:(NSString *)paramName
  65. ratio:(float)ratio
  66. param:(NSDictionary *)param
  67. success:(successBlock)success
  68. failure:(failureBlock)failure
  69. uploadProgress:(progressBlock)uploadProgress;
  70. #pragma mark - cache管理
  71. + (BOOL)saveCache:(NSDictionary *)cache withIdentifier:(NSString *)cacheIdentifier;
  72. + (NSDictionary *)cacheWithIdentifier:(NSString *)cacheIdentifier;
  73. @end