// // Server.m // FirstLink // // Created by unicode on 14-9-29. // Copyright (c) 2014年 FirstLink. All rights reserved. // #import "FKServerUtil.h" #import "GDataXMLNode.h" //#ifdef DEBUG // #define SERVER_ADDRESS @"http://112.124.40.161" // 测试环境 // #define SERVER_ADDRESS @"http://121.41.54.182" // 预发环境 // #define SERVER_ADDRESS @"http://api.fine3q.com" // 生产环境 //#else // #define SERVER_ADDRESS @"http://112.124.40.161" // 测试环境 // #define SERVER_ADDRESS @"http://api.fine3q.com" // 生产环境 //#endif @interface FKServerUtil () @property (nonatomic, strong) NSString *domain; @property (nonatomic, strong) NSArray *ipArray; @property (nonatomic, strong) NSString *apiServer; @property (nonatomic, strong) NSString *webServer; @end @implementation FKServerUtil + (FKServerUtil *)sharedInstance { static FKServerUtil *sharedFKServerUtilInstance = nil; static dispatch_once_t once_token; dispatch_once(&once_token, ^{ sharedFKServerUtilInstance = [[self alloc] init]; }); return sharedFKServerUtilInstance; } - (void)loadServerConfig { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"FKServerConfig" ofType:@"xml"]; NSError *error; NSString *xmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error]; if (!error) { GDataXMLDocument *xmlDocument = [[GDataXMLDocument alloc] initWithXMLString:xmlString options:0 error:&error]; if (!error) { GDataXMLElement *rootElement = [xmlDocument rootElement]; NSString *targetElementName = @"Release"; #ifdef DEBUG targetElementName = @"Debug"; #endif GDataXMLElement *serverElement = [rootElement elementsForName:targetElementName].firstObject; if (serverElement) { GDataXMLElement *domainElement = [serverElement elementsForName:@"domain"].firstObject; self.domain = [domainElement stringValue]; GDataXMLElement *webElement = [serverElement elementsForName:@"Web"].firstObject; _webServer = [webElement stringValue]; GDataXMLElement *hostsElement = [serverElement elementsForName:@"hosts"].firstObject; NSMutableArray *ipAddresses = [NSMutableArray array]; for (GDataXMLElement *ipElement in [hostsElement elementsForName:@"ip"]) { [ipAddresses addObject:[ipElement stringValue]]; } self.ipArray = ipAddresses; } if (self.domain) { _apiServer = self.domain; } else { _apiServer = self.ipArray.firstObject; } } } } - (NSString *)apiServer { return [NSString stringWithFormat:@"https://%@", (_apiServer ? _apiServer : @"api.fine3q.com")]; } - (NSString *)webServer { return [NSString stringWithFormat:@"http://%@", (_webServer ? _webServer : @"m.fine3q.com")]; } - (void)receiveErrorDomain { #ifndef DEBUG if (self.ipArray.firstObject) { _apiServer = self.ipArray.firstObject; } #endif } - (void)resetServerToDomain { #ifndef DEBUG if (self.domain) { _apiServer = self.domain; } #endif } - (NSString *)alipayNotifyURL { return [NSString stringWithFormat:@"%@/link-site/web/payment/mobile_paynotify.do", self.apiServer]; } - (NSString *)aliGolbalPayNotifyURL { return [NSString stringWithFormat:@"%@/link-site/web/payment/global_paynotify.do", self.apiServer]; } @end