ACNetwork.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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. #if TARGET_IPHONE_SIMULATOR//模拟器
  27. [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  28. #elif TARGET_OS_IPHONE//真机
  29. UIDevice * dev = [UIDevice currentDevice];
  30. NSUUID* uuid =dev.identifierForVendor;
  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. DebugLog(@"new_document result:%d",result);
  107. return jsobj;
  108. }
  109. +(NSDictionary*)save_document:(NSString*)file
  110. {
  111. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  112. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  113. // if(appDelegate.user!=nil)
  114. // [params setValue:appDelegate.user forKey:@"user"];
  115. //
  116. //
  117. // if(appDelegate.password!=nil)
  118. // [params setValue:appDelegate.password forKey:@"password"];
  119. params[@"_operate"]=@"deviceMain";
  120. if(![self IsNetworkAvailable])
  121. {
  122. DebugLog(@"NET ERR");
  123. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  124. // return nil;
  125. }
  126. NSData* json=[self get_json:URL_UPLOAD_PDF parameters:params file:file];
  127. //if(json==nil)
  128. if(json==nil)
  129. return nil;
  130. NSError *error=nil;
  131. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  132. int result = [[jsobj valueForKey:@"result"] intValue];
  133. DebugLog(@"new_document result:%d",result);
  134. return jsobj;
  135. }
  136. +(NSDictionary*)logout
  137. {
  138. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  139. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  140. if(appDelegate.user!=nil)
  141. [params setValue:appDelegate.user forKey:@"user"];
  142. if(appDelegate.password!=nil)
  143. [params setValue:appDelegate.password forKey:@"password"];
  144. params[@"_operate"]=@"logout_zip";
  145. if(![self IsNetworkAvailable])
  146. {
  147. DebugLog(@"NET ERR");
  148. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  149. // return nil;
  150. }
  151. NSData* json=[self get_json:URL_LOGOUT parameters:params file:nil];
  152. //if(json==nil)
  153. if(json==nil)
  154. return nil;
  155. NSError *error=nil;
  156. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  157. int result = [[jsobj valueForKey:@"result"] intValue];
  158. if (result==2)
  159. {
  160. [appDelegate Logout];
  161. }
  162. return jsobj;
  163. }
  164. +(int)Authorize : (NSString*) user password:(NSString*) password{
  165. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  166. // return RESULT_NET_ERROR;
  167. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  168. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  169. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  170. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  171. // if(appDelegate.duid !=nil)
  172. // [params setValue:appDelegate.duid forKey:@"udid"];
  173. // [params setValue:@"handset_login" forKey:@"action"];
  174. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  175. [params setValue:[AESCrypt AES128Encrypt:user key:@"usai2010"] forKey:@"user"];
  176. [params setValue:[AESCrypt AES128Encrypt:password key:@"usai2010"] forKey:@"password"];
  177. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  178. [params setValue:@"login" forKey:@"_operate"];
  179. //#ifdef TEST
  180. // [params setValue:@"true" forKey:@"is_debug"];
  181. //#else
  182. // [params setValue:@"false" forKey:@"is_debug"];
  183. //#endif
  184. NSData* json= nil;
  185. // if(appDelegate.offline_mode)
  186. // {
  187. // json= [OLDataProvider offline_login:params] ;
  188. //
  189. // }
  190. // else
  191. if(![self IsNetworkAvailable])
  192. return RESULT_NET_NOTAVAILABLE;
  193. json =[self get_json:URL_UPDATE_AUTH parameters:params file:nil];
  194. if(json==nil)
  195. return RESULT_NET_ERROR;
  196. int ret = [self parse_authinfo:json user:user password:password];
  197. DebugLog(@"parse_authinfo return %d ",ret);
  198. return ret;
  199. }
  200. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  201. {
  202. DebugLog(@"parse_authinfo");
  203. NSError *error=nil;
  204. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  205. if(jsobj)
  206. {
  207. UIApplication * app = [UIApplication sharedApplication];
  208. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  209. int result = [[jsobj valueForKey:@"result"] intValue];
  210. if (result<0)
  211. return result;
  212. if(result!=AP_USER_AUTH&& result!=9)
  213. {
  214. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  215. [appDelegate Logout];
  216. if(result==8)
  217. {
  218. return RESULT_LOGIN_DEVICE;
  219. }
  220. return RESULT_FALSE;
  221. }
  222. // NSDictionary* objheader = [jsobj objectForKey:@"header"];
  223. //
  224. // NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  225. // user=[objheader objectForKey:@"username"] ;
  226. // DebugLog(@"required_ver=%@ ",required_ver);
  227. // // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  228. // // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  229. // // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  230. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  231. //
  232. // // if([ibadge isEqual:[NSNull null]])
  233. // // strbadge=@"0";
  234. // // if(ibadge==nil)
  235. // // ibadge=@"0";
  236. // // if([strbadge isEqualToString:@"null"])
  237. // // strbadge=@"0";
  238. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  239. //
  240. // // BOOL bigger = [appDelegate.build compare:required_ver] ;
  241. // if([appDelegate.build intValue]<[required_ver intValue])
  242. // return RESULT_VER_LOW;
  243. // // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  244. // appDelegate.user = user;
  245. // appDelegate.password = password;
  246. //// appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  247. //// appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  248. // appDelegate.bLogin = true;
  249. [appDelegate Login:user pwd:password];
  250. //
  251. // if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  252. // {
  253. // appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  254. // appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  255. // // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  256. // // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  257. // // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  258. // }
  259. // NSString* mode =[jsobj valueForKey:@"mode"] ;
  260. // [appDelegate SetMode:mode];
  261. //
  262. //
  263. // appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  264. // appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  265. // appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  266. //
  267. // [appDelegate update_count_mark];
  268. //
  269. //
  270. //
  271. // appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  272. // appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  273. // appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  274. // appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  275. //
  276. // appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  277. // appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  278. // appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  279. // appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  280. // appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  281. // appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  282. //
  283. // appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  284. // appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  285. //
  286. // appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  287. //
  288. //
  289. //
  290. // appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  291. //
  292. // NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  293. //
  294. //
  295. //
  296. // appDelegate.OrderFilter= [[RAUtils string2dict:strfilter] mutableCopy];
  297. //
  298. //
  299. // [appDelegate set_main_button_panel];
  300. //
  301. // if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  302. //
  303. // // shop order status filter
  304. // NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  305. // [Singleton sharedInstance].shop_order_status_filter = [[RAUtils string2dict:shopOrderStatusFilterStr] mutableCopy];
  306. //
  307. // // specialInstruction
  308. // [Singleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  309. //
  310. // //-价格类型
  311. // [Singleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  312. //
  313. // // 权限
  314. // [Singleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  315. // [Singleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  316. //
  317. // [Singleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  318. //
  319. // [Singleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  320. //
  321. // [Singleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  322. // [[Singleton sharedInstance] resetGlobalLock];
  323. // [Singleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  324. // }
  325. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  326. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  327. // {
  328. // // no update on the server;
  329. // return RESULT_TRUE;
  330. // }
  331. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  332. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  333. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  334. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  335. // [defaults synchronize];
  336. //
  337. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  338. // NSArray* keys= [objfuncs allKeys];
  339. /*
  340. db.setTransactionSuccessful();
  341. db.endTransaction();
  342. */
  343. return RESULT_TRUE;
  344. }
  345. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  346. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  347. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  348. return RESULT_USERAUTH_ERROR;
  349. }
  350. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  351. {
  352. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  353. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  354. // if(appDelegate.user!=nil)
  355. // [params setValue:appDelegate.user forKey:@"user"];
  356. //
  357. // [params setValue:up_params forKey:@"upparam"];
  358. //
  359. // [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  360. //
  361. // [params setValue:result forKey:@"result"];
  362. // [params setValue:module forKey:@"interfac"];
  363. //
  364. // [params setValue:[RAUtils base64en:[RAUtils dict2string: [RAUtils device_info]]] forKey:@"device"];
  365. //
  366. //
  367. // // [params setValue:module forKey:@"module"];
  368. //
  369. // // [[UIDevice currentDevice] name];
  370. //
  371. // // if(appDelegate.offline_mode)
  372. // // {
  373. // // return [OLDataProvider offline_notimpl];
  374. // // }
  375. // if(![self IsNetworkAvailable])
  376. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  377. //
  378. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  379. // if(json==nil)
  380. // return nil;
  381. // NSError *error=nil;
  382. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  383. // return jsobj;
  384. NSMutableDictionary* jsobj = [@{@"result":@"2"} mutableCopy];
  385. return jsobj;
  386. }
  387. +(NSString *) prepareUploadFile:(NSString*) file json:(NSMutableDictionary*)json
  388. {
  389. NSString* serial= [[NSUUID UUID] UUIDString];
  390. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  391. NSString *cachefolder = [paths objectAtIndex:0];
  392. NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
  393. upfolder = [upfolder stringByAppendingPathComponent:serial];
  394. NSFileManager* fileManager = [NSFileManager defaultManager];
  395. BOOL bdir=YES;
  396. if(! [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
  397. {
  398. NSError *error = nil;
  399. bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
  400. if(!bsuccess)
  401. DebugLog(@"Create UPLOAD folder failed");
  402. }
  403. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  404. // ret[@"contact"]=[self prepareContact:serial];
  405. // ret[@"wishlist"]=[self prepareWishlist:serial];
  406. // ret[@"order"]=[self prepareOrder:serial soid:arr_order];
  407. // ret[@"portfolio"] = [self preparePortfolio:serial];
  408. // ret[@"view_portfolio"] = [self preparePDF:serial];
  409. NSString* str= [RAUtils dict2string:json];
  410. NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
  411. NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
  412. NSError *error=nil;
  413. [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  414. // NSArray* arr_files=[RAUtils allFilesAtPath:upfolder];
  415. ZipArchive* zip = [[ZipArchive alloc] init];
  416. BOOL result = [zip CreateZipFile2:zippath Password:nil];
  417. result = [zip addFileToZip:file newname:[file lastPathComponent]];
  418. result = [zip addFileToZip:jsonpath newname:[jsonpath lastPathComponent]];
  419. if( ![zip CloseZipFile2] )
  420. {
  421. zippath = @"";
  422. }
  423. return zippath;
  424. }
  425. +(NSDictionary*)request_DocList:(NSMutableDictionary*) params
  426. {
  427. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  428. // if(appDelegate.user!=nil)
  429. // [params setValue:appDelegate.user forKey:@"user"];
  430. //
  431. //
  432. // if(appDelegate.password!=nil)
  433. // [params setValue:appDelegate.password forKey:@"password"];
  434. params[@"_operate"]=@"listIpad";
  435. if(![self IsNetworkAvailable])
  436. {
  437. DebugLog(@"NET ERR");
  438. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  439. // return nil;
  440. }
  441. NSData* json=[self get_json:URL_REQUEST_DOC parameters:params file:nil];
  442. //if(json==nil)
  443. if(json==nil)
  444. return nil;
  445. NSError *error=nil;
  446. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  447. return jsobj;
  448. }
  449. @end