ACNetwork.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. //
  2. // ACNetwork.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/26/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ACNetwork.h"
  9. #import "AppDelegate.h"
  10. #import "RAUtils.h"
  11. #import "ZipArchive.h"
  12. #import "config.h"
  13. #import "AESCrypt.h"
  14. @implementation ACNetwork
  15. +(NSMutableDictionary*) prepare_addtional_params:(NSMutableDictionary* ) params
  16. {
  17. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  18. if(appDelegate.user!=nil)
  19. [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai2010"] forKey:@"user"];
  20. if(appDelegate.password!=nil)
  21. [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai2010"] forKey:@"password"];
  22. [params setValue:appDelegate.build forKey:@"app_ver"];
  23. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  24. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  25. [params setValue:short_version forKey:@"app_short_ver"];
  26. UIDevice * dev = [UIDevice currentDevice];
  27. NSUUID* uuid =dev.identifierForVendor;
  28. #if TARGET_IPHONE_SIMULATOR//模拟器
  29. [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  30. #elif TARGET_OS_IPHONE//真机
  31. [params setValue:uuid.UUIDString forKey:@"deviceid"];
  32. #endif
  33. return params;
  34. }
  35. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  36. {
  37. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  38. // DebugLog(e);
  39. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  40. params = [self prepare_addtional_params:params];
  41. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  42. int result=[[jsobj valueForKey:@"result"] intValue];
  43. // UIApplication * app = [UIApplication sharedApplication];
  44. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  45. switch (result) {
  46. case 0:
  47. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  48. break;
  49. case 1:
  50. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  51. break;
  52. case 2:
  53. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  54. break;
  55. case 8:
  56. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  57. break;
  58. case 9:
  59. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  60. break;
  61. case 99:
  62. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  63. break;
  64. default:
  65. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  66. break;
  67. }
  68. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  69. // {
  70. // [jsobj setValue:@"9" forKey:@"result"];
  71. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  72. // }
  73. return jsobj;
  74. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  75. NSString* base64str = jsobj[@"str"];
  76. NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  77. jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  78. return jsobj;
  79. }];
  80. /*
  81. */
  82. return nil;
  83. }
  84. +(NSDictionary*)new_document
  85. {
  86. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  87. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  88. if(appDelegate.user!=nil)
  89. [params setValue:appDelegate.user forKey:@"user"];
  90. if(appDelegate.password!=nil)
  91. [params setValue:appDelegate.password forKey:@"password"];
  92. params[@"_operate"]=@"doc_id";
  93. if(![self IsNetworkAvailable])
  94. {
  95. DebugLog(@"NET ERR");
  96. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  97. // return nil;
  98. }
  99. NSData* json=[self get_json:URL_NEW_DOCUMENT parameters:params file:nil];
  100. //if(json==nil)
  101. if(json==nil)
  102. return nil;
  103. NSError *error=nil;
  104. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  105. int result = [[jsobj valueForKey:@"result"] intValue];
  106. return jsobj;
  107. }
  108. +(NSDictionary*)save_document:(NSString*)file
  109. {
  110. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  111. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  112. // if(appDelegate.user!=nil)
  113. // [params setValue:appDelegate.user forKey:@"user"];
  114. //
  115. //
  116. // if(appDelegate.password!=nil)
  117. // [params setValue:appDelegate.password forKey:@"password"];
  118. params[@"_operate"]=@"deviceMain";
  119. if(![self IsNetworkAvailable])
  120. {
  121. DebugLog(@"NET ERR");
  122. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  123. // return nil;
  124. }
  125. NSData* json=[self get_json:URL_UPLOAD_PDF parameters:params file:file];
  126. //if(json==nil)
  127. if(json==nil)
  128. return nil;
  129. NSError *error=nil;
  130. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  131. int result = [[jsobj valueForKey:@"result"] intValue];
  132. return jsobj;
  133. }
  134. +(NSDictionary*)logout
  135. {
  136. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  137. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  138. if(appDelegate.user!=nil)
  139. [params setValue:appDelegate.user forKey:@"user"];
  140. if(appDelegate.password!=nil)
  141. [params setValue:appDelegate.password forKey:@"password"];
  142. params[@"_operate"]=@"logout_zip";
  143. if(![self IsNetworkAvailable])
  144. {
  145. DebugLog(@"NET ERR");
  146. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  147. // return nil;
  148. }
  149. NSData* json=[self get_json:URL_LOGOUT parameters:params file:nil];
  150. //if(json==nil)
  151. if(json==nil)
  152. return nil;
  153. NSError *error=nil;
  154. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  155. int result = [[jsobj valueForKey:@"result"] intValue];
  156. if (result==2)
  157. {
  158. [appDelegate Logout];
  159. }
  160. return jsobj;
  161. }
  162. +(int)Authorize : (NSString*) user password:(NSString*) password{
  163. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  164. // return RESULT_NET_ERROR;
  165. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  166. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  167. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  168. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  169. // if(appDelegate.duid !=nil)
  170. // [params setValue:appDelegate.duid forKey:@"udid"];
  171. // [params setValue:@"handset_login" forKey:@"action"];
  172. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  173. [params setValue:[AESCrypt AES128Encrypt:user key:@"usai2010"] forKey:@"user"];
  174. [params setValue:[AESCrypt AES128Encrypt:password key:@"usai2010"] forKey:@"password"];
  175. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  176. [params setValue:@"login" forKey:@"_operate"];
  177. //#ifdef TEST
  178. // [params setValue:@"true" forKey:@"is_debug"];
  179. //#else
  180. // [params setValue:@"false" forKey:@"is_debug"];
  181. //#endif
  182. NSData* json= nil;
  183. // if(appDelegate.offline_mode)
  184. // {
  185. // json= [OLDataProvider offline_login:params] ;
  186. //
  187. // }
  188. // else
  189. if(![self IsNetworkAvailable])
  190. return RESULT_NET_NOTAVAILABLE;
  191. json =[self get_json:URL_UPDATE_AUTH parameters:params file:nil];
  192. if(json==nil)
  193. return RESULT_NET_ERROR;
  194. int ret = [self parse_authinfo:json user:user password:password];
  195. DebugLog(@"parse_authinfo return %d ",ret);
  196. return ret;
  197. }
  198. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  199. {
  200. DebugLog(@"parse_authinfo");
  201. NSError *error=nil;
  202. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  203. if(jsobj)
  204. {
  205. UIApplication * app = [UIApplication sharedApplication];
  206. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  207. int result = [[jsobj valueForKey:@"result"] intValue];
  208. if (result<0)
  209. return result;
  210. if(result!=AP_USER_AUTH&& result!=9)
  211. {
  212. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  213. [appDelegate Logout];
  214. if(result==8)
  215. {
  216. return RESULT_LOGIN_DEVICE;
  217. }
  218. return RESULT_FALSE;
  219. }
  220. // NSDictionary* objheader = [jsobj objectForKey:@"header"];
  221. //
  222. // NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  223. // user=[objheader objectForKey:@"username"] ;
  224. // DebugLog(@"required_ver=%@ ",required_ver);
  225. // // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  226. // // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  227. // // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  228. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  229. //
  230. // // if([ibadge isEqual:[NSNull null]])
  231. // // strbadge=@"0";
  232. // // if(ibadge==nil)
  233. // // ibadge=@"0";
  234. // // if([strbadge isEqualToString:@"null"])
  235. // // strbadge=@"0";
  236. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  237. //
  238. // // BOOL bigger = [appDelegate.build compare:required_ver] ;
  239. // if([appDelegate.build intValue]<[required_ver intValue])
  240. // return RESULT_VER_LOW;
  241. // // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  242. // appDelegate.user = user;
  243. // appDelegate.password = password;
  244. //// appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  245. //// appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  246. // appDelegate.bLogin = true;
  247. [appDelegate Login:user pwd:password];
  248. //
  249. // if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  250. // {
  251. // appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  252. // appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  253. // // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  254. // // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  255. // // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  256. // }
  257. // NSString* mode =[jsobj valueForKey:@"mode"] ;
  258. // [appDelegate SetMode:mode];
  259. //
  260. //
  261. // appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  262. // appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  263. // appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  264. //
  265. // [appDelegate update_count_mark];
  266. //
  267. //
  268. //
  269. // appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  270. // appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  271. // appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  272. // appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  273. //
  274. // appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  275. // appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  276. // appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  277. // appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  278. // appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  279. // appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  280. //
  281. // appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  282. // appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  283. //
  284. // appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  285. //
  286. //
  287. //
  288. // appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  289. //
  290. // NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  291. //
  292. //
  293. //
  294. // appDelegate.OrderFilter= [[RAUtils string2dict:strfilter] mutableCopy];
  295. //
  296. //
  297. // [appDelegate set_main_button_panel];
  298. //
  299. // if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  300. //
  301. // // shop order status filter
  302. // NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  303. // [Singleton sharedInstance].shop_order_status_filter = [[RAUtils string2dict:shopOrderStatusFilterStr] mutableCopy];
  304. //
  305. // // specialInstruction
  306. // [Singleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  307. //
  308. // //-价格类型
  309. // [Singleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  310. //
  311. // // 权限
  312. // [Singleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  313. // [Singleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  314. //
  315. // [Singleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  316. //
  317. // [Singleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  318. //
  319. // [Singleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  320. // [[Singleton sharedInstance] resetGlobalLock];
  321. // [Singleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  322. // }
  323. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  324. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  325. // {
  326. // // no update on the server;
  327. // return RESULT_TRUE;
  328. // }
  329. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  330. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  331. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  332. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  333. // [defaults synchronize];
  334. //
  335. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  336. // NSArray* keys= [objfuncs allKeys];
  337. /*
  338. db.setTransactionSuccessful();
  339. db.endTransaction();
  340. */
  341. return RESULT_TRUE;
  342. }
  343. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  344. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  345. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  346. return RESULT_USERAUTH_ERROR;
  347. }
  348. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  349. {
  350. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  351. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  352. // if(appDelegate.user!=nil)
  353. // [params setValue:appDelegate.user forKey:@"user"];
  354. //
  355. // [params setValue:up_params forKey:@"upparam"];
  356. //
  357. // [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  358. //
  359. // [params setValue:result forKey:@"result"];
  360. // [params setValue:module forKey:@"interfac"];
  361. //
  362. // [params setValue:[RAUtils base64en:[RAUtils dict2string: [RAUtils device_info]]] forKey:@"device"];
  363. //
  364. //
  365. // // [params setValue:module forKey:@"module"];
  366. //
  367. // // [[UIDevice currentDevice] name];
  368. //
  369. // // if(appDelegate.offline_mode)
  370. // // {
  371. // // return [OLDataProvider offline_notimpl];
  372. // // }
  373. // if(![self IsNetworkAvailable])
  374. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  375. //
  376. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  377. // if(json==nil)
  378. // return nil;
  379. // NSError *error=nil;
  380. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  381. // return jsobj;
  382. NSMutableDictionary* jsobj = [@{@"result":@"2"} mutableCopy];
  383. return jsobj;
  384. }
  385. +(NSString *) prepareUploadFile:(NSString*) file json:(NSMutableDictionary*)json
  386. {
  387. NSString* serial= [[NSUUID UUID] UUIDString];
  388. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  389. NSString *cachefolder = [paths objectAtIndex:0];
  390. NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
  391. upfolder = [upfolder stringByAppendingPathComponent:serial];
  392. NSFileManager* fileManager = [NSFileManager defaultManager];
  393. BOOL bdir=YES;
  394. if(! [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
  395. {
  396. NSError *error = nil;
  397. bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
  398. if(!bsuccess)
  399. DebugLog(@"Create UPLOAD folder failed");
  400. }
  401. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  402. // ret[@"contact"]=[self prepareContact:serial];
  403. // ret[@"wishlist"]=[self prepareWishlist:serial];
  404. // ret[@"order"]=[self prepareOrder:serial soid:arr_order];
  405. // ret[@"portfolio"] = [self preparePortfolio:serial];
  406. // ret[@"view_portfolio"] = [self preparePDF:serial];
  407. NSString* str= [RAUtils dict2string:json];
  408. NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
  409. NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
  410. NSError *error=nil;
  411. [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  412. // NSArray* arr_files=[RAUtils allFilesAtPath:upfolder];
  413. ZipArchive* zip = [[ZipArchive alloc] init];
  414. BOOL result = [zip CreateZipFile2:zippath Password:nil];
  415. result = [zip addFileToZip:file newname:[file lastPathComponent]];
  416. result = [zip addFileToZip:jsonpath newname:[jsonpath lastPathComponent]];
  417. if( ![zip CloseZipFile2] )
  418. {
  419. zippath = @"";
  420. }
  421. return zippath;
  422. }
  423. +(NSDictionary*)request_DocList:(NSMutableDictionary*) params
  424. {
  425. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  426. // if(appDelegate.user!=nil)
  427. // [params setValue:appDelegate.user forKey:@"user"];
  428. //
  429. //
  430. // if(appDelegate.password!=nil)
  431. // [params setValue:appDelegate.password forKey:@"password"];
  432. params[@"_operate"]=@"listIpad";
  433. if(![self IsNetworkAvailable])
  434. {
  435. DebugLog(@"NET ERR");
  436. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  437. // return nil;
  438. }
  439. NSData* json=[self get_json:URL_REQUEST_DOC parameters:params file:nil];
  440. //if(json==nil)
  441. if(json==nil)
  442. return nil;
  443. NSError *error=nil;
  444. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  445. return jsobj;
  446. }
  447. @end