OnlineDataProvider.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. //
  2. // OnlineDataProvider.m
  3. // RA TradeFiling
  4. //
  5. // Created by Rui Zhang on 11/19/20.
  6. //
  7. #import "OnlineDataProvider.h"
  8. #import "config.h"
  9. #import "RAUtils.h"
  10. @implementation OnlineDataProvider
  11. + (void)request_login : (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  12. {
  13. // long ver = 0;
  14. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  15. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  16. // ver = appDelegate.authVer;
  17. // if(appDelegate.duid !=nil)
  18. // [params setValue:appDelegate.duid forKey:@"udid"];
  19. [params setValue:@"login" forKey:@"action"];
  20. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  21. [params setValue:user forKey:@"user"];
  22. [params setValue:password forKey:@"password"];
  23. // [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  24. #ifdef TEST
  25. [params setValue:@"true" forKey:@"is_debug"];
  26. #else
  27. [params setValue:@"false" forKey:@"is_debug"];
  28. #endif
  29. [self request_interface:URL_LOGIN parameters:params err_record_url:nil completionHandler:result retry:0];
  30. }
  31. + (void)request_signup : (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  32. {
  33. // long ver = 0;
  34. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  35. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  36. // ver = appDelegate.authVer;
  37. // if(appDelegate.duid !=nil)
  38. // [params setValue:appDelegate.duid forKey:@"udid"];
  39. [params setValue:@"signup" forKey:@"action"];
  40. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  41. [params setValue:user forKey:@"user"];
  42. [params setValue:password forKey:@"password"];
  43. // [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  44. //#ifdef TEST
  45. // [params setValue:@"true" forKey:@"is_debug"];
  46. //#else
  47. // [params setValue:@"false" forKey:@"is_debug"];
  48. //#endif
  49. [self request_interface:URL_SIGNUP parameters:params err_record_url:nil completionHandler:result retry:0];
  50. }
  51. + (void)request_changepassword:(NSString*) newpassword completionHandler:(resultHandler)result
  52. {
  53. NSMutableDictionary* params = [NSMutableDictionary new];
  54. params[@"newpassword"]=newpassword;
  55. params[@"action"]=@"changepassword";
  56. // params = [self prepare_addtional_params:params];
  57. [self request_interface:URL_CHANGE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  58. }
  59. + (void)request_logout : (resultHandler)result
  60. {
  61. NSMutableDictionary* params = [NSMutableDictionary new];
  62. params[@"action"]=@"logout";
  63. // params = [self prepare_addtional_params:params];
  64. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:result retry:0];
  65. }
  66. + (void)request_home :(nullable NSMutableDictionary *)params completionHandler:(resultHandler)result
  67. {
  68. // params = [self prepare_addtional_params:params];
  69. if(params==nil)
  70. params = [NSMutableDictionary new];
  71. params[@"action"]=@"dashboardMobile";
  72. [self request_interface:URL_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  73. }
  74. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  75. {
  76. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  77. //
  78. // if(appDelegate.offline_mode)
  79. // {
  80. // params[@"offline_Command"]=url;
  81. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  82. // }
  83. //
  84. // if(![self IsNetworkAvailable])
  85. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  86. //
  87. // NSData* json=[self get_json:url parameters:params];
  88. // if(json!=nil)
  89. // {
  90. // NSError *error=nil;
  91. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  92. // if([[jsobj valueForKey:@"result"]intValue]==2)
  93. // [appDelegate SetSo:nil];
  94. //
  95. //
  96. // return jsobj;
  97. // }
  98. // else
  99. // return nil;
  100. }
  101. +(void)request_save_editor:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  102. {
  103. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  104. [self request_interface:URL_SAVE_EDITOR parameters:params err_record_url:nil completionHandler:result retry:0];
  105. }
  106. + (void)request_result:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  107. {
  108. params[@"action"]=@"result";
  109. [self request_interface:URL_SEARCH_RESULT parameters:params err_record_url:nil completionHandler:result retry:0];
  110. // return [self mockResult:params];
  111. //
  112. // params[@"action"]=@"handset_search";
  113. //
  114. // [self request_interface:URL_SEARCH_RESULT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resultjson) {
  115. // NSMutableDictionary *resultDic = resultjson;
  116. //
  117. // // detail data in local database
  118. // NSString *module_name = [params objectForKey:@"module_name"];
  119. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  120. // NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
  121. // [resultDic setValue:actions forKey:@"actions"];
  122. // result(resultDic);
  123. // } retry:0];
  124. //
  125. }
  126. + (void)request_cadedate:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  127. {
  128. params[@"action"]=@"cadedate";
  129. [self request_interface:URL_CADEDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  130. // return [self mockResult:params];
  131. //
  132. // params[@"action"]=@"handset_search";
  133. //
  134. // [self request_interface:URL_SEARCH_RESULT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resultjson) {
  135. // NSMutableDictionary *resultDic = resultjson;
  136. //
  137. // // detail data in local database
  138. // NSString *module_name = [params objectForKey:@"module_name"];
  139. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  140. // NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
  141. // [resultDic setValue:actions forKey:@"actions"];
  142. // result(resultDic);
  143. // } retry:0];
  144. //
  145. }
  146. +(void) request_editor: (NSMutableDictionary *) params completionHandler:(resultHandler)result
  147. {
  148. [self request_interface:URL_REQUEST_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  149. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  150. // [params setValue:@"handset_search" forKey:@"action"];
  151. //// [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  152. //
  153. //
  154. // [self request_interface:URL_REQUEST_RECORDS parameters:params err_record_url:nil completionHandler:result retry:0];
  155. // return;
  156. }
  157. +(void) request_detail: (NSMutableDictionary *) params completionHandler:(resultHandler)result
  158. {
  159. [self request_interface:URL_REQUEST_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  160. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  161. // [params setValue:@"handset_search" forKey:@"action"];
  162. //// [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  163. //
  164. //
  165. // [self request_interface:URL_REQUEST_RECORDS parameters:params err_record_url:nil completionHandler:result retry:0];
  166. // return;
  167. }
  168. + (void)request_retrievepassword: (NSString*)user email:(NSString*)email completionHandler:(resultHandler)result
  169. {
  170. NSMutableDictionary* params = [NSMutableDictionary new];
  171. params[@"action"]=@"retrievePassword";
  172. params[@"user"]=user;
  173. params[@"email"]=email;
  174. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  175. }
  176. + (void)request_fastdownload:(nullable NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  177. {
  178. [self request_file_fast:url parameters:params completionHandler:result];
  179. }
  180. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  181. {
  182. if (params == nil) {
  183. params = [NSMutableDictionary dictionary];
  184. }
  185. // NSString *currentLanguageRegion = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] firstObject];
  186. NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
  187. [params setValue:preferredLanguage forKey:@"language"];
  188. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  189. // if(appDelegate.user!=nil && params[@"user"] == nil)
  190. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"Usai2010"] forKey:@"user"];
  191. // if(appDelegate.password!=nil&& params[@"pwd"] == nil)
  192. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"Usai2010"] forKey:@"pwd"];
  193. if(RASingleton.sharedInstance.user!=nil && params[@"user"] == nil)
  194. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  195. if(RASingleton.sharedInstance.password!=nil&& params[@"password"] == nil)
  196. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  197. // [params setValue:appDelegate.build forKey:@"app_ver"];
  198. //
  199. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  200. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  201. [params setValue:short_version forKey:@"app_ver"];
  202. #if TARGET_IPHONE_SIMULATOR//模拟器
  203. [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  204. #elif TARGET_OS_IPHONE//真机
  205. UIDevice * dev = [UIDevice currentDevice];
  206. NSUUID* uuid =dev.identifierForVendor;
  207. [params setValue:uuid.UUIDString forKey:@"deviceid"];
  208. #endif
  209. if(RASingleton.sharedInstance.companylist.count>0 && [params[@"company"] stringValue].length==0)
  210. {
  211. params[@"company"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
  212. }
  213. params[@"os"]=@"iOS";
  214. return params;
  215. }
  216. //+ (void)request_savepanel: (NSString*)panel_setting completionHandler:(resultHandler)result
  217. //{
  218. //// NSMutableDictionary* params = [NSMutableDictionary new];
  219. //// params[@"function_panel"]=panel_setting;
  220. ////// params = [self prepare_addtional_params:params];
  221. //// [self request_interface:URL_SAVE_PANEL parameters:params err_record_url:nil completionHandler:result retry:0];
  222. //}
  223. //重新实现request_interface 接口,对部分返回结果预处理。
  224. +(void)request_interface : (NSString*) url parameters:(NSMutableDictionary *) params err_record_url:(NSString* )recorder_url completionHandler:(resultHandler)result retry:(int) retry
  225. {
  226. [super request_interface:url parameters:params err_record_url:recorder_url completionHandler:^(NSMutableDictionary *resultjson) {
  227. if([resultjson[@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  228. {
  229. // [RAUtils message_alert:@"User login on other device." title:@"Warrning" controller:nil];
  230. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:resultjson[@"err_msg"]];
  231. // UIViewController* vc = [RAUtils getCurrentVC];
  232. // [RAUtils message_alert:@"User login on other device." title:@"Warrning" controller:vc action_handler:^(UIAlertAction * _Nonnull action) {
  233. // [vc.navigationController popToRootViewControllerAnimated:true];
  234. // [RASingleton.sharedInstance logout];
  235. // [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGOUT object:nil];
  236. // } completion:^{
  237. //
  238. //
  239. // }];
  240. }
  241. // NSMutableDictionary *resultDic = resultjson;
  242. //
  243. // // detail data in local database
  244. // NSString *module_name = [params objectForKey:@"module_name"];
  245. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  246. // NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
  247. // [resultDic setValue:actions forKey:@"actions"];
  248. result(resultjson);
  249. }retry:retry];
  250. }
  251. @end