No Description

FKServerUtil.m 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // Server.m
  3. // FirstLink
  4. //
  5. // Created by unicode on 14-9-29.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "FKServerUtil.h"
  9. #import "GDataXMLNode.h"
  10. //#ifdef DEBUG
  11. // #define SERVER_ADDRESS @"http://112.124.40.161" // 测试环境
  12. // #define SERVER_ADDRESS @"http://121.41.54.182" // 预发环境
  13. // #define SERVER_ADDRESS @"http://api.fine3q.com" // 生产环境
  14. //#else
  15. // #define SERVER_ADDRESS @"http://112.124.40.161" // 测试环境
  16. // #define SERVER_ADDRESS @"http://api.fine3q.com" // 生产环境
  17. //#endif
  18. @interface FKServerUtil ()
  19. @property (nonatomic, strong) NSString *domain;
  20. @property (nonatomic, strong) NSArray *ipArray;
  21. @property (nonatomic, strong) NSString *apiServer;
  22. @property (nonatomic, strong) NSString *webServer;
  23. @end
  24. @implementation FKServerUtil
  25. + (FKServerUtil *)sharedInstance {
  26. static FKServerUtil *sharedFKServerUtilInstance = nil;
  27. static dispatch_once_t once_token;
  28. dispatch_once(&once_token, ^{
  29. sharedFKServerUtilInstance = [[self alloc] init];
  30. });
  31. return sharedFKServerUtilInstance;
  32. }
  33. - (void)loadServerConfig {
  34. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"FKServerConfig" ofType:@"xml"];
  35. NSError *error;
  36. NSString *xmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding
  37. error:&error];
  38. if (!error) {
  39. GDataXMLDocument *xmlDocument = [[GDataXMLDocument alloc] initWithXMLString:xmlString options:0
  40. error:&error];
  41. if (!error) {
  42. GDataXMLElement *rootElement = [xmlDocument rootElement];
  43. NSString *targetElementName = @"Release";
  44. #ifdef DEBUG
  45. targetElementName = @"Debug";
  46. #endif
  47. GDataXMLElement *serverElement = [rootElement elementsForName:targetElementName].firstObject;
  48. if (serverElement) {
  49. GDataXMLElement *domainElement = [serverElement elementsForName:@"domain"].firstObject;
  50. self.domain = [domainElement stringValue];
  51. GDataXMLElement *webElement = [serverElement elementsForName:@"Web"].firstObject;
  52. _webServer = [webElement stringValue];
  53. GDataXMLElement *hostsElement = [serverElement elementsForName:@"hosts"].firstObject;
  54. NSMutableArray *ipAddresses = [NSMutableArray array];
  55. for (GDataXMLElement *ipElement in [hostsElement elementsForName:@"ip"]) {
  56. [ipAddresses addObject:[ipElement stringValue]];
  57. }
  58. self.ipArray = ipAddresses;
  59. }
  60. if (self.domain) {
  61. _apiServer = self.domain;
  62. } else {
  63. _apiServer = self.ipArray.firstObject;
  64. }
  65. }
  66. }
  67. }
  68. - (NSString *)apiServer {
  69. return [NSString stringWithFormat:@"https://%@", (_apiServer ? _apiServer : @"api.fine3q.com")];
  70. }
  71. - (NSString *)webServer {
  72. return [NSString stringWithFormat:@"http://%@", (_webServer ? _webServer : @"m.fine3q.com")];
  73. }
  74. - (void)receiveErrorDomain {
  75. #ifndef DEBUG
  76. if (self.ipArray.firstObject) {
  77. _apiServer = self.ipArray.firstObject;
  78. }
  79. #endif
  80. }
  81. - (void)resetServerToDomain {
  82. #ifndef DEBUG
  83. if (self.domain) {
  84. _apiServer = self.domain;
  85. }
  86. #endif
  87. }
  88. - (NSString *)alipayNotifyURL {
  89. return [NSString stringWithFormat:@"%@/link-site/web/payment/mobile_paynotify.do", self.apiServer];
  90. }
  91. - (NSString *)aliGolbalPayNotifyURL {
  92. return [NSString stringWithFormat:@"%@/link-site/web/payment/global_paynotify.do", self.apiServer];
  93. }
  94. @end