1
This commit is contained in:
@@ -18,12 +18,12 @@
|
||||
if (needShow) { [KBHUD dismiss]; }
|
||||
|
||||
if (error) {
|
||||
if (completion) completion(KB_PAY_ERROR_CODE, error.localizedDescription ?: @"网络错误");
|
||||
if (completion) completion(ERROR_CODE, error.localizedDescription ?: @"网络错误");
|
||||
return;
|
||||
}
|
||||
|
||||
NSInteger sta = [self.class extractStatusFromResponseObject:jsonOrData response:response];
|
||||
NSString *msg = [self.class extractMessageFromResponseObject:jsonOrData] ?: (sta == KB_PAY_SUCC_CODE ? @"OK" : @"失败");
|
||||
NSString *msg = [self.class extractMessageFromResponseObject:jsonOrData] ?: (sta == SUCCESS_CODE ? @"OK" : @"失败");
|
||||
if (completion) completion(sta, msg);
|
||||
}];
|
||||
}
|
||||
@@ -36,21 +36,21 @@
|
||||
NSDictionary *d = (NSDictionary *)obj;
|
||||
id code = d[@"code"] ?: d[@"status"] ?: d[@"retcode"];
|
||||
if ([code isKindOfClass:NSNumber.class]) {
|
||||
return [((NSNumber *)code) integerValue] == 0 ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
|
||||
return [((NSNumber *)code) integerValue] == 0 ? SUCCESS_CODE : ERROR_CODE;
|
||||
}
|
||||
if ([code isKindOfClass:NSString.class]) {
|
||||
// 常见:"0" 视为成功
|
||||
return [((NSString *)code) integerValue] == 0 ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
|
||||
return [((NSString *)code) integerValue] == 0 ? SUCCESS_CODE : ERROR_CODE;
|
||||
}
|
||||
id success = d[@"success"] ?: d[@"ok"];
|
||||
if ([success respondsToSelector:@selector(boolValue)]) {
|
||||
return [success boolValue] ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
|
||||
return [success boolValue] ? SUCCESS_CODE : ERROR_CODE;
|
||||
}
|
||||
}
|
||||
// 无明显字段,按 HTTP 2xx 视为成功
|
||||
NSInteger http = 0;
|
||||
if ([resp isKindOfClass:NSHTTPURLResponse.class]) { http = ((NSHTTPURLResponse *)resp).statusCode; }
|
||||
return (http >= 200 && http < 300) ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
|
||||
return (http >= 200 && http < 300) ? SUCCESS_CODE : ERROR_CODE;
|
||||
}
|
||||
|
||||
+ (NSString *)extractMessageFromResponseObject:(id)obj {
|
||||
|
||||
Reference in New Issue
Block a user