RQHTTPResponse.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // RQHTTPResponse.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/16.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQHTTPResponse.h"
  9. #import "RQHTTPServiceConstant.h"
  10. @interface RQHTTPResponse ()
  11. /// The parsed RQObject object corresponding to the API response.
  12. /// The developer need care this data
  13. @property (nonatomic, readwrite, strong) id parsedResult;
  14. /// 自己服务器返回的状态码
  15. @property (nonatomic, readwrite, assign) RQHTTPResponseCode code;
  16. /// 自己服务器返回的信息
  17. @property (nonatomic, readwrite, copy) NSString *msg;
  18. @end
  19. @implementation RQHTTPResponse
  20. - (instancetype)initWithResponseObject:(id)responseObject parsedResult:(id)parsedResult {
  21. self = [super init];
  22. if (self) {
  23. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  24. NSDictionary *dic = responseObject;
  25. NSMutableDictionary *mydic = dic.mutableCopy;
  26. if ([mydic.allKeys containsObject:@"path"]) {
  27. if ([mydic[@"path"] isEqualToString:RQ_GET_Userinfo]) {
  28. [mydic removeObjectForKey:@"path"];
  29. self.parsedResult = [RQWechatUserInfoModel wechatUserInfoModelWithDictionary:mydic.copy];
  30. self.code = 200;
  31. self.msg = @"";
  32. } else if ([mydic[@"path"] isEqualToString:RQ_GET_Refresh_token]) {
  33. [mydic removeObjectForKey:@"path"];
  34. self.parsedResult = [RQWechatRefreshTokenModel wechatRefreshTokenModelWithDictionary: mydic.copy];
  35. self.code = 200;
  36. self.msg = @"";
  37. } else {
  38. self.parsedResult = parsedResult ?:NSNull.null;
  39. self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue];
  40. self.msg = responseObject[RQHTTPServiceResponseMsgKey];
  41. }
  42. } else {
  43. self.parsedResult = parsedResult ?:NSNull.null;
  44. self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue];
  45. self.msg = responseObject[RQHTTPServiceResponseMsgKey];
  46. }
  47. } else {
  48. self.parsedResult = parsedResult ?:NSNull.null;
  49. self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue];
  50. self.msg = responseObject[RQHTTPServiceResponseMsgKey];
  51. }
  52. }
  53. return self;
  54. }
  55. @end