| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661 |
- //
- // RANetwork.m
- // Apex Mobile
- //
- // Created by Ray on 31/01/2018.
- // Copyright © 2018 United Software Applications, Inc. All rights reserved.
- //
- #import "config.h"
- #import "RAUtils.h"
- #import "AESCrypt.h"
- #import "RANetwork.h"
- #import "AppDelegate.h"
- #import "RAConvertor.h"
- #import "ApexMobileDB.h"
- @implementation RANetwork
- +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
- {
-
-
- params = [self prepare_addtional_params:params];
-
- return [super get_json:url parameters:params file: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 RESULT_TRUE:
- [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 RESULT_TIMEOUT:
- [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;
- }
- +(NSMutableDictionary*) prepare_addtional_params:(NSMutableDictionary* ) params
- {
-
- if (params == nil) {
- params = [NSMutableDictionary dictionary];
- }
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(appDelegate.user!=nil && params[@"user"] == nil)
- // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"Usai2010"] forKey:@"user"];
- // if(appDelegate.password!=nil&& params[@"pwd"] == nil)
- // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"Usai2010"] forKey:@"pwd"];
-
- if(appDelegate.user!=nil && params[@"user"] == nil)
- [params setValue:appDelegate.user forKey:@"user"];
- if(appDelegate.password!=nil&& params[@"pwd"] == nil)
- [params setValue:appDelegate.password forKey:@"pwd"];
-
- [params setValue:appDelegate.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;
- }
- +(int) ChangePassword : (NSString*) newpass user:(NSString*) user oldpass:(NSString*) oldpass
- {
-
- if(![NetworkUtils IsNetworkAvailable])
- return RESULT_NET_NOTAVAILABLE;
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
-
- NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
- [params setValue:user forKey:@"user"];
- [params setValue:oldpass forKey:@"oldpass"];
- [params setValue:newpass forKey:@"newpass"];
- [params setValue:@"Change Password" forKey:@"module_name"];
- [params setValue:@"handset_search" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params file:nil];
-
-
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
-
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- if(jsobj)
- {
- int result = [[jsobj valueForKey:@"result"] intValue];
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_RETRIEVE_PASS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- if(result!=AP_USER_AUTH)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- return RESULT_FALSE;
-
- }
- return RESULT_TRUE;
-
- }
- return RESULT_NET_ERROR;
-
-
- }
- +(int) RetrievePassword : (NSString*) user email:(NSString*) email
- {
-
- if(![NetworkUtils IsNetworkAvailable])
- return RESULT_NET_NOTAVAILABLE;
- NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
- [params setValue:user forKey:@"user"];
- [params setValue:email forKey:@"email"];
- [params setValue:@"Retrieve Password" forKey:@"module_name"];
- [params setValue:@"handset_search" forKey:@"action"];
- NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
-
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- if(jsobj)
- {
- int result = [[jsobj valueForKey:@"result"] intValue];
- if(result!=AP_USER_AUTH)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- return RESULT_FALSE;
-
- }
- return RESULT_TRUE;
-
- }
- return RESULT_NET_ERROR;
-
-
- }
- +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
- {
- DebugLog(@"parse_authinfo");
- NSError *error=nil;
-
- sqlite3 *db =[ApexMobileDB get_db];
-
-
-
-
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- if(jsobj)
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- int result = [[jsobj valueForKey:@"result"] intValue];
- if(result!=AP_USER_AUTH)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- [appDelegate Logout];
- return RESULT_FALSE;
-
- }
- NSDictionary* objheader = [jsobj objectForKey:@"header"];
-
- NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
- DebugLog(@"required_ver=%@ ",required_ver);
- NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
- NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
- versionNum = [NSString stringWithFormat:@"A%@",versionNum];
- int ibadge = [[objheader valueForKey:@"badge"] intValue];
-
- // if([ibadge isEqual:[NSNull null]])
- // strbadge=@"0";
- // if(ibadge==nil)
- // ibadge=@"0";
- // if([strbadge isEqualToString:@"null"])
- // strbadge=@"0";
- app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
-
- BOOL bigger = [versionNum compare:required_ver] ;
- if(!bigger)
- return RESULT_VER_LOW;
- // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
- appDelegate.user = user;
- appDelegate.password = password;
- // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
- if ([[objheader valueForKey:@"update"] boolValue]==false)
- {
- // no update on the server;
- return RESULT_TRUE;
- }
- int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
- // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
-
- [ApexMobileDB execSql:@"delete from auth_ver;" db:db];
- [ApexMobileDB execSql:[NSString stringWithFormat:@"insert into auth_ver (ver) values (%d);",Auth_InfoVer] db:db];
-
- // [defaults synchronize];
-
- NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
- NSArray* keys= [objfuncs allKeys];
-
-
-
- [ApexMobileDB execSql: [NSString stringWithFormat: @"update fields_info set abandon = 1 where user ='%@'",user] db:db];
- [ApexMobileDB execSql: [NSString stringWithFormat: @"update actions_info set abandon = 1 where user ='%@'",user] db:db];
- char* sql = "insert into fields_info(name,aname,field_type,function_name,behavior,priority,show,user) values(?,?,?,?,?,?,?,?)";
- char* sql1 = "insert into actions_info(name,function_name,user,priority) values(?,?,?,?)";
-
- sqlite3_stmt *stmt;
- sqlite3_stmt *stmt1;
- sqlite3_prepare_v2(db, sql, -1, &stmt, nil);
- sqlite3_prepare_v2(db, sql1, -1, &stmt1, nil);
-
- // db.beginTransaction();
- for(int i=0;i<keys.count;i++)
- {
- NSString* func_name = keys[i];
- NSDictionary *objfun = [objfuncs objectForKey:func_name];
- int behavior, priority = 999;
- int show =1;
- NSDictionary *objbehavior = [objfun objectForKey:@"search"];
- NSArray* keysbehavior= [objbehavior allKeys];
- behavior = BEHAVIOR_SEARCH;
- for(int j=0;j<keysbehavior.count;j++)
- {
- NSString* field = keysbehavior[j];
- NSDictionary* field_info = [objbehavior objectForKey:field];
- NSString* field_name =[field_info valueForKey:@"name"] ;
- NSString* field_type = [field_info valueForKey:@"type"] ;
- NSString* alias_name = [field_info valueForKey:@"alias"] ;
- priority = [[field_info valueForKey:@"priority"] intValue];
- if(priority==999)
- show=0;
- else
- show=1;
- int id = [ApexMobileDB get_recordid:db table:@"fields_info" where:[NSString stringWithFormat:@"name='%@' and behavior=%d and function_name='%@' and user='%@'",field_name,behavior,func_name,user]];
- if(id>=0)
- [ApexMobileDB execSql:[NSString stringWithFormat:@"update fields_info set abandon = 0 where _id=%d",id] db:db];
- else
- {
-
- sqlite3_bind_text(stmt, 1, [field_name UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 2, [alias_name UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 3, [field_type UTF8String], -1, NULL);
-
- sqlite3_bind_text(stmt, 4, [func_name UTF8String], -1, NULL);
-
- sqlite3_bind_int(stmt, 5, behavior);
- sqlite3_bind_int(stmt, 6, priority);
- sqlite3_bind_int(stmt, 7, show);
- sqlite3_bind_text(stmt, 8, [user UTF8String], -1, NULL);
-
-
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- fprintf(stderr, "Error: insert search failed, error infomation: %s\n", sqlite3_errmsg(db));
- }
- sqlite3_reset(stmt);
-
- }
-
-
- }
-
- objbehavior = [objfun objectForKey:@"result"];
- NSArray* keysresult= [objbehavior allKeys];
- behavior = BEHAVIOR_RESULT;
- for(int j=0;j<keysresult.count;j++)
- {
- NSString* field = keysresult[j];
- NSDictionary* field_info = [objbehavior objectForKey:field];
- NSString* field_name =[field_info valueForKey:@"name"] ;
- NSString* field_type = [field_info valueForKey:@"type"] ;
- NSString* alias_name = [field_info valueForKey:@"alias"] ;
- priority = [[field_info valueForKey:@"priority"] intValue];
- if(priority==999)
- show=0;
- else
- show=1;
- int id = [ApexMobileDB get_recordid:db table:@"fields_info" where:[NSString stringWithFormat:@"name='%@' and behavior=%d and function_name='%@' and user='%@'",field_name,behavior,func_name,user]];
- if(id>=0)
- [ApexMobileDB execSql:[NSString stringWithFormat:@"update fields_info set abandon = 0 where _id=%d",id] db:db];
- else
- {
- sqlite3_bind_text(stmt, 1, [field_name UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 2, [alias_name UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 3, [field_type UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 4, [func_name UTF8String], -1, NULL);
- sqlite3_bind_int(stmt, 5, behavior);
- sqlite3_bind_int(stmt, 6, priority);
- sqlite3_bind_int(stmt, 7, show);
- sqlite3_bind_text(stmt, 8, [user UTF8String], -1, NULL);
-
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- fprintf(stderr, "Error: insert result failed, error infomation: %s\n", sqlite3_errmsg(db));
- }
- sqlite3_reset(stmt);
-
- }
- }
- objbehavior = [objfun objectForKey:@"actions"];
- NSArray* keysactions= [objbehavior allKeys];
- behavior = BEHAVIOR_SEARCH;
- for(int j=0;j<keysactions.count;j++)
- {
- NSString* actionname = keysactions[j];
- int action_priority = [[objbehavior valueForKey:actionname] intValue];
- int id = [ApexMobileDB get_recordid:db table:@"actions_info" where:[NSString stringWithFormat:@"name='%@' and function_name='%@' and user='%@'",actionname,func_name,user]];
- if(id>=0)
- [ApexMobileDB execSql:[NSString stringWithFormat:@"update actions_info set abandon = 0 , priority=%d where _id=%d",action_priority,id] db:db];
- else
- {
-
- sqlite3_bind_text(stmt1, 1, [actionname UTF8String], -1, NULL);
- sqlite3_bind_text(stmt1, 2, [func_name UTF8String], -1, NULL);
- sqlite3_bind_text(stmt1, 3, [user UTF8String], -1, NULL);
- sqlite3_bind_int(stmt1, 4, action_priority);
-
- if (sqlite3_step(stmt1) != SQLITE_DONE)
- {
- fprintf(stderr, "Error: insert action_info failed, error infomation: %s\n", sqlite3_errmsg(db));
- }
- sqlite3_reset(stmt1);
- }
- }
- }
- [ApexMobileDB execSql:@"delete from fields_info where abandon = 1" db:db];
- [ApexMobileDB execSql:@"delete from actions_info where abandon = 1" db:db];
-
- sqlite3_finalize(stmt);
- sqlite3_finalize(stmt1);
- sqlite3_close(db);
- /*
-
- db.setTransactionSuccessful();
- db.endTransaction();
- */
- 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;
- }
- +(DetailContent*) get_detailcontent: (NSMutableDictionary *) params
- {
- DebugLog(@"get_detailcontent");
- DetailContent * detailContent = [[DetailContent alloc] init];
- NSMutableArray* segments = [[NSMutableArray alloc] init];
- detailContent.segments = segments;
- if(![NetworkUtils IsNetworkAvailable])
- {
- detailContent.result_code = RESULT_NET_NOTAVAILABLE;
- return detailContent;
- }
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- [params setValue:@"handset_search" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- NSData* json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- detailContent.result_code = RESULT_NET_ERROR;
- return detailContent;
- }
-
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
-
-
- if(jsobj)
- {
- int result = [[jsobj valueForKey:@"result"] intValue];
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- detailContent.result_code = RESULT_NET_ERROR;
- return detailContent;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- if(result!=AP_USER_AUTH)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- detailContent.result_code = result;
- return detailContent;
-
- }
-
-
- // if([params[@"action_type"] isEqualToString:@"Tracking"])
- // {
- // NSString *path = [[NSBundle mainBundle] pathForResource:@"fake_tracking.json" ofType:nil];
- // NSData *data = [[NSData alloc] initWithContentsOfFile:path];
- // NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
- // jsobj = json;
- // }
-
- int count =[[jsobj valueForKey:@"count"] intValue];
-
- // if ([[params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
- // NSMutableDictionary *mJson = [jsobj mutableCopy];
- // NSDictionary *comm = @{
- // @"_name": @"Communication",
- // @"_type": @"communication",
- // @"cc": @"",
- // @"receipt": @"",
- // @"count": @2,
- // @"item0": @{
- // @"Sender": @"user name",
- // @"msg": @"content bla bla bla...",
- // @"mst_time": @"04/28/2018 20:15:33",
- // @"email_url": @"https://www.baidu.com"
- // },
- // @"item1": @{
- // @"Sender": @"user name",
- // @"msg": @"content bla bla bla...",
- // @"mst_time": @"04/28/2018 20:15:33"
- // }
- // };
- // [mJson setObject:comm forKey:[NSString stringWithFormat:@"group%d",count]];
- //
- // [mJson setObject:@(++count) forKey:@"count"];
- //
- // jsobj = mJson;
- // }
-
- detailContent.result_code = RESULT_TRUE;
- if(count==0)
- {
-
- return detailContent;
- }
-
- for(int i=0;i<count;i++)
- {
-
- NSDictionary* segment = [jsobj objectForKey:[NSString stringWithFormat:@"group%d",i]];
- [segments addObject:segment];
-
- /*
- JSONObject groupobj = jsonObj.getJSONObject("group" + i);
- View v = inflater.inflate(R.layout.group_tag, null);
- v.setOnClickListener(this);
-
- TextView tvgroup = (TextView) v.findViewById(R.id.tv_group);
- String group_name = groupobj.getString("_name");
- tvgroup.setText(group_name);
- v.setId(commonUtil.generateViewId());
- ll_root.addView(v);
- String grouptype = groupobj.getString("_type");
-
- */
- }
-
- // NSDictionary* objrecords = [jsobj objectForKey:@"records"];
-
- detailContent.originContent = jsobj;
-
- return detailContent;
-
- }
- return nil;
-
- }
- +(PageData*) get_pagedata: (NSMutableDictionary *) params
- {
-
- DebugLog(@"get_pagedata");
- if(![NetworkUtils IsNetworkAvailable])
- return nil;
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- [params setValue:@"handset_search" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- NSData* json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
-
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- if(jsobj)
- {
- int result = [[jsobj valueForKey:@"result"] intValue];
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- if(result!=AP_USER_AUTH)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- return nil;
-
- }
-
- NSDictionary* objrecords = [jsobj objectForKey:@"records"];
-
- PageData * pageData = [[PageData alloc] initWithRecords:objrecords];
- return pageData;
-
- }
- return nil;
-
- }
- +(int) get_recordcount: (NSMutableDictionary *) params// delegate:(id < NSURLConnectionDelegate >)delegate
- {
- DebugLog(@"get_recordcount");
- if(![NetworkUtils IsNetworkAvailable])
- return RESULT_NET_NOTAVAILABLE;
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- [params setValue:@"handset_search_count" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
-
- NSData* json=[self get_json:URL_REQUEST_COUNT parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
-
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- if(jsobj)
- {
- int result = [[jsobj valueForKey:@"result"] intValue];
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_REQUEST_COUNT parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- if(result!=AP_USER_AUTH)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- return RESULT_USERAUTH_ERROR;
-
- }
- else
- return [[jsobj valueForKey:@"count" ] intValue];
- }
-
- return RESULT_ERROR;
- }
- //+(bool) IsHostAvailable : (NSString*) url
- //{
- // Reachability *r = [Reachability reachabilityWithHostName:url];
- // int i = [r currentReachabilityStatus];
- // if ([r currentReachabilityStatus]==NotReachable)
- // return false;
- // return true;
- //}
- +(bool) IsNetworkAvailable
- {
-
- if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
- ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
- return false;
- return true;
- }
- +(void)post_without_return : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
- {
-
- // [self get_json:url parameters:params file:nil err_recorder:nil result_handler:nil decrypt_handler:nil];
-
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- //分界线的标识符
- NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
- //根据url初始化request
- NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
- cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
- timeoutInterval:30];
- //分界线 --AaB03x
- NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
- //结束符 AaB03x--
- NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
- //要上传的图片
- // UIImage *image=[params objectForKey:@"pic"];
- //得到图片的data
- // NSData* data = UIImagePNGRepresentation(image);
- //http body的字符串
- NSMutableString *body=[[NSMutableString alloc]init];
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // [params setValue:@"handset_login" forKey:@"action"];
- // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- // [params setValue:password forKey:@"password"];
- // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
- // [headers setValue:headQuerlString forKey:@"param"];
- //参数的集合的所有key的集合
- NSArray *keys= [params allKeys];
- DebugLog(@"================parms==================");
- //遍历keys
- for(int i=0;i<[keys count];i++)
- {
- //得到当前key
- NSString *key=[keys objectAtIndex:i];
- //如果key不是pic,说明value是字符类型,比如name:Boris
- if(![key isEqualToString:@"pic"])
- {
- //添加分界线,换行
- [body appendFormat:@"%@\r\n",MPboundary];
- //添加字段名称,换2行
- [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
- //添加字段的值
- [body appendFormat:@"%@\r\n",[params objectForKey:key]];
- DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
- }
- }
- DebugLog(@"================parms==================");
- ////添加分界线,换行
- [body appendFormat:@"%@\r\n",MPboundary];
- //声明pic字段,文件名为boris.png
- [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
- //声明上传文件的格式
- [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
- //声明结束符:--AaB03x--
- NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
- //声明myRequestData,用来放入http body
- NSMutableData *myRequestData=[NSMutableData data];
- //将body字符串转化为UTF8格式的二进制
- [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
- //将image的data加入
- // [myRequestData appendData:data];
- //加入结束符--AaB03x--
- [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
- //设置HTTPHeader中Content-Type的值
- NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
- //设置HTTPHeader
- [request setValue:content forHTTPHeaderField:@"Content-Type"];
- //设置Content-Length
- [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
- //设置http body
- [request setHTTPBody:myRequestData];
- //http method
- [request setHTTPMethod:@"POST"];
- // NSHTTPURLResponse* urlResponse = nil;
- //
- // NSError *error = [[NSError alloc] init];
- //
- [NSURLConnection sendAsynchronousRequest:request queue:nil completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){}];
- // NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:nil];
-
-
-
- }
- +(NSData*)get_marketnews : (NSString*) id limit: (int) limit
- {
- if(![NetworkUtils IsNetworkAvailable])
- return nil;//RESULT_NET_NOTAVAILABLE;
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- [params setValue:@"Market News" forKey:@"module_name"];
- [params setValue:@"search" forKey:@"action_type"];
- [params setValue:id forKey:@"id"];
- [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
-
- NSData* json=[self get_json:URL_ANNOUNCEMENTS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- return json;
-
-
-
- }
- +(NSData*)get_MessageDetail: (int) offset limit:(int) limit from:(NSString*) sid to:(NSString*) eid
- {
- if(![NetworkUtils IsNetworkAvailable])
- return nil;//RESULT_NET_NOTAVAILABLE;
-
-
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- // NSString* sess
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- [params setValue:@"Pull Message" forKey:@"module_name"];
- [params setValue:@"handset_search" forKey:@"action"];
- [params setValue:sid forKey:@"s_id"];
- [params setValue:eid forKey:@"e_id"];
- [params setValue:@"detail" forKey:@"action_type"];
- [params setValue:@"handset_search" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- [params setValue:appDelegate.duid forKey:@"uuid"];
-
-
-
- [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
- [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
- // [params setValue:@"20" forKey:@"limit"];
-
- NSData* json=[self get_json:URL_PUSH parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- int result = [[jsobj valueForKey:@"result" ] intValue] ;
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_PUSH parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- if(result!= AP_MESSAGE_NEW)
- return nil;
-
-
- return json;
-
- }
- +(int) delAllMessage:(NSString*) before
- {
- if(![NetworkUtils IsNetworkAvailable])
- return RESULT_NET_NOTAVAILABLE;//RESULT_NET_NOTAVAILABLE;
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- // NSString* sess
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- [params setValue:@"Pull Message" forKey:@"module_name"];
- [params setValue:@"read_all" forKey:@"action_type"];
- [params setValue:@"handset_search" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- [params setValue:appDelegate.duid forKey:@"uuid"];
- [params setValue:before forKey:@"id"];
-
-
- NSData* json=[self get_json:URL_PUSH parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- int result = [[jsobj valueForKey:@"result" ] intValue] ;
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_PUSH parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return RESULT_NET_ERROR;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- return result;
-
-
- }
- +(NSData*)pull_message: (int) offset
- {
- if(![NetworkUtils IsNetworkAvailable])
- return nil;//RESULT_NET_NOTAVAILABLE;
-
-
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- // NSString* sess
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- [params setValue:@"Pull Message" forKey:@"module_name"];
- [params setValue:@"ios_list" forKey:@"action_type"];
- [params setValue:@"handset_search" forKey:@"action"];
- // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
- [params setValue:appDelegate.duid forKey:@"uuid"];
- [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
- [params setValue:@"20" forKey:@"limit"];
-
- NSData* json=[self get_json:URL_PUSH parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- int result = [[jsobj valueForKey:@"result" ] intValue] ;
- if(result== AP_SESSION_EXPIRED)
- {
- [self Authorize:appDelegate.user password:appDelegate.password];
- json=[self get_json:URL_PUSH parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- result = [[jsobj valueForKey:@"result"] intValue];
-
- }
- if(result!= AP_MESSAGE_NEW)
- return nil;
-
-
- return json;
-
- }
- +(bool) UpdateServiceLocation
- {
- if(![NetworkUtils IsNetworkAvailable])
- return false;//RESULT_NET_NOTAVAILABLE;
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- [params setValue:@"Location" forKey:@"module_name"];
- [params setValue:@"search" forKey:@"action_type"];
- [params setValue:@"999" forKey:@"limit"];
-
- NSData* json=[self get_json:URL_LOCATIONS parameters:params file:nil];
- if (json==nil)
- return false;
-
- NSError *error=nil;
- NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- NSString* remote_ver = [jsobj valueForKey:@"version"] ;
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- NSString *local_ver =[defaults stringForKey:@"location_ver"];
- int total = [[jsobj valueForKey:@"total"] intValue];
-
- BOOL bigger = [remote_ver compare:local_ver];
- // if(!bigger)
- // return false;
-
-
- sqlite3 *db =[ApexMobileDB get_db];
- [ApexMobileDB execSql:@"delete from locations" db:db];
-
- char* sql = "insert into locations(area,company,city,longitude,latitude,address,telephone,fax,contact,email) values(?,?,?,?,?,?,?,?,?,?)";
- sqlite3_stmt *stmt;
-
- sqlite3_prepare_v2(db, sql, -1, &stmt, nil);
-
- NSDictionary* objrecords = [jsobj objectForKey:@"records"];
-
- for(int i=0;i<total;i++)
- {
-
- NSDictionary* objlocation = [objrecords objectForKey:[NSString stringWithFormat:@"record%d",i]];
- NSString* area = [objlocation valueForKey:@"area"];
- NSString* company = [objlocation valueForKey:@"company"];
- NSString* city = [objlocation valueForKey:@"city"];
- NSString* longitude = [objlocation valueForKey:@"longitude"] ;
- NSString* latitude = [objlocation valueForKey:@"latitude"] ;
- NSString* address = [objlocation valueForKey:@"address"];
- NSString* telephone = [objlocation valueForKey:@"telephone"];
- NSString* fax = [objlocation valueForKey:@"fax"];
- NSString* contact = [objlocation valueForKey:@"contact"];
- NSString* email = [objlocation valueForKey:@"email"];
-
-
- if([area isEqual:[NSNull null]])
- area=@"";
- if(area==nil)
- area=@"";
- if([area isEqualToString:@"null"])
- area=@"";
-
-
- if([company isEqual:[NSNull null]])
- company=@"";
- if(company==nil)
- company=@"";
- if([company isEqualToString:@"null"])
- company=@"";
-
- if([city isEqual:[NSNull null]])
- city=@"";
- if(city==nil)
- city=@"";
- if([city isEqualToString:@"null"])
- city=@"";
-
- if([longitude isEqual:[NSNull null]])
- longitude=@"";
- if(longitude==nil)
- longitude=@"";
- if([longitude isEqualToString:@"null"])
- longitude=@"";
-
- if([latitude isEqual:[NSNull null]])
- latitude=@"";
- if(latitude==nil)
- latitude=@"";
- if([latitude isEqualToString:@"null"])
- latitude=@"";
-
- if([address isEqual:[NSNull null]])
- address=@"";
- if(address==nil)
- address=@"";
- if([address isEqualToString:@"null"])
- address=@"";
-
- if([telephone isEqual:[NSNull null]])
- telephone=@"";
- if(telephone==nil)
- telephone=@"";
- if([telephone isEqualToString:@"null"])
- telephone=@"";
-
- if([fax isEqual:[NSNull null]])
- fax=@"";
- if(fax==nil)
- fax=@"";
- if([fax isEqualToString:@"null"])
- fax=@"";
-
- if([contact isEqual:[NSNull null]])
- contact=@"";
- if(contact==nil)
- contact=@"";
- if([contact isEqualToString:@"null"])
- contact=@"";
-
- if([email isEqual:[NSNull null]])
- email=@"";
- if(email==nil)
- email=@"";
- if([email isEqualToString:@"null"])
- email=@"";
-
- sqlite3_bind_text(stmt, 1, [area UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 2, [company UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 3, [city UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 4, [longitude UTF8String], -1, NULL);
-
- sqlite3_bind_text(stmt, 5, [latitude UTF8String], -1, NULL);
-
-
-
- sqlite3_bind_text(stmt, 6, [address UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 7, [telephone UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 8, [fax UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 9, [contact UTF8String], -1, NULL);
- sqlite3_bind_text(stmt, 10, [email UTF8String], -1, NULL);
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
-
- fprintf(stderr, "Error: insert search failed, error infomation: %s\nsql:%s\n", sqlite3_errmsg(db),sqlite3_sql(stmt));
- }
- sqlite3_reset(stmt);
-
- }
-
- sqlite3_finalize(stmt);
-
- sqlite3_close(db);
-
- [defaults removeObjectForKey:@"location_ver"];
- [defaults setValue:remote_ver forKey:@"location_ver"];
- // [defaults synchronize];
- return true;
-
- }
- //+(void) testmail1:(UIViewController*) caller
- //{
- // MFMailComposeViewController *mail=[[MFMailComposeViewController alloc] init];
- // mail.mailComposeDelegate=caller;
- //
- // //设置主题
- // [mail setSubject:@"测试发送电子邮件"];
- //
- // //添加收件人
- // NSArray *toRecipients=[NSArray arrayWithObject:@"admin@163.com"];
- // [mail setToRecipients:toRecipients];
- // //添加抄送;
- // NSArray *ccRecipients=[NSArray arrayWithObjects:@"test1@163.com",@"test@qq.com", nil];
- // [mail setCcRecipients:ccRecipients];
- // //添加密送
- // NSArray *bccRecipients=[NSArray arrayWithObject:@"admin@gmail.com"];
- // [mail setBccRecipients:bccRecipients];
- //
- //
- // //添加一张图片
- // UIImage *addPic=[UIImage imageNamed:@"bg_3"];
- // NSData *imageData=UIImagePNGRepresentation(addPic);
- // [mail addAttachmentData:imageData mimeType:@"image/png" fileName:@"icon"];
- //
- // //添加一个xml附件
- //// NSString *file=[self fullBundlePathFromRelativePath:@"model.xml"];
- //// NSData *xmldata=[NSData dataWithContentsOfFile:file];
- //// [mail addAttachmentData:xmldata mimeType:@"" fileName:@"model"];
- //
- // NSString *emailBody=@"<font color='red'>send test email</font>";
- // [mail setMessageBody:emailBody isHTML:YES];
- // [caller presentViewController:mail animated:YES completion:nil];
- //
- //
- //}
- //+(void) testmail
- //{
- // NSMutableString *buffer=
- // [NSMutableString stringWithString:
- // @"<HTML><HEAD><TITLE>PAGE</TITLE></HEAD><BODY>example<img src=\"data:image/png;base64,\/9j\/4AAQSkZJRgABAQAAAQABAAD\/\/gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK\/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy\/9sAQwEJCQkMCwwYDQ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cMTo\/X\/AJar\/WvINYUCBJOd27FFFadCB+h\/dkP0rojeXDWwVpWYIMKCelFFUgMmYB74SsMsIyM\/jVyNR5WaKKuh8ciavwoiRt0e1sFfQ0+5jSFFlhXynX5cpxkHtRRUYn+KiqP8NlcH5g55ZSGBPPNNnmeS6kkOAXbJAHHNFFEt0Zr4TR0yxhN\/b3Q3B+SQDwSK61X\/ANlee+KKK4qmrOuGx6r8N\/8AkXrn\/r7b\/wBASiiit4fCjN7n\/9k=\" /></BODY></HTML>"];
- // NSString* subjectLine =@"Example HTML formatted EMAIL with Image";
- //
- // NSString *str1 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorSystemDefault, (CFStringRef) subjectLine, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8));
- // NSString *str2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorSystemDefault, (CFStringRef)buffer, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8));
- //
- // NSString *urlString = [NSString stringWithFormat:@"mailto:?subject=%@&body=%@",str1 ,str2 ];
- //
- // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
- //
- //// [NSURL URLWithString:urlString];
- //}
- +(NSData*)get_announcements : (NSString*) id limit: (int) limit
- {
- if(![NetworkUtils IsNetworkAvailable])
- return nil;//RESULT_NET_NOTAVAILABLE;
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- [params setValue:@"Announcements" forKey:@"module_name"];
- [params setValue:@"search" forKey:@"action_type"];
- [params setValue:id forKey:@"id"];
- [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
-
- NSData* json=[self get_json:URL_ANNOUNCEMENTS parameters:params file:nil];
- if (json==nil)
- {
- DebugLog(@"json is wrong");
- return nil;
- }
- return json;
-
-
-
- }
- +(void)Logout
- {
- if(![NetworkUtils IsNetworkAvailable])
- return ;//RESULT_NET_NOTAVAILABLE;
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- if(appDelegate.duid !=nil)
- [params setValue:appDelegate.duid forKey:@"udid"];
- [params setValue:@"handset_logout" forKey:@"action"];
-
- [self post_without_return :URL_UPDATE_AUTH parameters:params];
- }
- +(int)Authorize : (NSString*) user password:(NSString*) password{
-
- if(![NetworkUtils IsNetworkAvailable])
- return RESULT_NET_NOTAVAILABLE;
- // if(![RANetwork IsHostAvailable:URL_UPDATE_AUTH])
- // return RESULT_NET_ERROR;
-
-
- __block long ver = 0;
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- ver = appDelegate.authVer;
- if(appDelegate.duid !=nil)
- [params setValue:appDelegate.duid forKey:@"udid"];
- });
-
- [params setValue:@"handset_login" forKey:@"action"];
- // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
-
- [params setValue:user forKey:@"user"];
- [params setValue:password forKey:@"password"];
- [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
- #ifdef TEST
- [params setValue:@"true" forKey:@"is_debug"];
- #else
- [params setValue:@"false" forKey:@"is_debug"];
- #endif
- NSData* 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;
-
- }
- + (NSDictionary *)collectErrMsg:(NSString *)errMsg DeviceInfo:(NSString *)deviceInfo Time:(NSString *)time {
-
- NSMutableDictionary *params = [@{
- @"device_info" : deviceInfo == nil ? @"" : deviceInfo,
- @"crash_info" : errMsg == nil ? @"" : errMsg,
- @"crash_time" : time == nil ? @"" : time
- } mutableCopy];
-
- NSData* json=[self get_json:URL_ERR_LOG parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
- }
- + (NSDictionary *)requestHome {
-
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
-
- // action=hand_new_home_list
- [params setObject:@"hand_new_home_list" forKey:@"action"];
- [params setObject:@(YES) forKey:@"request_location"];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.personalmode)
- params[@"personal_mode"] = @"true";
- else
- params[@"personal_mode"] = @"false";
- NSData* json=[self get_json:URL_HOME parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
-
- }
- + (NSDictionary *)search:(NSMutableDictionary *)params {
-
- [params setObject:@"handset_search" forKey:@"action"];
-
- NSData* json=[self get_json:URL_REQUEST_COUNT parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
- }
- + (NSDictionary *)requestOrderHistory:(NSMutableDictionary *)params {
-
- [params setObject:@"hand_new_home_list_all" forKey:@"action"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.personalmode)
- params[@"personal_mode"] = @"true";
- else
- params[@"personal_mode"] = @"false";
- NSData* json=[self get_json:URL_HISTORY parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
- }
- + (void)download_file:(NSMutableDictionary *)params url:(NSString *)url toCachePath:(NSString *)path progressHandler:(progressHandler)progressHandler completionHandler:(resultHandler)result {
- params = [self prepare_addtional_params:params];
- [NetworkUtils downloadFileOffset:0 Param:params from:url method:@"POST" toPath:path progressHandler:progressHandler completionHandler:result];
- }
- + (NSDictionary *)requestKPI {
-
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
-
- [params setObject:@"hand_new_kpi" forKey:@"action"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.personalmode)
- params[@"personal_mode"] = @"true";
- else
- params[@"personal_mode"] = @"false";
- NSData* json=[self get_json:URL_KPI parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
-
- }
- + (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc SerialNo:(NSString *)serialNo {
-
- if (!email) {
- email = @"";
- }
- if (!serialNo) {
- serialNo = @"";
- }
-
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- [params setObject:@"handset_search" forKey:@"action"];
- [params setObject:@"save_communication_email" forKey:@"action_type"];
- [params setObject:serialNo forKey:@"serial_no"];
- [params setObject:email forKey:@"msg"];
-
- if (cc) {
- [params setObject:cc forKey:@"cc"];
- }
-
-
- NSData* json=[self get_json:URL_SEND_COMM_EMAIL parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
-
- }
- + (NSDictionary *)uploadUserSql:(NSString *)sql {
-
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- [params setObject:@"handset_search" forKey:@"action"];
- [params setValue:sql forKey:@"sql"];
-
- NSData* json=[self get_json:URL_UPLOAD_SQL parameters:params file:nil];
-
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
-
- NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
-
- return resultDic;
- }
- + (NSDictionary *)mockResult:(NSDictionary *)params {
-
- sleep(2);
- // Booking : module_name = Ocean Booking
- NSDictionary *item_booking = @{
- @"type": @0,
- @"title":@"FU YAMA TRADing", // Consignee
- @"date":@"03/28/2019 - 04/24/2019", // M.V ETD - M.V ETA
- @"port":@"CNYTN - USLAX", // pol pod
- @"desc":@"B61180700423", // Booking#
- @"detail":@"HUNG TA GARDEN ENTERPRISE CO., LTD", // Shipper
- @"consignee": @"Martin Jane",
- @"addition":@[
- @{
- @"name":@"Carrier Booking#",
- @"value":@"NAM1774822"
- },
- @{
- @"name":@"Consignee",
- @"value":@"FU YAMA TRADing"
- },
- @{
- @"name":@"Place Of Delivery",
- @"value":@"CAPE TOWN, SOUTH AFRICA"
- },
- ],
- @"rowActionParameters":@[
- @"27d620831e3f458643c8046305e2cd13"
- ]
- };
- // B/L Info : module_name = Ocean B/L info.
- NSDictionary *item_BL = @{
- @"type": @1,
- @"icon": @"status_ae",
- @"title":@"FU YAMA TRADing", // Consignee
- @"date":@"03/28/2019 - 04/24/2019", // ETD - ETA Port
- @"port":@"CNYTN - USLAX", // pol pod
- @"desc":@"A1903300004", // hbol#
- @"detail":@"VIENXING GLOBAL PTE LTD", // Shipper
- @"transport_stage": @3,
- @"rowActionParameters":@[
- @"27d620831e3f458643c8046305e2cd13"
- ]
- };
- // Container : module_name = Container detail
- NSDictionary *item_container = @{
- @"type": @2,
- @"icon": @"status_ae",
- @"title": @"CN - YC STONE INC",
- @"hbol": @"A1901280696",
- @"desc": @"A1901280696(1 containers)",
- @"detail": @"Gate in full for a booking; CNGOM (GAOMING, 44, CN 2019-01-04)",
- @"date": @"01/16/2019 - 01/29/2019",
- @"port": @"CNNSA - USLGB",
- @"transport_stage": @3,
- @"rowActionParameters":@[
- @"27d620831e3f458643c8046305e2cd13"
- ]
- };
- // Document : module_name = Download Document
- NSDictionary *item_doc = @{
- @"type": @3,
- @"fileName":@"A1811390637FR1-UTA.pdf",
- @"fileType":@"HBL",
- @"fileDesc":@"BOL:A1811390637, PO#:0001791,0001722,0001885",
- @"rowActionParameters":@[
- @"handset_search",
- @"download_doc",
- @"https://ra.apexshipping.com/main_new.php",
- @"QW10UUtFeDdRNlBFTzhLbFpYcCUyRmtUSFJnWHRwZ1RQSnBnZmpQblc0c1BHJTJCR1E5c2ZScWY3NXpIazJ0OXdicHEyUnolMkJxSkN1MDVV",
- @"Question : FileName: ONEYSRGU12759300FR3.PDF, BOL: ONEYSRGU12759300",
- @"FileName: ONEYSRGU12759300FR3.PDF, BOL: ONEYSRGU12759300",
- @""
- ]
- };
- NSString *module_name = [params objectForKey:@"module_name"];
- NSMutableArray *arr = [NSMutableArray array];
- for (int i = 0; i < 20; i++) {
- if ([module_name isEqualToString:@"Ocean Booking"]) {
- [arr addObject:item_booking.copy];
- } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
- [arr addObject:item_BL.copy];
- } else if ([module_name isEqualToString:@"Container detail"]) {
- [arr addObject:item_container.copy];
- } else if ([module_name isEqualToString:@"Download Document"]) {
- [arr addObject:item_doc.copy];
- }
- }
- NSArray *menu;
- NSString *title = @"";
- if ([module_name isEqualToString:@"Ocean Booking"]) {
- title = @"Ocean Booking";
- menu = @[
- @{
- @"title": @"Setting",
- @"action": @"field_setting"
- },
- @{
- @"title": @"Save",
- @"action": @"save"
- }
- ];
-
- } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
- title = @"Ocean B/L info";
- menu = @[
- @{
- @"title": @"Setting",
- @"action": @"field_setting"
- },
- @{
- @"title": @"Save",
- @"action": @"save"
- }
- ];
- } else if ([module_name isEqualToString:@"Container detail"]) {
- title = @"Container detail";
- menu = @[
- @{
- @"title": @"Setting",
- @"action": @"field_setting"
- },
- @{
- @"title": @"Save",
- @"action": @"save"
- }
- ];
- } else if ([module_name isEqualToString:@"Download Document"]) {
- title = @"Download Document";
- menu = @[
- @{
- @"title": @"Save",
- @"action": @"save"
- }
- ];
- }
- NSArray *row_actions;
- if ([module_name isEqualToString:@"Download Document"]) {
- row_actions = @[@{
- @"title": @"Download Document",
- @"module": @"quick_look",
- @"url": @"https://ra.apexshipping.com/main_new.php",
- @"params": @{
- @"action": @0,
- @"action_type": @1,
- @"prefix": @2,
- @"url": @3,
- @"email_subject": @4,
- @"email_content": @5,
- @"email": @6
- }
- }];
- } else {
- row_actions = @[@{
- @"title": @"Ocean B/L info Detail",
- @"module": @"detail",
- @"url": @"https://ra.apexshipping.com/main_new.php?action=handset_search",
- @"params": @{
- @"id": @0,
- }
- }];
- }
- NSDictionary *resultDic = @{
- @"result" : @RESULT_TRUE,
- @"title" : title,
- @"row_actions" : row_actions,
- @"items" : arr,
- @"menu" : menu
- };
- // for detail
- // NSArray *actions = @[
- // @"Detail",
- // @"ISF LOG",
- // @"AMS LOG",
- // @"Tracing",
- // @"Detail"
- // ];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
- NSMutableDictionary *json = [resultDic mutableCopy];
- [json setValue:actions forKey:@"actions"];
- NSLog(@"%@",[RAConvertor dict2string:json]);
- return json;
-
- }
- + (NSDictionary *)fetchResultParameters:(NSMutableDictionary *)params {
-
- // return [self mockResult:params];
-
- params[@"action"]=@"handset_search";
- NSData* json=[self get_json:URL_SEARCH_RESULT parameters:params file:nil];
- if (json==nil)
- {
- return @{
- @"result" : @RESULT_NET_ERROR,
- @"err_msg" : MSG_NET_ERROR
- };
- }
- NSMutableDictionary *resultDic = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
-
- // detail data in local database
- NSString *module_name = [params objectForKey:@"module_name"];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
- [resultDic setValue:actions forKey:@"actions"];
-
- return resultDic;
- }
- + (NSDictionary *)saveSearchParameters:(NSString *)paramStr forModule:(NSString *)module withName:(NSString *)name {
- if (!paramStr || !module) {
- return @{
- @"result" : @RESULT_FALSE,
- @"err_msg" : @"Sorry, something is wrong."
- };
- }
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- NSString *sql = [NSString stringWithFormat: @"insert into history(params,name,module_name,user) values('%@','%@','%@','%@')",paramStr,name,module,appDelegate.user];
-
- __block BOOL out_success = NO;
- [ApexMobileDB jk_sync_excute:sql completion:^(BOOL success) {
- out_success = success;
- }];
-
- if (out_success) {
-
- return @{
- @"result" : @RESULT_TRUE,
- @"err_msg" : @"save success."
- };
-
- } else {
- return @{
- @"result" : @RESULT_FALSE,
- @"err_msg" : @"Sorry, something is wrong."
- };
- }
- }
- + (NSString *)getDisplayFieldsForFunction:(NSString *)function {
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- return [ApexMobileDB getDisplayFieldsForFunction:function withUser:appDelegate.user];
- }
- @end
|