// // RQHTTPResponse.m // RQCommon // // Created by 张嵘 on 2018/11/16. // Copyright © 2018 张嵘. All rights reserved. // #import "RQHTTPResponse.h" #import "RQHTTPServiceConstant.h" @interface RQHTTPResponse () /// The parsed RQObject object corresponding to the API response. /// The developer need care this data @property (nonatomic, readwrite, strong) id parsedResult; /// 自己服务器返回的状态码 @property (nonatomic, readwrite, assign) RQHTTPResponseCode code; /// 自己服务器返回的信息 @property (nonatomic, readwrite, copy) NSString *msg; @end @implementation RQHTTPResponse - (instancetype)initWithResponseObject:(id)responseObject parsedResult:(id)parsedResult { self = [super init]; if (self) { if ([responseObject isKindOfClass:[NSDictionary class]]) { NSDictionary *dic = responseObject; NSMutableDictionary *mydic = dic.mutableCopy; if ([mydic.allKeys containsObject:@"path"]) { if ([mydic[@"path"] isEqualToString:RQ_GET_Userinfo]) { [mydic removeObjectForKey:@"path"]; self.parsedResult = [RQWechatUserInfoModel wechatUserInfoModelWithDictionary:mydic.copy]; self.code = 200; self.msg = @""; } else if ([mydic[@"path"] isEqualToString:RQ_GET_Refresh_token]) { [mydic removeObjectForKey:@"path"]; self.parsedResult = [RQWechatRefreshTokenModel wechatRefreshTokenModelWithDictionary: mydic.copy]; self.code = 200; self.msg = @""; } else { self.parsedResult = parsedResult ?:NSNull.null; self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue]; self.msg = responseObject[RQHTTPServiceResponseMsgKey]; } } else { self.parsedResult = parsedResult ?:NSNull.null; self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue]; self.msg = responseObject[RQHTTPServiceResponseMsgKey]; } } else { self.parsedResult = parsedResult ?:NSNull.null; self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue]; self.msg = responseObject[RQHTTPServiceResponseMsgKey]; } } return self; } @end