| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983 |
- //
- // ACNetwork.m
- // AntsContract
- //
- // Created by Ray on 12/26/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "RANetwork.h"
- #import "AppDelegate.h"
- #import "RAUtils.h"
- #import "ZipArchive.h"
- #import "config.h"
- #import "AESCrypt.h"
- //#import <AdSupport/ASIdentifierManager.h>
- @implementation RANetwork
- //+(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
- +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
- {
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:[AESCrypt AES128Encrypt:RASingleton.sharedInstance.user key:@"usai2010"] forKey:@"user"];
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:[AESCrypt AES128Encrypt:RASingleton.sharedInstance.password key:@"usai2010"] forKey:@"password"];
-
-
- [params setValue:[RAUtils device_info][@"build"] forKey:@"app_ver"];
-
- NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
- NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
- [params setValue:short_version forKey:@"app_short_ver"];
-
-
- #if TARGET_IPHONE_SIMULATOR//模拟器
- [params setValue:@"simulator_uuid" forKey:@"deviceid"];
- #elif TARGET_OS_IPHONE//真机
- UIDevice * dev = [UIDevice currentDevice];
- NSUUID* uuid =dev.identifierForVendor;
- [params setValue:uuid.UUIDString forKey:@"deviceid"];
- #endif
-
- return params;
- }
- +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
- {
-
-
-
-
- // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
- // DebugLog(e);
- // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
- params = [self prepare_additional_params:params];
-
- return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
- int result=[[jsobj valueForKey:@"result"] intValue];
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- switch (result) {
- case 0:
- [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
- break;
- case 1:
- [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
- break;
- case 2:
- [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
- break;
- case 8:
- [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
- break;
- case 9:
- [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
- break;
- case 99:
- [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
- break;
- default:
- [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
- break;
- }
-
-
- // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
- // {
- // [jsobj setValue:@"9" forKey:@"result"];
- // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
- // }
- return jsobj;
- } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
-
- NSString* base64str = jsobj[@"str"];
- NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
- jsobj=[[RAConvertor string2dict:decryptstr] mutableCopy];
- return jsobj;
- }];
-
-
- /*
-
- */
- return nil;
- }
- //+(NSDictionary*)new_document
- //{
- //
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(RASingleton.sharedInstance.user!=nil)
- // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- //
- //
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- // params[@"_operate"]=@"doc_id";
- //
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- // // return nil;
- // }
- // NSData* json=[self get_json:URL_NEW_DOCUMENT parameters:params file:nil];
- // //if(json==nil)
- //
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // int result = [[jsobj valueForKey:@"result"] intValue];
- // DebugLog(@"new_document result:%d",result);
- //
- // return jsobj;
- //}
- //+(NSDictionary*)upload_file:(NSString*)file params:(NSMutableDictionary*) params
- //{
- //
- //
- //
- // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // // if(appDelegate.user!=nil)
- // // [params setValue:appDelegate.user forKey:@"user"];
- // //
- // //
- // // if(appDelegate.password!=nil)
- // // [params setValue:appDelegate.password forKey:@"password"];
- // params[@"_operate"]=@"uploadFileIpad";
- //
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- // // return nil;
- // }
- // NSData* json=[self get_json:URL_UPLOAD_PDF parameters:params file:file];
- // //if(json==nil)
- //
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // int result = [[jsobj valueForKey:@"result"] intValue];
- //
- // DebugLog(@"upload_file result:%d",result);
- // return jsobj;
- //}
- //+(NSDictionary*)save_document:(NSString*)file isnew:(bool)isNewDocument
- //{
- //
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //// if(appDelegate.user!=nil)
- //// [params setValue:appDelegate.user forKey:@"user"];
- ////
- ////
- //// if(appDelegate.password!=nil)
- //// [params setValue:appDelegate.password forKey:@"password"];
- // params[@"_operate"]=@"deviceMain";
- // params[@"modify_document"]=[NSNumber numberWithBool:!isNewDocument];
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- // // return nil;
- // }
- // NSData* json=[self get_json:URL_UPLOAD_PDF parameters:params file:file];
- // //if(json==nil)
- //
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // int result = [[jsobj valueForKey:@"result"] intValue];
- //
- // DebugLog(@"new_document result:%d",result);
- // return jsobj;
- //}
- //+(NSDictionary*)logout
- //{
- //
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- ////
- // if(RASingleton.sharedInstance.user!=nil)
- // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- //
- //
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- // params[@"_operate"]=@"logout_zip";
- //
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- // // return nil;
- // }
- // NSData* json=[self get_json:URL_LOGOUT parameters:params file:nil];
- // //if(json==nil)
- //
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // int result = [[jsobj valueForKey:@"result"] intValue];
- //
- // if (result==2)
- // {
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // [appDelegate Logout];
- // });
- //
- // }
- // return jsobj;
- //}
- //+(int)Authorize : (NSString*) user password:(NSString*) password{
- //
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
- //
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- //
- //
- // [params setValue:[AESCrypt AES128Encrypt:user key:@"usai2010"] forKey:@"user"];
- // [params setValue:[AESCrypt AES128Encrypt:password key:@"usai2010"] forKey:@"password"];
- // [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
- // [params setValue:@"login" forKey:@"_operate"];
- //
- // NSData* json= nil;
- //
- // if(![self IsNetworkAvailable])
- // return RESULT_NET_NOTAVAILABLE;
- // json =[self get_json:URL_UPDATE_AUTH parameters:params file:nil];
- //
- //
- //
- // if(json==nil)
- // return RESULT_NET_ERROR;
- //
- //
- // int ret = [self parse_authinfo:json user:user password:password];
- // DebugLog(@"parse_authinfo return %d ",ret);
- //
- //
- // return ret;
- //
- //
- //}
- //+(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
- //{
- // DebugLog(@"parse_authinfo");
- // NSError *error=nil;
- //
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // if(jsobj)
- // {
- //
- //
- // int result = [[jsobj valueForKey:@"result"] intValue];
- //
- // if (result<0)
- // return result;
- // if(result!=AP_USER_AUTH&& result!=9)
- // {
- //
- //
- // DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- //// [appDelegate Logout];
- // if(result==8)
- // {
- // return RESULT_LOGIN_DEVICE;
- // }
- // return RESULT_FALSE;
- //
- // }
- //
- // NSString* offPrefix = jsobj[@"randcode"];
- // bool skip_verify = [jsobj[@"skip_save_verify"] boolValue];
- //
- //
- //
- // NSString* agentName = jsobj[@"agent_name"];
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- //
- //
- //// NSString* skip_save_verify = jsobj[@"skip_save_verify"];
- //
- //
- //
- // NSMutableDictionary* user_info = [NSMutableDictionary new];
- // user_info[@"prefix"]=offPrefix;
- // user_info[@"agent_name"]= agentName;
- //
- //
- //
- // [defaults setObject:user_info forKey:user];
- //
- //
- // [defaults synchronize];
- //
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // [appDelegate Login:user pwd:password skip_verify:skip_verify offPrefix:offPrefix agentName:agentName];
- //
- // });
- //
- //
- //
- // return RESULT_TRUE;
- //
- // }
- // // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
- // // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
- // // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
- //
- //
- //
- // return RESULT_USERAUTH_ERROR;
- //}
- +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
- {
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(appDelegate.user!=nil)
- // [params setValue:appDelegate.user forKey:@"user"];
- //
- // [params setValue:up_params forKey:@"upparam"];
- //
- // [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
- //
- // [params setValue:result forKey:@"result"];
- // [params setValue:module forKey:@"interfac"];
- //
- // [params setValue:[RAUtils base64en:[RAUtils dict2string: [RAUtils device_info]]] forKey:@"device"];
- //
- //
- // // [params setValue:module forKey:@"module"];
- //
- // // [[UIDevice currentDevice] name];
- //
- // // if(appDelegate.offline_mode)
- // // {
- // // return [OLDataProvider offline_notimpl];
- // // }
- // if(![self IsNetworkAvailable])
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- //
- // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // return jsobj;
- NSMutableDictionary* jsobj = [@{@"result":@"2"} mutableCopy];
- return jsobj;
- }
- +(NSString *) packfiles2zip:(NSMutableArray*) arr_file
- {
-
- if(arr_file.count==0)
- {
- DebugLog(@"packfiles2zip: source list is empty.");
- return @"";
- }
- NSString* serial= [[NSUUID UUID] UUIDString];
-
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
-
- NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
- upfolder = [upfolder stringByAppendingPathComponent:serial];
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=YES;
- if(! [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- {
- DebugLog(@"Create UPLOAD folder failed");
- return @"";
- }
-
- }
-
-
-
- NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
-
-
- ZipArchive* zip = [[ZipArchive alloc] init];
-
-
- BOOL result = [zip CreateZipFile2:zippath Password:nil];
-
- for(int i=0;i<arr_file.count;i++)
- {
- NSString* file = arr_file[i];
- result = [zip addFileToZip:file newname:[file lastPathComponent]];
- }
-
-
-
-
- if( ![zip CloseZipFile2] )
- {
- zippath = @"";
- }
-
-
-
-
-
- return zippath;
- }
- +(NSString *) prepareUploadFile:(NSString*) file json:(NSMutableDictionary*)json
- {
- NSString* serial= [[NSUUID UUID] UUIDString];
-
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
-
- NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
- upfolder = [upfolder stringByAppendingPathComponent:serial];
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=YES;
- if(! [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- DebugLog(@"Create UPLOAD folder failed");
-
- }
-
- // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- // ret[@"contact"]=[self prepareContact:serial];
- // ret[@"wishlist"]=[self prepareWishlist:serial];
- // ret[@"order"]=[self prepareOrder:serial soid:arr_order];
- // ret[@"portfolio"] = [self preparePortfolio:serial];
- // ret[@"view_portfolio"] = [self preparePDF:serial];
-
- NSString* str= [RAConvertor dict2string:json];
-
-
-
-
-
- NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
-
- NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
-
-
- NSError *error=nil;
-
- [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
-
- // NSArray* arr_files=[RAUtils allFilesAtPath:upfolder];
-
- ZipArchive* zip = [[ZipArchive alloc] init];
-
-
- BOOL result = [zip CreateZipFile2:zippath Password:nil];
-
- result = [zip addFileToZip:file newname:[file lastPathComponent]];
- result = [zip addFileToZip:jsonpath newname:[jsonpath lastPathComponent]];
-
- // for(int l=0;l<[json[@"count"] intValue];l++)
- // {
- //
- // NSMutableDictionary * page_json = json[[NSString stringWithFormat:@"page_%d",l] ];
- //
- // for(int p=0;p<[page_json[@"count"] intValue];p++)
- // {
- // NSMutableDictionary * control_json = page_json[[NSString stringWithFormat:@"control_%d",p] ];
- // if([control_json[@"type"] isEqualToString:@"Signature"] )
- // {
- // NSString* signature_path = control_json[@"value"];
- // if(signature_path.length>0)
- // result = [zip addFileToZip:signature_path newname:[signature_path lastPathComponent]];
- // }
- // }
- // }
-
- if( ![zip CloseZipFile2] )
- {
- zippath = @"";
- }
-
-
-
-
- return zippath;
- }
- //
- //+(NSDictionary*)request_DocList:(NSMutableDictionary*) params
- //{
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //// if(appDelegate.user!=nil)
- //// [params setValue:appDelegate.user forKey:@"user"];
- ////
- ////
- //// if(appDelegate.password!=nil)
- //// [params setValue:appDelegate.password forKey:@"password"];
- // params[@"_operate"]=@"listIpad";
- //
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- // // return nil;
- // }
- // NSData* json=[self get_json:URL_REQUEST_DOC parameters:params file:nil];
- // //if(json==nil)
- //
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- //
- // return jsobj;
- //}
- //+(NSDictionary *) updateNotes:(NSString*) doc_number notes:(NSString*)notes
- //{
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(RASingleton.sharedInstance.user!=nil)
- // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- //
- //
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- //
- // params[@"doc_number"]=doc_number;
- // params[@"notes"]=notes;
- //
- // params[@"_operate"]=@"updateNotes";
- //
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- // // return nil;
- // }
- // NSData* json=[self get_json:URL_UPDATE_NOTES parameters:params file:nil];
- // //if(json==nil)
- //
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // int result = [[jsobj valueForKey:@"result"] intValue];
- // DebugLog(@"new_document result:%d",result);
- //
- // return jsobj;
- //
- //}
- +(NSString *) getjsonPath:(NSString*) serial
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
-
- NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
- upfolder = [upfolder stringByAppendingPathComponent:serial];
-
- NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
- return jsonpath;
- }
- +(NSString *) getPDFPath:(NSString*) file
- {
-
- NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
-
- NSString *saveDirectory=[paths objectAtIndex:0];
- NSString *saveFileName=file ;
-
- NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
-
-
- DebugLog(@"%@",newFilePath);
- return newFilePath;
- }
- +(NSString *) offline_docnumber
- {
- // return @"prefix123";
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if( RASingleton.sharedInstance.user==nil)
- return nil;
-
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- NSDictionary* user_info = [defaults dictionaryForKey:RASingleton.sharedInstance.user];
- NSString* prefix=user_info[@"prefix"];
- NSString* agentname=user_info[@"agent_name"];
- RASingleton.sharedInstance.agentName = agentname;
- if(prefix==nil)
- return nil;
- long docint=[defaults integerForKey:prefix];
- docint++;
- [defaults removeObjectForKey:prefix];
- [defaults setInteger:docint forKey:prefix];
- [defaults synchronize];
-
- return [NSString stringWithFormat:@"%@%06ld",prefix,docint ];
- }
- //+ (int)heartBeat {
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- // [params setObject:@"getStatus" forKey:@"_operate"];
- //
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- //// if(appDelegate.user!=nil)
- //// [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai2010"] forKey:@"user"];
- //// if(appDelegate.password!=nil)
- //// [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai2010"] forKey:@"password"];
- //
- // if(RASingleton.sharedInstance.user!=nil)
- // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- //
- ////
- //// NSString *DeviceToken = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
- //// [params setValue:DeviceToken forKey:@"deviceid"];
- //
- //
- // NSData* json=[self get_json:URL_HEART_BEAT parameters:params file:nil];
- // if(json==nil)
- // return -1;
- // NSError *error=nil;
- // NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- //
- // return [[resultDic objectForKey:@"result"] intValue];
- //}
- #pragma mark new network
- +(void)request_new_document : (NSMutableDictionary*) params completionHandler:(resultHandler)result
- {
-
-
-
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(RASingleton.sharedInstance.user!=nil)
- // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- //
- //
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- params[@"_operate"]=@"doc_id";
-
- // if(![self IsNetworkAvailable])
- // {
- // DebugLog(@"NET ERR");
- //
- // result ([[RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil] mutableCopy]);
- //
- // return;
- // // return nil;
- // }
-
- [self request_interface:URL_NEW_DOCUMENT parameters:params err_record_url:nil completionHandler:result retry:0];
- // NSData* json=[self get_json:URL_NEW_DOCUMENT parameters:params file:nil];
- //if(json==nil)
-
- //
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // int result = [[jsobj valueForKey:@"result"] intValue];
- // DebugLog(@"new_document result:%d",result);
- //
- // return jsobj;
- }
- +(void)request_login : (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
- {
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
-
- [params setValue:[AESCrypt AES128Encrypt:user key:@"usai2010"] forKey:@"user"];
- [params setValue:[AESCrypt AES128Encrypt:password key:@"usai2010"] forKey:@"password"];
- [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
- [params setValue:@"login" forKey:@"_operate"];
-
-
- [self request_interface:URL_UPDATE_AUTH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
- int ret = [self parse_logininfo:chresult user:user password:password] ;
-
-
- NSMutableDictionary * retjson = [NSMutableDictionary new];
-
- retjson[@"result"]= [NSNumber numberWithInt:ret];
-
- result(retjson);
-
-
- } retry:0];
-
- }
- +(int)parse_logininfo: (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
- {
- DebugLog(@"parse_authinfo");
- // NSError *error=nil;
-
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- if(jsobj)
- {
-
- int result = [[jsobj valueForKey:@"result"] intValue];
-
- if (result<0)
- return result;
- if(result!=AP_USER_AUTH&& result!=9)
- {
-
-
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- // [appDelegate Logout];
- if(result==8)
- {
- return RESULT_LOGIN_DEVICE;
- }
- return RESULT_FALSE;
-
- }
-
- NSString* offPrefix = jsobj[@"randcode"];
- bool skip_verify = [jsobj[@"skip_save_verify"] boolValue];
-
-
-
- NSString* agentName = jsobj[@"agent_name"];
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
-
- // NSString* skip_save_verify = jsobj[@"skip_save_verify"];
-
-
- NSMutableDictionary* user_info = [NSMutableDictionary new];
- user_info[@"prefix"]=offPrefix;
- user_info[@"agent_name"]= agentName;
-
-
- [defaults setObject:user_info forKey:user];
-
- [defaults synchronize];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- [appDelegate Login:user pwd:password skip_verify:skip_verify offPrefix:offPrefix agentName:agentName];
-
-
- return RESULT_TRUE;
-
- }
- // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
- // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
- // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
-
-
-
- return RESULT_USERAUTH_ERROR;
- }
- +(void)request_logout:(resultHandler)result
- {
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
-
-
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- params[@"_operate"]=@"logout_zip";
-
-
- [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
- NSMutableDictionary* jsobj=resulti;
- int result_code = [[jsobj valueForKey:@"result"] intValue];
-
- if (result_code==2)
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [appDelegate Logout];
- }
- result(resulti);
- } retry:0];
-
- }
- +(void)request_doc_list:(NSMutableDictionary*) params completionHandler:(resultHandler)result
- {
- params[@"_operate"]=@"listIpad";
- [self request_interface:URL_REQUEST_DOC parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
-
- NSString* base64str = chresult[@"str"];
- NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
- chresult=[[RAConvertor string2dict:decryptstr] mutableCopy];
-
- result(chresult);
-
- } retry:0];
-
- }
- +(void)request_save_document:(NSString*)file isnew:(bool)isNewDocument completionHandler:(resultHandler)result
- {
-
-
- // file
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- params[@"_operate"]=@"deviceMain";
- params[@"modify_document"]=[NSNumber numberWithBool:!isNewDocument];
-
- params=[self prepare_additional_params:params];
- // [self request_interface:URL_UPLOAD_PDF parameters:params err_record_url:nil completionHandler:result retry:0];
-
-
-
- NSData* data = [NSData dataWithContentsOfFile:file];
- NSString* filename = [file lastPathComponent];
- [self request_upload_fast:data FileName:filename server:URL_UPLOAD_PDF parameters:params completionHandler:result];
- //if(json==nil)
- }
- +(void) request_update_notes:(NSString*) doc_number notes:(NSString*)notes completionHandler:(resultHandler)result
- {
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
-
-
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
-
- params[@"doc_number"]=doc_number;
- params[@"notes"]=notes;
-
- params[@"_operate"]=@"updateNotes";
-
- [self request_interface:URL_UPDATE_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
-
- //if(json==nil)
- }
- + (void)request_heart_beat:(resultHandler)result
- {
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setObject:@"getStatus" forKey:@"_operate"];
-
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
-
-
- [self request_interface:URL_HEART_BEAT parameters:params err_record_url:nil completionHandler:result retry:0];
-
- }
- + (void)request_upload_file:(NSString*)file params:(NSMutableDictionary*) params completionHandler:(resultHandler)result
- {
- params[@"_operate"]=@"uploadFileIpad";
-
- params=[self prepare_additional_params:params];
- // [self request_interface:URL_UPLOAD_PDF parameters:params err_record_url:nil completionHandler:result retry:0];
-
-
-
- NSData* data = [NSData dataWithContentsOfFile:file];
- NSString* filename = [file lastPathComponent];
- [self request_upload_fast:data FileName:filename server:URL_UPLOAD_PDF parameters:params completionHandler:result];
-
-
- }
- @end
|