RANetwork.m 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719
  1. //
  2. // RANetwork.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 31/01/2018.
  6. // Copyright © 2018 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "config.h"
  9. #import "RAUtils.h"
  10. #import "AESCrypt.h"
  11. #import "RANetwork.h"
  12. #import "AppDelegate.h"
  13. #import "RAConvertor.h"
  14. #import "ApexMobileDB.h"
  15. @implementation RANetwork
  16. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  17. {
  18. params = [self prepare_addtional_params:params];
  19. return [super get_json:url parameters:params file:file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  20. int result=[[jsobj valueForKey:@"result"] intValue];
  21. // UIApplication * app = [UIApplication sharedApplication];
  22. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  23. switch (result) {
  24. case 0:
  25. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  26. break;
  27. case 1:
  28. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  29. break;
  30. case RESULT_TRUE:
  31. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  32. break;
  33. // case 8:
  34. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  35. // break;
  36. case 9:
  37. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  38. break;
  39. case RESULT_TIMEOUT:
  40. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  41. break;
  42. default:
  43. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  44. break;
  45. }
  46. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  47. // {
  48. // [jsobj setValue:@"9" forKey:@"result"];
  49. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  50. // }
  51. return jsobj;
  52. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  53. NSString* base64str = jsobj[@"str"];
  54. NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"Usai2010"];
  55. jsobj=[[RAConvertor string2dict:decryptstr] mutableCopy];
  56. return jsobj;
  57. }];
  58. /*
  59. */
  60. return nil;
  61. }
  62. +(NSMutableDictionary*) prepare_addtional_params:(NSMutableDictionary* ) params
  63. {
  64. if (params == nil) {
  65. params = [NSMutableDictionary dictionary];
  66. }
  67. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  68. // if(appDelegate.user!=nil && params[@"user"] == nil)
  69. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"Usai2010"] forKey:@"user"];
  70. // if(appDelegate.password!=nil&& params[@"pwd"] == nil)
  71. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"Usai2010"] forKey:@"pwd"];
  72. if(appDelegate.user!=nil && params[@"user"] == nil)
  73. [params setValue:appDelegate.user forKey:@"user"];
  74. if(appDelegate.password!=nil&& params[@"pwd"] == nil)
  75. [params setValue:appDelegate.password forKey:@"pwd"];
  76. [params setValue:appDelegate.build forKey:@"app_ver"];
  77. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  78. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  79. [params setValue:short_version forKey:@"app_short_ver"];
  80. #if TARGET_IPHONE_SIMULATOR//模拟器
  81. [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  82. #elif TARGET_OS_IPHONE//真机
  83. UIDevice * dev = [UIDevice currentDevice];
  84. NSUUID* uuid =dev.identifierForVendor;
  85. [params setValue:uuid.UUIDString forKey:@"deviceid"];
  86. #endif
  87. params[@"os"]=@"iOS";
  88. return params;
  89. }
  90. +(int) ChangePassword : (NSString*) newpass user:(NSString*) user oldpass:(NSString*) oldpass
  91. {
  92. if(![NetworkUtils IsNetworkAvailable])
  93. return RESULT_NET_NOTAVAILABLE;
  94. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  95. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  96. [params setValue:user forKey:@"user"];
  97. [params setValue:oldpass forKey:@"oldpass"];
  98. [params setValue:newpass forKey:@"newpass"];
  99. [params setValue:@"Change Password" forKey:@"module_name"];
  100. [params setValue:@"handset_search" forKey:@"action"];
  101. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  102. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params file:nil];
  103. if (json==nil)
  104. {
  105. DebugLog(@"json is wrong");
  106. return RESULT_NET_ERROR;
  107. }
  108. NSError *error=nil;
  109. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  110. if(jsobj)
  111. {
  112. int result = [[jsobj valueForKey:@"result"] intValue];
  113. if(result== AP_SESSION_EXPIRED)
  114. {
  115. [self Authorize:appDelegate.user password:appDelegate.password];
  116. json=[self get_json:URL_RETRIEVE_PASS parameters:params file:nil];
  117. if (json==nil)
  118. {
  119. DebugLog(@"json is wrong");
  120. return RESULT_NET_ERROR;
  121. }
  122. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  123. result = [[jsobj valueForKey:@"result"] intValue];
  124. }
  125. if(result!=AP_USER_AUTH)
  126. {
  127. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  128. return RESULT_FALSE;
  129. }
  130. return RESULT_TRUE;
  131. }
  132. return RESULT_NET_ERROR;
  133. }
  134. +(int) RetrievePassword : (NSString*) user email:(NSString*) email
  135. {
  136. if(![NetworkUtils IsNetworkAvailable])
  137. return RESULT_NET_NOTAVAILABLE;
  138. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  139. [params setValue:user forKey:@"user"];
  140. [params setValue:email forKey:@"email"];
  141. [params setValue:@"Retrieve Password" forKey:@"module_name"];
  142. [params setValue:@"handset_search" forKey:@"action"];
  143. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params file:nil];
  144. if (json==nil)
  145. {
  146. DebugLog(@"json is wrong");
  147. return RESULT_NET_ERROR;
  148. }
  149. NSError *error=nil;
  150. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  151. if(jsobj)
  152. {
  153. int result = [[jsobj valueForKey:@"result"] intValue];
  154. if(result!=AP_USER_AUTH)
  155. {
  156. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  157. return RESULT_FALSE;
  158. }
  159. return RESULT_TRUE;
  160. }
  161. return RESULT_NET_ERROR;
  162. }
  163. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  164. {
  165. DebugLog(@"parse_authinfo");
  166. NSError *error=nil;
  167. sqlite3 *db =[ApexMobileDB get_db];
  168. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  169. if(jsobj)
  170. {
  171. UIApplication * app = [UIApplication sharedApplication];
  172. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  173. int result = [[jsobj valueForKey:@"result"] intValue];
  174. if(result!=AP_USER_AUTH)
  175. {
  176. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  177. [appDelegate Logout];
  178. return RESULT_FALSE;
  179. }
  180. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  181. NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
  182. DebugLog(@"required_ver=%@ ",required_ver);
  183. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  184. NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  185. versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  186. int ibadge = [[objheader valueForKey:@"badge"] intValue];
  187. // if([ibadge isEqual:[NSNull null]])
  188. // strbadge=@"0";
  189. // if(ibadge==nil)
  190. // ibadge=@"0";
  191. // if([strbadge isEqualToString:@"null"])
  192. // strbadge=@"0";
  193. app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  194. BOOL bigger = [versionNum compare:required_ver] ;
  195. if(!bigger)
  196. return RESULT_VER_LOW;
  197. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  198. appDelegate.user = user;
  199. appDelegate.password = password;
  200. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  201. if ([[objheader valueForKey:@"update"] boolValue]==false)
  202. {
  203. // no update on the server;
  204. return RESULT_TRUE;
  205. }
  206. int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  207. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  208. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  209. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  210. [ApexMobileDB execSql:@"delete from auth_ver;" db:db];
  211. [ApexMobileDB execSql:[NSString stringWithFormat:@"insert into auth_ver (ver) values (%d);",Auth_InfoVer] db:db];
  212. // [defaults synchronize];
  213. NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  214. NSArray* keys= [objfuncs allKeys];
  215. [ApexMobileDB execSql: [NSString stringWithFormat: @"update fields_info set abandon = 1 where user ='%@'",user] db:db];
  216. [ApexMobileDB execSql: [NSString stringWithFormat: @"update actions_info set abandon = 1 where user ='%@'",user] db:db];
  217. char* sql = "insert into fields_info(name,aname,field_type,function_name,behavior,priority,show,user) values(?,?,?,?,?,?,?,?)";
  218. char* sql1 = "insert into actions_info(name,function_name,user,priority) values(?,?,?,?)";
  219. sqlite3_stmt *stmt;
  220. sqlite3_stmt *stmt1;
  221. sqlite3_prepare_v2(db, sql, -1, &stmt, nil);
  222. sqlite3_prepare_v2(db, sql1, -1, &stmt1, nil);
  223. // db.beginTransaction();
  224. for(int i=0;i<keys.count;i++)
  225. {
  226. NSString* func_name = keys[i];
  227. NSDictionary *objfun = [objfuncs objectForKey:func_name];
  228. int behavior, priority = 999;
  229. int show =1;
  230. NSDictionary *objbehavior = [objfun objectForKey:@"search"];
  231. NSArray* keysbehavior= [objbehavior allKeys];
  232. behavior = BEHAVIOR_SEARCH;
  233. for(int j=0;j<keysbehavior.count;j++)
  234. {
  235. NSString* field = keysbehavior[j];
  236. NSDictionary* field_info = [objbehavior objectForKey:field];
  237. NSString* field_name =[field_info valueForKey:@"name"] ;
  238. NSString* field_type = [field_info valueForKey:@"type"] ;
  239. NSString* alias_name = [field_info valueForKey:@"alias"] ;
  240. priority = [[field_info valueForKey:@"priority"] intValue];
  241. if(priority==999)
  242. show=0;
  243. else
  244. show=1;
  245. 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]];
  246. if(id>=0)
  247. [ApexMobileDB execSql:[NSString stringWithFormat:@"update fields_info set abandon = 0 where _id=%d",id] db:db];
  248. else
  249. {
  250. sqlite3_bind_text(stmt, 1, [field_name UTF8String], -1, NULL);
  251. sqlite3_bind_text(stmt, 2, [alias_name UTF8String], -1, NULL);
  252. sqlite3_bind_text(stmt, 3, [field_type UTF8String], -1, NULL);
  253. sqlite3_bind_text(stmt, 4, [func_name UTF8String], -1, NULL);
  254. sqlite3_bind_int(stmt, 5, behavior);
  255. sqlite3_bind_int(stmt, 6, priority);
  256. sqlite3_bind_int(stmt, 7, show);
  257. sqlite3_bind_text(stmt, 8, [user UTF8String], -1, NULL);
  258. if (sqlite3_step(stmt) != SQLITE_DONE)
  259. {
  260. fprintf(stderr, "Error: insert search failed, error infomation: %s\n", sqlite3_errmsg(db));
  261. }
  262. sqlite3_reset(stmt);
  263. }
  264. }
  265. objbehavior = [objfun objectForKey:@"result"];
  266. NSArray* keysresult= [objbehavior allKeys];
  267. behavior = BEHAVIOR_RESULT;
  268. for(int j=0;j<keysresult.count;j++)
  269. {
  270. NSString* field = keysresult[j];
  271. NSDictionary* field_info = [objbehavior objectForKey:field];
  272. NSString* field_name =[field_info valueForKey:@"name"] ;
  273. NSString* field_type = [field_info valueForKey:@"type"] ;
  274. NSString* alias_name = [field_info valueForKey:@"alias"] ;
  275. priority = [[field_info valueForKey:@"priority"] intValue];
  276. if(priority==999)
  277. show=0;
  278. else
  279. show=1;
  280. 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]];
  281. if(id>=0)
  282. [ApexMobileDB execSql:[NSString stringWithFormat:@"update fields_info set abandon = 0 where _id=%d",id] db:db];
  283. else
  284. {
  285. sqlite3_bind_text(stmt, 1, [field_name UTF8String], -1, NULL);
  286. sqlite3_bind_text(stmt, 2, [alias_name UTF8String], -1, NULL);
  287. sqlite3_bind_text(stmt, 3, [field_type UTF8String], -1, NULL);
  288. sqlite3_bind_text(stmt, 4, [func_name UTF8String], -1, NULL);
  289. sqlite3_bind_int(stmt, 5, behavior);
  290. sqlite3_bind_int(stmt, 6, priority);
  291. sqlite3_bind_int(stmt, 7, show);
  292. sqlite3_bind_text(stmt, 8, [user UTF8String], -1, NULL);
  293. if (sqlite3_step(stmt) != SQLITE_DONE)
  294. {
  295. fprintf(stderr, "Error: insert result failed, error infomation: %s\n", sqlite3_errmsg(db));
  296. }
  297. sqlite3_reset(stmt);
  298. }
  299. }
  300. objbehavior = [objfun objectForKey:@"actions"];
  301. NSArray* keysactions= [objbehavior allKeys];
  302. behavior = BEHAVIOR_SEARCH;
  303. for(int j=0;j<keysactions.count;j++)
  304. {
  305. NSString* actionname = keysactions[j];
  306. int action_priority = [[objbehavior valueForKey:actionname] intValue];
  307. int id = [ApexMobileDB get_recordid:db table:@"actions_info" where:[NSString stringWithFormat:@"name='%@' and function_name='%@' and user='%@'",actionname,func_name,user]];
  308. if(id>=0)
  309. [ApexMobileDB execSql:[NSString stringWithFormat:@"update actions_info set abandon = 0 , priority=%d where _id=%d",action_priority,id] db:db];
  310. else
  311. {
  312. sqlite3_bind_text(stmt1, 1, [actionname UTF8String], -1, NULL);
  313. sqlite3_bind_text(stmt1, 2, [func_name UTF8String], -1, NULL);
  314. sqlite3_bind_text(stmt1, 3, [user UTF8String], -1, NULL);
  315. sqlite3_bind_int(stmt1, 4, action_priority);
  316. if (sqlite3_step(stmt1) != SQLITE_DONE)
  317. {
  318. fprintf(stderr, "Error: insert action_info failed, error infomation: %s\n", sqlite3_errmsg(db));
  319. }
  320. sqlite3_reset(stmt1);
  321. }
  322. }
  323. }
  324. [ApexMobileDB execSql:@"delete from fields_info where abandon = 1" db:db];
  325. [ApexMobileDB execSql:@"delete from actions_info where abandon = 1" db:db];
  326. sqlite3_finalize(stmt);
  327. sqlite3_finalize(stmt1);
  328. sqlite3_close(db);
  329. [ApexMobileDB deleteResultFields];
  330. [ApexMobileDB updateResultDisplayFields];
  331. /*
  332. db.setTransactionSuccessful();
  333. db.endTransaction();
  334. */
  335. return RESULT_TRUE;
  336. }
  337. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  338. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  339. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  340. return RESULT_USERAUTH_ERROR;
  341. }
  342. +(DetailContent*) get_detailcontent: (NSMutableDictionary *) params
  343. {
  344. DebugLog(@"get_detailcontent");
  345. DetailContent * detailContent = [[DetailContent alloc] init];
  346. NSMutableArray* segments = [[NSMutableArray alloc] init];
  347. detailContent.segments = segments;
  348. if(![NetworkUtils IsNetworkAvailable])
  349. {
  350. detailContent.result_code = RESULT_NET_NOTAVAILABLE;
  351. return detailContent;
  352. }
  353. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  354. [params setValue:@"handset_search" forKey:@"action"];
  355. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  356. NSData* json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
  357. if (json==nil)
  358. {
  359. DebugLog(@"json is wrong");
  360. detailContent.result_code = RESULT_NET_ERROR;
  361. return detailContent;
  362. }
  363. //------------hack detail html 字体大小-----------
  364. NSString *str = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  365. str=[str stringByReplacingOccurrencesOfString:@"<table " withString:@"<table style=font-size:12px "];
  366. DebugLog(@"hack string: %@",str);
  367. //------- hack-----------
  368. NSDictionary *jsobj=[RAConvertor string2dict:str];
  369. NSError *error=nil;
  370. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  371. //
  372. //
  373. if(jsobj)
  374. {
  375. int result = [[jsobj valueForKey:@"result"] intValue];
  376. if(result== AP_SESSION_EXPIRED)
  377. {
  378. [self Authorize:appDelegate.user password:appDelegate.password];
  379. json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
  380. if (json==nil)
  381. {
  382. DebugLog(@"json is wrong");
  383. detailContent.result_code = RESULT_NET_ERROR;
  384. return detailContent;
  385. }
  386. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  387. result = [[jsobj valueForKey:@"result"] intValue];
  388. }
  389. if(result!=AP_USER_AUTH)
  390. {
  391. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  392. detailContent.result_code = result;
  393. return detailContent;
  394. }
  395. // if([params[@"action_type"] isEqualToString:@"Tracking"])
  396. // {
  397. // NSString *path = [[NSBundle mainBundle] pathForResource:@"fake_tracking.json" ofType:nil];
  398. // NSData *data = [[NSData alloc] initWithContentsOfFile:path];
  399. // NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  400. // jsobj = json;
  401. // }
  402. int count =[[jsobj valueForKey:@"count"] intValue];
  403. // if ([[params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
  404. // NSMutableDictionary *mJson = [jsobj mutableCopy];
  405. // NSDictionary *comm = @{
  406. // @"_name": @"Communication",
  407. // @"_type": @"communication",
  408. // @"cc": @"",
  409. // @"receipt": @"",
  410. // @"count": @2,
  411. // @"item0": @{
  412. // @"Sender": @"user name",
  413. // @"msg": @"content bla bla bla...",
  414. // @"mst_time": @"04/28/2018 20:15:33",
  415. // @"email_url": @"https://www.baidu.com"
  416. // },
  417. // @"item1": @{
  418. // @"Sender": @"user name",
  419. // @"msg": @"content bla bla bla...",
  420. // @"mst_time": @"04/28/2018 20:15:33"
  421. // }
  422. // };
  423. // [mJson setObject:comm forKey:[NSString stringWithFormat:@"group%d",count]];
  424. //
  425. // [mJson setObject:@(++count) forKey:@"count"];
  426. //
  427. // jsobj = mJson;
  428. // }
  429. detailContent.result_code = RESULT_TRUE;
  430. if(count==0)
  431. {
  432. return detailContent;
  433. }
  434. for(int i=0;i<count;i++)
  435. {
  436. NSDictionary* segment = [jsobj objectForKey:[NSString stringWithFormat:@"group%d",i]];
  437. [segments addObject:segment];
  438. /*
  439. JSONObject groupobj = jsonObj.getJSONObject("group" + i);
  440. View v = inflater.inflate(R.layout.group_tag, null);
  441. v.setOnClickListener(this);
  442. TextView tvgroup = (TextView) v.findViewById(R.id.tv_group);
  443. String group_name = groupobj.getString("_name");
  444. tvgroup.setText(group_name);
  445. v.setId(commonUtil.generateViewId());
  446. ll_root.addView(v);
  447. String grouptype = groupobj.getString("_type");
  448. */
  449. }
  450. // NSDictionary* objrecords = [jsobj objectForKey:@"records"];
  451. detailContent.originContent = jsobj;
  452. return detailContent;
  453. }
  454. return nil;
  455. }
  456. +(PageData*) get_pagedata: (NSMutableDictionary *) params
  457. {
  458. DebugLog(@"get_pagedata");
  459. if(![NetworkUtils IsNetworkAvailable])
  460. return nil;
  461. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  462. [params setValue:@"handset_search" forKey:@"action"];
  463. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  464. NSData* json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
  465. if (json==nil)
  466. {
  467. DebugLog(@"json is wrong");
  468. return nil;
  469. }
  470. NSError *error=nil;
  471. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  472. if(jsobj)
  473. {
  474. int result = [[jsobj valueForKey:@"result"] intValue];
  475. if(result== AP_SESSION_EXPIRED)
  476. {
  477. [self Authorize:appDelegate.user password:appDelegate.password];
  478. json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
  479. if (json==nil)
  480. {
  481. DebugLog(@"json is wrong");
  482. return nil;
  483. }
  484. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  485. result = [[jsobj valueForKey:@"result"] intValue];
  486. }
  487. if(result!=AP_USER_AUTH)
  488. {
  489. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  490. return nil;
  491. }
  492. NSDictionary* objrecords = [jsobj objectForKey:@"records"];
  493. PageData * pageData = [[PageData alloc] initWithRecords:objrecords];
  494. return pageData;
  495. }
  496. return nil;
  497. }
  498. +(int) get_recordcount: (NSMutableDictionary *) params// delegate:(id < NSURLConnectionDelegate >)delegate
  499. {
  500. DebugLog(@"get_recordcount");
  501. if(![NetworkUtils IsNetworkAvailable])
  502. return RESULT_NET_NOTAVAILABLE;
  503. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  504. [params setValue:@"handset_search_count" forKey:@"action"];
  505. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  506. NSData* json=[self get_json:URL_REQUEST_COUNT parameters:params file:nil];
  507. if (json==nil)
  508. {
  509. DebugLog(@"json is wrong");
  510. return RESULT_NET_ERROR;
  511. }
  512. NSError *error=nil;
  513. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  514. if(jsobj)
  515. {
  516. int result = [[jsobj valueForKey:@"result"] intValue];
  517. if(result== AP_SESSION_EXPIRED)
  518. {
  519. [self Authorize:appDelegate.user password:appDelegate.password];
  520. json=[self get_json:URL_REQUEST_COUNT parameters:params file:nil];
  521. if (json==nil)
  522. {
  523. DebugLog(@"json is wrong");
  524. return RESULT_NET_ERROR;
  525. }
  526. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  527. result = [[jsobj valueForKey:@"result"] intValue];
  528. }
  529. if(result!=AP_USER_AUTH)
  530. {
  531. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  532. return RESULT_USERAUTH_ERROR;
  533. }
  534. else
  535. return [[jsobj valueForKey:@"count" ] intValue];
  536. }
  537. return RESULT_ERROR;
  538. }
  539. //+(bool) IsHostAvailable : (NSString*) url
  540. //{
  541. // Reachability *r = [Reachability reachabilityWithHostName:url];
  542. // int i = [r currentReachabilityStatus];
  543. // if ([r currentReachabilityStatus]==NotReachable)
  544. // return false;
  545. // return true;
  546. //}
  547. +(bool) IsNetworkAvailable
  548. {
  549. if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  550. ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  551. return false;
  552. return true;
  553. }
  554. +(void)post_without_return : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  555. {
  556. params = [self prepare_addtional_params:params];
  557. // [self get_json:url parameters:params file:nil err_recorder:nil result_handler:nil decrypt_handler:nil];
  558. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  559. //分界线的标识符
  560. NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  561. //根据url初始化request
  562. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  563. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  564. timeoutInterval:30];
  565. //分界线 --AaB03x
  566. NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  567. //结束符 AaB03x--
  568. NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  569. //要上传的图片
  570. // UIImage *image=[params objectForKey:@"pic"];
  571. //得到图片的data
  572. // NSData* data = UIImagePNGRepresentation(image);
  573. //http body的字符串
  574. NSMutableString *body=[[NSMutableString alloc]init];
  575. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  576. // [params setValue:@"handset_login" forKey:@"action"];
  577. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  578. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  579. // [params setValue:password forKey:@"password"];
  580. // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  581. // [headers setValue:headQuerlString forKey:@"param"];
  582. //参数的集合的所有key的集合
  583. NSArray *keys= [params allKeys];
  584. DebugLog(@"================parms==================");
  585. //遍历keys
  586. for(int i=0;i<[keys count];i++)
  587. {
  588. //得到当前key
  589. NSString *key=[keys objectAtIndex:i];
  590. //如果key不是pic,说明value是字符类型,比如name:Boris
  591. if(![key isEqualToString:@"pic"])
  592. {
  593. //添加分界线,换行
  594. [body appendFormat:@"%@\r\n",MPboundary];
  595. //添加字段名称,换2行
  596. [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  597. //添加字段的值
  598. [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  599. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  600. }
  601. }
  602. DebugLog(@"================parms==================");
  603. ////添加分界线,换行
  604. [body appendFormat:@"%@\r\n",MPboundary];
  605. //声明pic字段,文件名为boris.png
  606. [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  607. //声明上传文件的格式
  608. [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  609. //声明结束符:--AaB03x--
  610. NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  611. //声明myRequestData,用来放入http body
  612. NSMutableData *myRequestData=[NSMutableData data];
  613. //将body字符串转化为UTF8格式的二进制
  614. [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  615. //将image的data加入
  616. // [myRequestData appendData:data];
  617. //加入结束符--AaB03x--
  618. [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  619. //设置HTTPHeader中Content-Type的值
  620. NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  621. //设置HTTPHeader
  622. [request setValue:content forHTTPHeaderField:@"Content-Type"];
  623. //设置Content-Length
  624. [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  625. //设置http body
  626. [request setHTTPBody:myRequestData];
  627. //http method
  628. [request setHTTPMethod:@"POST"];
  629. // NSHTTPURLResponse* urlResponse = nil;
  630. //
  631. // NSError *error = [[NSError alloc] init];
  632. //
  633. [NSURLConnection sendAsynchronousRequest:request queue:nil completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){}];
  634. // NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:nil];
  635. }
  636. +(NSData*)get_marketnews : (NSString*) id limit: (int) limit
  637. {
  638. if(![NetworkUtils IsNetworkAvailable])
  639. return nil;//RESULT_NET_NOTAVAILABLE;
  640. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  641. [params setValue:@"Market News" forKey:@"module_name"];
  642. [params setValue:@"search" forKey:@"action_type"];
  643. [params setValue:id forKey:@"id"];
  644. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  645. NSData* json=[self get_json:URL_ANNOUNCEMENTS parameters:params file:nil];
  646. if (json==nil)
  647. {
  648. DebugLog(@"json is wrong");
  649. return nil;
  650. }
  651. return json;
  652. }
  653. +(NSData*)get_MessageDetail: (int) offset limit:(int) limit from:(NSString*) sid to:(NSString*) eid
  654. {
  655. if(![NetworkUtils IsNetworkAvailable])
  656. return nil;//RESULT_NET_NOTAVAILABLE;
  657. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  658. // NSString* sess
  659. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  660. [params setValue:@"Pull Message" forKey:@"module_name"];
  661. [params setValue:@"handset_search" forKey:@"action"];
  662. [params setValue:sid forKey:@"s_id"];
  663. [params setValue:eid forKey:@"e_id"];
  664. [params setValue:@"detail" forKey:@"action_type"];
  665. [params setValue:@"handset_search" forKey:@"action"];
  666. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  667. [params setValue:appDelegate.duid forKey:@"uuid"];
  668. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  669. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  670. // [params setValue:@"20" forKey:@"limit"];
  671. NSData* json=[self get_json:URL_PUSH parameters:params file:nil];
  672. if (json==nil)
  673. {
  674. DebugLog(@"json is wrong");
  675. return nil;
  676. }
  677. NSError *error=nil;
  678. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  679. int result = [[jsobj valueForKey:@"result" ] intValue] ;
  680. if(result== AP_SESSION_EXPIRED)
  681. {
  682. [self Authorize:appDelegate.user password:appDelegate.password];
  683. json=[self get_json:URL_PUSH parameters:params file:nil];
  684. if (json==nil)
  685. {
  686. DebugLog(@"json is wrong");
  687. return nil;
  688. }
  689. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  690. result = [[jsobj valueForKey:@"result"] intValue];
  691. }
  692. if(result!= AP_MESSAGE_NEW)
  693. return nil;
  694. return json;
  695. }
  696. +(int) delAllMessage:(NSString*) before
  697. {
  698. if(![NetworkUtils IsNetworkAvailable])
  699. return RESULT_NET_NOTAVAILABLE;//RESULT_NET_NOTAVAILABLE;
  700. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  701. // NSString* sess
  702. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  703. [params setValue:@"Pull Message" forKey:@"module_name"];
  704. [params setValue:@"read_all" forKey:@"action_type"];
  705. [params setValue:@"handset_search" forKey:@"action"];
  706. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  707. [params setValue:appDelegate.duid forKey:@"uuid"];
  708. [params setValue:before forKey:@"id"];
  709. NSData* json=[self get_json:URL_PUSH parameters:params file:nil];
  710. if (json==nil)
  711. {
  712. DebugLog(@"json is wrong");
  713. return RESULT_NET_ERROR;
  714. }
  715. NSError *error=nil;
  716. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  717. int result = [[jsobj valueForKey:@"result" ] intValue] ;
  718. if(result== AP_SESSION_EXPIRED)
  719. {
  720. [self Authorize:appDelegate.user password:appDelegate.password];
  721. json=[self get_json:URL_PUSH parameters:params file:nil];
  722. if (json==nil)
  723. {
  724. DebugLog(@"json is wrong");
  725. return RESULT_NET_ERROR;
  726. }
  727. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  728. result = [[jsobj valueForKey:@"result"] intValue];
  729. }
  730. return result;
  731. }
  732. +(NSData*)pull_message: (int) offset
  733. {
  734. if(![NetworkUtils IsNetworkAvailable])
  735. return nil;//RESULT_NET_NOTAVAILABLE;
  736. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  737. // NSString* sess
  738. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  739. [params setValue:@"Pull Message" forKey:@"module_name"];
  740. [params setValue:@"ios_list" forKey:@"action_type"];
  741. [params setValue:@"handset_search" forKey:@"action"];
  742. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  743. [params setValue:appDelegate.duid forKey:@"uuid"];
  744. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  745. [params setValue:@"20" forKey:@"limit"];
  746. NSData* json=[self get_json:URL_PUSH parameters:params file:nil];
  747. if (json==nil)
  748. {
  749. DebugLog(@"json is wrong");
  750. return nil;
  751. }
  752. NSError *error=nil;
  753. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  754. int result = [[jsobj valueForKey:@"result" ] intValue] ;
  755. if(result== AP_SESSION_EXPIRED)
  756. {
  757. [self Authorize:appDelegate.user password:appDelegate.password];
  758. json=[self get_json:URL_PUSH parameters:params file:nil];
  759. if (json==nil)
  760. {
  761. DebugLog(@"json is wrong");
  762. return nil;
  763. }
  764. jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  765. result = [[jsobj valueForKey:@"result"] intValue];
  766. }
  767. if(result!= AP_MESSAGE_NEW)
  768. return nil;
  769. return json;
  770. }
  771. +(NSDictionary*) RequestServiceLocation
  772. {
  773. if(![NetworkUtils IsNetworkAvailable])
  774. return false;//RESULT_NET_NOTAVAILABLE;
  775. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  776. [params setValue:@"Location" forKey:@"module_name"];
  777. [params setValue:@"search" forKey:@"action_type"];
  778. [params setValue:@"999" forKey:@"limit"];
  779. NSData* json=[self get_json:URL_LOCATIONS parameters:params file:nil];
  780. if (json==nil)
  781. {
  782. return @{
  783. @"result" : @RESULT_NET_ERROR,
  784. @"err_msg" : MSG_NET_ERROR
  785. };
  786. }
  787. NSError *error=nil;
  788. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  789. NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:@"service_location.json"];
  790. if(jsobj!=nil&&[jsobj[@"result"] intValue]!=RESULT_NET_ERROR&&[jsobj[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
  791. {
  792. [jsobj writeToFile:path atomically:YES];
  793. // return ret;
  794. }
  795. return jsobj;
  796. }
  797. +(bool) UpdateServiceLocation
  798. {
  799. if(![NetworkUtils IsNetworkAvailable])
  800. return false;//RESULT_NET_NOTAVAILABLE;
  801. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  802. [params setValue:@"Location" forKey:@"module_name"];
  803. [params setValue:@"search" forKey:@"action_type"];
  804. [params setValue:@"999" forKey:@"limit"];
  805. NSData* json=[self get_json:URL_LOCATIONS parameters:params file:nil];
  806. if (json==nil)
  807. return false;
  808. NSError *error=nil;
  809. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  810. NSString* remote_ver = [jsobj valueForKey:@"version"] ;
  811. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  812. NSString *local_ver =[defaults stringForKey:@"location_ver"];
  813. int total = [[jsobj valueForKey:@"total"] intValue];
  814. BOOL bigger = [remote_ver compare:local_ver];
  815. // if(!bigger)
  816. // return false;
  817. sqlite3 *db =[ApexMobileDB get_db];
  818. [ApexMobileDB execSql:@"delete from locations" db:db];
  819. char* sql = "insert into locations(area,company,city,longitude,latitude,address,telephone,fax,contact,email) values(?,?,?,?,?,?,?,?,?,?)";
  820. sqlite3_stmt *stmt;
  821. sqlite3_prepare_v2(db, sql, -1, &stmt, nil);
  822. NSDictionary* objrecords = [jsobj objectForKey:@"records"];
  823. for(int i=0;i<total;i++)
  824. {
  825. NSDictionary* objlocation = [objrecords objectForKey:[NSString stringWithFormat:@"record%d",i]];
  826. NSString* area = [objlocation valueForKey:@"area"];
  827. NSString* company = [objlocation valueForKey:@"company"];
  828. NSString* city = [objlocation valueForKey:@"city"];
  829. NSString* longitude = [objlocation valueForKey:@"longitude"] ;
  830. NSString* latitude = [objlocation valueForKey:@"latitude"] ;
  831. NSString* address = [objlocation valueForKey:@"address"];
  832. NSString* telephone = [objlocation valueForKey:@"telephone"];
  833. NSString* fax = [objlocation valueForKey:@"fax"];
  834. NSString* contact = [objlocation valueForKey:@"contact"];
  835. NSString* email = [objlocation valueForKey:@"email"];
  836. if([area isEqual:[NSNull null]])
  837. area=@"";
  838. if(area==nil)
  839. area=@"";
  840. if([area isEqualToString:@"null"])
  841. area=@"";
  842. if([company isEqual:[NSNull null]])
  843. company=@"";
  844. if(company==nil)
  845. company=@"";
  846. if([company isEqualToString:@"null"])
  847. company=@"";
  848. if([city isEqual:[NSNull null]])
  849. city=@"";
  850. if(city==nil)
  851. city=@"";
  852. if([city isEqualToString:@"null"])
  853. city=@"";
  854. if([longitude isEqual:[NSNull null]])
  855. longitude=@"";
  856. if(longitude==nil)
  857. longitude=@"";
  858. if([longitude isEqualToString:@"null"])
  859. longitude=@"";
  860. if([latitude isEqual:[NSNull null]])
  861. latitude=@"";
  862. if(latitude==nil)
  863. latitude=@"";
  864. if([latitude isEqualToString:@"null"])
  865. latitude=@"";
  866. if([address isEqual:[NSNull null]])
  867. address=@"";
  868. if(address==nil)
  869. address=@"";
  870. if([address isEqualToString:@"null"])
  871. address=@"";
  872. if([telephone isEqual:[NSNull null]])
  873. telephone=@"";
  874. if(telephone==nil)
  875. telephone=@"";
  876. if([telephone isEqualToString:@"null"])
  877. telephone=@"";
  878. if([fax isEqual:[NSNull null]])
  879. fax=@"";
  880. if(fax==nil)
  881. fax=@"";
  882. if([fax isEqualToString:@"null"])
  883. fax=@"";
  884. if([contact isEqual:[NSNull null]])
  885. contact=@"";
  886. if(contact==nil)
  887. contact=@"";
  888. if([contact isEqualToString:@"null"])
  889. contact=@"";
  890. if([email isEqual:[NSNull null]])
  891. email=@"";
  892. if(email==nil)
  893. email=@"";
  894. if([email isEqualToString:@"null"])
  895. email=@"";
  896. sqlite3_bind_text(stmt, 1, [area UTF8String], -1, NULL);
  897. sqlite3_bind_text(stmt, 2, [company UTF8String], -1, NULL);
  898. sqlite3_bind_text(stmt, 3, [city UTF8String], -1, NULL);
  899. sqlite3_bind_text(stmt, 4, [longitude UTF8String], -1, NULL);
  900. sqlite3_bind_text(stmt, 5, [latitude UTF8String], -1, NULL);
  901. sqlite3_bind_text(stmt, 6, [address UTF8String], -1, NULL);
  902. sqlite3_bind_text(stmt, 7, [telephone UTF8String], -1, NULL);
  903. sqlite3_bind_text(stmt, 8, [fax UTF8String], -1, NULL);
  904. sqlite3_bind_text(stmt, 9, [contact UTF8String], -1, NULL);
  905. sqlite3_bind_text(stmt, 10, [email UTF8String], -1, NULL);
  906. if (sqlite3_step(stmt) != SQLITE_DONE)
  907. {
  908. fprintf(stderr, "Error: insert search failed, error infomation: %s\nsql:%s\n", sqlite3_errmsg(db),sqlite3_sql(stmt));
  909. }
  910. sqlite3_reset(stmt);
  911. }
  912. sqlite3_finalize(stmt);
  913. sqlite3_close(db);
  914. [defaults removeObjectForKey:@"location_ver"];
  915. [defaults setValue:remote_ver forKey:@"location_ver"];
  916. // [defaults synchronize];
  917. return true;
  918. }
  919. //+(void) testmail1:(UIViewController*) caller
  920. //{
  921. // MFMailComposeViewController *mail=[[MFMailComposeViewController alloc] init];
  922. // mail.mailComposeDelegate=caller;
  923. //
  924. // //设置主题
  925. // [mail setSubject:@"测试发送电子邮件"];
  926. //
  927. // //添加收件人
  928. // NSArray *toRecipients=[NSArray arrayWithObject:@"admin@163.com"];
  929. // [mail setToRecipients:toRecipients];
  930. // //添加抄送;
  931. // NSArray *ccRecipients=[NSArray arrayWithObjects:@"test1@163.com",@"test@qq.com", nil];
  932. // [mail setCcRecipients:ccRecipients];
  933. // //添加密送
  934. // NSArray *bccRecipients=[NSArray arrayWithObject:@"admin@gmail.com"];
  935. // [mail setBccRecipients:bccRecipients];
  936. //
  937. //
  938. // //添加一张图片
  939. // UIImage *addPic=[UIImage imageNamed:@"bg_3"];
  940. // NSData *imageData=UIImagePNGRepresentation(addPic);
  941. // [mail addAttachmentData:imageData mimeType:@"image/png" fileName:@"icon"];
  942. //
  943. // //添加一个xml附件
  944. //// NSString *file=[self fullBundlePathFromRelativePath:@"model.xml"];
  945. //// NSData *xmldata=[NSData dataWithContentsOfFile:file];
  946. //// [mail addAttachmentData:xmldata mimeType:@"" fileName:@"model"];
  947. //
  948. // NSString *emailBody=@"<font color='red'>send test email</font>";
  949. // [mail setMessageBody:emailBody isHTML:YES];
  950. // [caller presentViewController:mail animated:YES completion:nil];
  951. //
  952. //
  953. //}
  954. //+(void) testmail
  955. //{
  956. // NSMutableString *buffer=
  957. // [NSMutableString stringWithString:
  958. // @"<HTML><HEAD><TITLE>PAGE</TITLE></HEAD><BODY>example<img src=\"data:image/png;base64,\/9j\/4AAQSkZJRgABAQAAAQABAAD\/\/gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK\/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy\/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy\/8AAEQgAZABkAwEiAAIRAQMRAf\/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC\/\/EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29\/j5+v\/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC\/\/EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29\/j5+v\/aAAwDAQACEQMRAD8A9JK81JGKQ9acnWkxonjXpV+2TJFU4x0q9AcVIy6yDZXNeI9WGi2qz\/ZZrlnfascQyfc\/SukLfLXD+K7bVrvVIfseovaW0ajcqMFLknnkn0q6cOd8rdgUlFptXXYn8L+JLfxJHO0ULwvC4Vo3IJweh\/n+VdWigJXm3hrR7vSfF891E0QsbnKlGmDPzyD78\/zr0lT8tZq+zOjFRpKd6T0aT9PIqXKcms+QVpzc1nyjmrOYxpByeahYVM7DcR3qFjTIOs8JjGly\/wDXc\/8AoK0UeEiTpc2R0nOP++VooKRkE81Wv9VstJtGu76dIYV4LN3PoPU1M5wa5Dxxpj6hFp0u\/wDdW85Z1IyDkYB\/P+dKTsrjirux0mleMNC1YSfZNQjbyl3vvBTC+vzAcVrQ6\/pnkCZbtGj9V5\/SvGbmGO3ltGd44ljmVQY0wTknH610+jTPqniFrLzHMk2nSrISQdgyAh49yfzrJTu7G06Timd2njPSHG7zJ1izgStCwRj7HFM1HxJo9qHa5nUeXk\/dJPGenr9015vJBJltLMgWfmLaW+62MfkOtZC28niq7uNVvpNw3GONUOBwOO\/FCn3G6F2kmem6Z4utb29EMunz2oYFopHKsGwM\/wAJODjPFbNz4l0qxjY3V2kRBUYbgnPp615r4EjkfVZLd5I1ksiUDYB3e2e\/BP5Ve8RpNba7PLMwbzFQLhf4Qv8AiGpqTtdk+zTnyo6PVPGEBSJNNlieSVPMEkgJQLxjgdc5qHw54im1pbiG6t1juLfbuaPOxwc4Iz06HiuCvdZj05Es2zHudiJslcqwBK9MdQT16mo7DxxcQWd1aWMUbysQiXBYkgkYB98UOdnd7FRoOatHc9NuLS4gj8ySPCE8HI71nyPiuMtYb8app80F5ezP5qrcLLMWDKT83BP1Nd29pj+HP41akpbHPODg7M6jwe27SZj\/ANNz\/wCgrRVfwIMaNc8k\/wClv17fKtFUCOV8Ua7H4e0mS+dPMYELGmcbmPQV5FqHxE1fUX2XCxLb5yIogVBPbJ5Ndr8UHiks7K3lkChpGcDdjOBj+teYDTN+7bMNvUEina6DXdG5aeLLWa8i\/tCCZogoY7cEq4PUev416\/4aisII5dQt5Gea8hAikYABV6jH418\/vpkiDcsiE\/lXr3gqWX\/hDrFXOZFZl65wAxIH60o043G6knuYHivWDN4km0q1AWRYiZZx94ueQPyP61V0CNtN0u6imuU8zdvRHHQkf54rmreV77xlqEwYndLI3JxkFuBXQPbIWAj3guueud2O\/wCPFZVEm7GlKbjqT+DrN7jWdl5eGJ7h2cBDlmYcn6Hmu68VReXa2sgbcwlSBWmYk4Y45I+ufwrzKyuntPFmmLkK6SM2AeBkYx+leheObjGhWDZwWvYyfwBNdVGCcNUYTm1K6Haz4KtNU01kila3uVAKkDKsR69\/xzXmen+GNTnknlDxxpDIyhXGSWHoO3Ne43LiMrzwTXETMLPVJ4snDSM2Pcnd\/WnVhZXRm6jSM+z1O7triJ4IJRKjZzIm1R9fXr2r0bSdXg1fKeWY5lGSucg\/SuHbbI+4g1f8N3K2+sxPK6omWBJOBjBrBK2xPtZSep6P4LXbpV0P+nt\/5LRUvhJdumXB7NcuwPqCBRTN1seI\/GFP3OmP6NIM\/gv+FeULNIBtEjgZ7GvavinYNdeHBMgy1tKHP+6eD\/MV4ntY5wrEewphexIs8+cLK+f96up8PeNb\/Q7MWiRJcQmUyEyZ3DIAIBz7Vy0EcomRvJdwD0x1FeyaJ4R0l9Kt5ZzFK80YZZADgZ9vXtUyk1sa04Opoeb6G7f2ld4B3SfOPpknNbl7JN5aoJFDysqbh0Xnn8hSS6TBZ3GqXkDlmtd6xrjA2jOc+9ZWj6jd3+sWULKih5lCsVPHPSo1k9BuPJZM6m78P6Vpemxajbzn7VERKMvkkjnB+tP8UeKNN1nRbJbK6EkiTh3jIIZcAjODW34gt7mHQrt7pVhiZQhbA4JOBj868vkjjjJAKN2DDoa0oSlFNMWIhFNWPR9WD+NL66htNWaC3hwkJRvkd9uSTjr1xWRo1te2dxNZajIzSqoeF2OQy9Dg96PAFzMqXlpGCImdX3Ljg+mP89K1tb1GIa6qXUohaOIbC5wHz156VLm3OzJqU4+x5upZHTNLpys97tjbY244YnGOKrxTLIuVkVh2IOan0y8W0u2m278E8Zx2xWii5NJdThS6nrfhAsdJlDuXKzkbic5+VaKj8F3gvtGlkEezbOVxuzn5VOf1oolFxfKzqg04po5HXbVb3Trq2YZEsTJ+YryF7exsIyLZcqv3juJyfxr2e9yEYjqBxXhV5dOYTATwXLP65oSuyuZJNWM+5kuXLyBiqknB\/pXoPgzVIh4Wmt5JcT2kRkG4\/wAB54+h\/nXHWTw3NqIBPtl8xhsblWyOtQR5SORMnkBTg9eacoXQoVHB3RH9svFtLqOGUyRE\/vARnaCcZz+NMsZZLW\/tLggjbIrqfof\/AK1UJhsuVUNwQGPPHrWroFot7r1hayfdlnRWz6Z5qoJK5LbbSO6+KWqNvs9LjPbz5Mfkv9a83kDQgqzAlTzg5GfrXo\/xZsVS+sL5RgyRmJv+AnI\/9CNebuD5Uhx1FNK6KrN8+pe07U73SrgXFlOYpCMEgAgj3B4qG\/v7m\/nNxdzPLIeNzGo0O6IH2qK44jIrOy3Fd2sRXCPtEsbFSPvbTivQPDcbx6NbvISXdd3Pp2\/TFcbPaNZtBG8qSmWBJjt7bh0PvXovh6zl1PRIJ4NmFHllc9CvH+FdeEdNT5p\/Iwrc\/LaJ6t8Nm3eHbj\/r7b\/0BKKk+HlrLaaDcxzLhvtbEc9tiUVhiGnVk0a0laCTOc1m7SysJrmQ8Ivp37frXmWi6BYazNNDeXkkVy+SiKAAffJ6\/Su58ZzhNAn9crx\/wIV4\/rOoyRzwvCxjkU7wyHBB7Vk02tDVNJ6q5eutG1LwxfPDcQ+Zb5YpJ\/Cw\/Hv7VnbsRZJ5JGQPpXX6D42Go2g0\/XLeO7t3G3zSPmX6jvV3WdJ0K2sntILQb2+ZZQ5z1\/hPOcccHsaSm1o0VKnGS5os880+7s4dVja8haWPymQKuOteh+DY\/DUdnFPuH9ogjcbgjcG\/2P6Y5rza4spLbVvszMGBQspA981oWfmwTJKuQ8bBh9RVxgptq+pmqjp2dro9c1XSP+EwsDaTSiAxN5kTkZPTGD+deOX0M0Tz2cMDyyxk+Z5alggBwT9K7mfxY40dtu6KVVIMiH25xXOeDWD6vcyyyHAhPB\/jBI\/TpS9+nD3tzWfs6tRcpz0LZhX8qnXTr6+2ra2c828HBRCQccmkvUihvX8lWEDNuUH+Een4dK71PGLQWypp9rbRpGoCb1JIx34NGr2RlaKvzM4VryS6dBMf3kaLEFIwQAMAYr0jQLFdN02ONpZFmPzOUkK8ntwa85xJq\/ioTXDqJJJ9zkLwTnPT8K9NikDkAn8jXPWk1aKKppPU9T+H7l9DuSXd\/wDSmGXbJ+4lFN+HgxoNxj\/n6b\/0BKK0hrFBLc848cMTo\/X\/AJar\/WvINYUCBJOd27FFFadCB+h\/dkP0rojeXDWwVpWYIMKCelFFUgMmYB74SsMsIyM\/jVyNR5WaKKuh8ciavwoiRt0e1sFfQ0+5jSFFlhXynX5cpxkHtRRUYn+KiqP8NlcH5g55ZSGBPPNNnmeS6kkOAXbJAHHNFFEt0Zr4TR0yxhN\/b3Q3B+SQDwSK61X\/ANlee+KKK4qmrOuGx6r8N\/8AkXrn\/r7b\/wBASiiit4fCjN7n\/9k=\" /></BODY></HTML>"];
  959. // NSString* subjectLine =@"Example HTML formatted EMAIL with Image";
  960. //
  961. // NSString *str1 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorSystemDefault, (CFStringRef) subjectLine, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8));
  962. // NSString *str2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorSystemDefault, (CFStringRef)buffer, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8));
  963. //
  964. // NSString *urlString = [NSString stringWithFormat:@"mailto:?subject=%@&body=%@",str1 ,str2 ];
  965. //
  966. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
  967. //
  968. //// [NSURL URLWithString:urlString];
  969. //}
  970. +(NSData*)get_announcements : (NSString*) id limit: (int) limit
  971. {
  972. if(![NetworkUtils IsNetworkAvailable])
  973. return nil;//RESULT_NET_NOTAVAILABLE;
  974. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  975. [params setValue:@"Announcements" forKey:@"module_name"];
  976. [params setValue:@"search" forKey:@"action_type"];
  977. [params setValue:id forKey:@"id"];
  978. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  979. NSData* json=[self get_json:URL_ANNOUNCEMENTS parameters:params file:nil];
  980. if (json==nil)
  981. {
  982. DebugLog(@"json is wrong");
  983. return nil;
  984. }
  985. return json;
  986. }
  987. +(void)Logout
  988. {
  989. if(![NetworkUtils IsNetworkAvailable])
  990. return ;//RESULT_NET_NOTAVAILABLE;
  991. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  992. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  993. if(appDelegate.duid !=nil)
  994. [params setValue:appDelegate.duid forKey:@"udid"];
  995. [params setValue:@"handset_logout" forKey:@"action"];
  996. [self post_without_return :URL_UPDATE_AUTH parameters:params];
  997. }
  998. +(int)Authorize : (NSString*) user password:(NSString*) password{
  999. if(![NetworkUtils IsNetworkAvailable])
  1000. return RESULT_NET_NOTAVAILABLE;
  1001. // if(![RANetwork IsHostAvailable:URL_UPDATE_AUTH])
  1002. // return RESULT_NET_ERROR;
  1003. __block long ver = 0;
  1004. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1005. dispatch_async(dispatch_get_main_queue(), ^{
  1006. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1007. ver = appDelegate.authVer;
  1008. if(appDelegate.duid !=nil)
  1009. [params setValue:appDelegate.duid forKey:@"udid"];
  1010. });
  1011. [params setValue:@"handset_login" forKey:@"action"];
  1012. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  1013. [params setValue:user forKey:@"user"];
  1014. [params setValue:password forKey:@"password"];
  1015. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  1016. #ifdef TEST
  1017. [params setValue:@"true" forKey:@"is_debug"];
  1018. #else
  1019. [params setValue:@"false" forKey:@"is_debug"];
  1020. #endif
  1021. NSData* json=[self get_json:URL_UPDATE_AUTH parameters:params file:nil];
  1022. if(json==nil)
  1023. return RESULT_NET_ERROR;
  1024. int ret = [self parse_authinfo:json user:user password:password];
  1025. DebugLog(@"parse_authinfo return %d ",ret);
  1026. return ret;
  1027. }
  1028. + (NSDictionary *)collectErrMsg:(NSString *)errMsg DeviceInfo:(NSString *)deviceInfo Time:(NSString *)time {
  1029. NSMutableDictionary *params = [@{
  1030. @"device_info" : deviceInfo == nil ? @"" : deviceInfo,
  1031. @"crash_info" : errMsg == nil ? @"" : errMsg,
  1032. @"crash_time" : time == nil ? @"" : time
  1033. } mutableCopy];
  1034. NSData* json=[self get_json:URL_ERR_LOG parameters:params file:nil];
  1035. if (json==nil)
  1036. {
  1037. return @{
  1038. @"result" : @RESULT_NET_ERROR,
  1039. @"err_msg" : MSG_NET_ERROR
  1040. };
  1041. }
  1042. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1043. return resultDic;
  1044. }
  1045. + (NSDictionary *)requestHome {
  1046. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  1047. // action=hand_new_home_list
  1048. [params setObject:@"hand_new_home_list" forKey:@"action"];
  1049. [params setObject:@(YES) forKey:@"request_location"];
  1050. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1051. if(appDelegate.personalmode)
  1052. params[@"personal_mode"] = @"true";
  1053. else
  1054. params[@"personal_mode"] = @"false";
  1055. NSData* json=[self get_json:URL_HOME parameters:params file:nil];
  1056. if (json==nil)
  1057. {
  1058. return @{
  1059. @"result" : @RESULT_NET_ERROR,
  1060. @"err_msg" : MSG_NET_ERROR
  1061. };
  1062. }
  1063. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1064. return resultDic;
  1065. }
  1066. + (NSDictionary *)search:(NSMutableDictionary *)params {
  1067. [params setObject:@"handset_search" forKey:@"action"];
  1068. NSData* json=[self get_json:URL_REQUEST_COUNT parameters:params file:nil];
  1069. if (json==nil)
  1070. {
  1071. return @{
  1072. @"result" : @RESULT_NET_ERROR,
  1073. @"err_msg" : MSG_NET_ERROR
  1074. };
  1075. }
  1076. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1077. return resultDic;
  1078. }
  1079. + (NSDictionary *)requestOrderHistory:(NSMutableDictionary *)params {
  1080. [params setObject:@"hand_new_home_list_all" forKey:@"action"];
  1081. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1082. if(appDelegate.personalmode)
  1083. params[@"personal_mode"] = @"true";
  1084. else
  1085. params[@"personal_mode"] = @"false";
  1086. NSData* json=[self get_json:URL_HISTORY parameters:params file:nil];
  1087. if (json==nil)
  1088. {
  1089. return @{
  1090. @"result" : @RESULT_NET_ERROR,
  1091. @"err_msg" : MSG_NET_ERROR
  1092. };
  1093. }
  1094. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1095. return resultDic;
  1096. }
  1097. + (void)download_file:(NSMutableDictionary *)params url:(NSString *)url toCachePath:(NSString *)path progressHandler:(progressHandler)progressHandler completionHandler:(resultHandler)result {
  1098. params = [self prepare_addtional_params:params];
  1099. [NetworkUtils downloadFileOffset:0 Param:params from:url method:@"POST" toPath:path progressHandler:progressHandler completionHandler:result];
  1100. }
  1101. + (NSDictionary *)requestKPI {
  1102. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  1103. [params setObject:@"hand_new_kpi" forKey:@"action"];
  1104. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1105. if(appDelegate.personalmode)
  1106. params[@"personal_mode"] = @"true";
  1107. else
  1108. params[@"personal_mode"] = @"false";
  1109. NSData* json=[self get_json:URL_KPI parameters:params file:nil];
  1110. if (json==nil)
  1111. {
  1112. return @{
  1113. @"result" : @RESULT_NET_ERROR,
  1114. @"err_msg" : MSG_NET_ERROR
  1115. };
  1116. }
  1117. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1118. return resultDic;
  1119. }
  1120. + (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc SerialNo:(NSString *)serialNo {
  1121. if (!email) {
  1122. email = @"";
  1123. }
  1124. if (!serialNo) {
  1125. serialNo = @"";
  1126. }
  1127. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  1128. [params setObject:@"handset_search" forKey:@"action"];
  1129. [params setObject:@"save_communication_email" forKey:@"action_type"];
  1130. [params setObject:serialNo forKey:@"serial_no"];
  1131. [params setObject:email forKey:@"msg"];
  1132. if (cc) {
  1133. [params setObject:cc forKey:@"cc"];
  1134. }
  1135. NSData* json=[self get_json:URL_SEND_COMM_EMAIL parameters:params file:nil];
  1136. if (json==nil)
  1137. {
  1138. return @{
  1139. @"result" : @RESULT_NET_ERROR,
  1140. @"err_msg" : MSG_NET_ERROR
  1141. };
  1142. }
  1143. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1144. return resultDic;
  1145. }
  1146. + (NSDictionary *)uploadUserSql:(NSString *)sql {
  1147. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  1148. [params setObject:@"handset_search" forKey:@"action"];
  1149. [params setValue:sql forKey:@"sql"];
  1150. NSData* json=[self get_json:URL_UPLOAD_SQL parameters:params file:nil];
  1151. if (json==nil)
  1152. {
  1153. return @{
  1154. @"result" : @RESULT_NET_ERROR,
  1155. @"err_msg" : MSG_NET_ERROR
  1156. };
  1157. }
  1158. NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
  1159. return resultDic;
  1160. }
  1161. + (NSDictionary *)mockResult:(NSDictionary *)params {
  1162. sleep(2);
  1163. // Booking : module_name = Ocean Booking
  1164. NSDictionary *item_booking = @{
  1165. @"type": @0,
  1166. @"title":@"FU YAMA TRADing", // Consignee
  1167. @"date":@"03/28/2019 - 04/24/2019", // M.V ETD - M.V ETA
  1168. @"port":@"CNYTN - USLAX", // pol pod
  1169. @"desc":@"B61180700423", // Booking#
  1170. @"detail":@"HUNG TA GARDEN ENTERPRISE CO., LTD", // Shipper
  1171. @"consignee": @"Martin Jane",
  1172. @"addition":@[
  1173. @{
  1174. @"name":@"Carrier Booking#",
  1175. @"value":@"NAM1774822"
  1176. },
  1177. @{
  1178. @"name":@"Consignee",
  1179. @"value":@"FU YAMA TRADing"
  1180. },
  1181. @{
  1182. @"name":@"Place Of Delivery",
  1183. @"value":@"CAPE TOWN, SOUTH AFRICA"
  1184. },
  1185. ],
  1186. @"rowActionParameters":@[
  1187. @"27d620831e3f458643c8046305e2cd13"
  1188. ]
  1189. };
  1190. // B/L Info : module_name = Ocean B/L info.
  1191. NSDictionary *item_BL = @{
  1192. @"type": @1,
  1193. @"icon": @"status_ae",
  1194. @"title":@"FU YAMA TRADing", // Consignee
  1195. @"date":@"03/28/2019 - 04/24/2019", // ETD - ETA Port
  1196. @"port":@"CNYTN - USLAX", // pol pod
  1197. @"desc":@"A1903300004", // hbol#
  1198. @"detail":@"VIENXING GLOBAL PTE LTD", // Shipper
  1199. @"transport_stage": @3,
  1200. @"rowActionParameters":@[
  1201. @"27d620831e3f458643c8046305e2cd13"
  1202. ]
  1203. };
  1204. // Container : module_name = Container detail
  1205. NSDictionary *item_container = @{
  1206. @"type": @2,
  1207. @"icon": @"status_ae",
  1208. @"title": @"CN - YC STONE INC",
  1209. @"hbol": @"A1901280696",
  1210. @"desc": @"A1901280696(1 containers)",
  1211. @"detail": @"Gate in full for a booking; CNGOM (GAOMING, 44, CN 2019-01-04)",
  1212. @"date": @"01/16/2019 - 01/29/2019",
  1213. @"port": @"CNNSA - USLGB",
  1214. @"transport_stage": @3,
  1215. @"rowActionParameters":@[
  1216. @"27d620831e3f458643c8046305e2cd13"
  1217. ]
  1218. };
  1219. // Document : module_name = Download Document
  1220. NSDictionary *item_doc = @{
  1221. @"type": @3,
  1222. @"fileName":@"A1811390637FR1-UTA.pdf",
  1223. @"fileType":@"HBL",
  1224. @"po":@"0001791,0001722,0001885",
  1225. @"bol":@"A1811390637",
  1226. @"rowActionParameters":@[
  1227. @"handset_search",
  1228. @"download_doc",
  1229. @"https://ra.apexshipping.com/main_new.php",
  1230. @"QW10UUtFeDdRNlBFTzhLbFpYcCUyRmtUSFJnWHRwZ1RQSnBnZmpQblc0c1BHJTJCR1E5c2ZScWY3NXpIazJ0OXdicHEyUnolMkJxSkN1MDVV",
  1231. @"Question : FileName: ONEYSRGU12759300FR3.PDF, BOL: ONEYSRGU12759300",
  1232. @"FileName: ONEYSRGU12759300FR3.PDF, BOL: ONEYSRGU12759300",
  1233. @""
  1234. ]
  1235. };
  1236. NSString *module_name = [params objectForKey:@"module_name"];
  1237. NSMutableArray *arr = [NSMutableArray array];
  1238. for (int i = 0; i < 20; i++) {
  1239. if ([module_name isEqualToString:@"Ocean Booking"]) {
  1240. [arr addObject:item_booking.copy];
  1241. } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
  1242. [arr addObject:item_BL.copy];
  1243. } else if ([module_name isEqualToString:@"Container detail"]) {
  1244. [arr addObject:item_container.copy];
  1245. } else if ([module_name isEqualToString:@"Download Document"]) {
  1246. [arr addObject:item_doc.copy];
  1247. }
  1248. }
  1249. NSArray *menu;
  1250. NSString *title = @"";
  1251. if ([module_name isEqualToString:@"Ocean Booking"]) {
  1252. title = @"Ocean Booking";
  1253. menu = @[
  1254. @{
  1255. @"title": @"Setting",
  1256. @"action": @"field_setting"
  1257. },
  1258. @{
  1259. @"title": @"Save",
  1260. @"action": @"save"
  1261. }
  1262. ];
  1263. } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
  1264. title = @"Ocean B/L info";
  1265. menu = @[
  1266. @{
  1267. @"title": @"Setting",
  1268. @"action": @"field_setting"
  1269. },
  1270. @{
  1271. @"title": @"Save",
  1272. @"action": @"save"
  1273. }
  1274. ];
  1275. } else if ([module_name isEqualToString:@"Container detail"]) {
  1276. title = @"Container detail";
  1277. menu = @[
  1278. @{
  1279. @"title": @"Setting",
  1280. @"action": @"field_setting"
  1281. },
  1282. @{
  1283. @"title": @"Save",
  1284. @"action": @"save"
  1285. }
  1286. ];
  1287. } else if ([module_name isEqualToString:@"Download Document"]) {
  1288. title = @"Download Document";
  1289. menu = @[
  1290. @{
  1291. @"title": @"Save",
  1292. @"action": @"save"
  1293. }
  1294. ];
  1295. }
  1296. NSArray *row_actions;
  1297. if ([module_name isEqualToString:@"Download Document"]) {
  1298. row_actions = @[@{
  1299. @"title": @"Download Document",
  1300. @"module": @"quick_look",
  1301. @"url": @"https://ra.apexshipping.com/main_new.php",
  1302. @"params": @{
  1303. @"action": @0,
  1304. @"action_type": @1,
  1305. @"prefix": @2,
  1306. @"url": @3,
  1307. @"email_subject": @4,
  1308. @"email_content": @5,
  1309. @"email": @6
  1310. }
  1311. }];
  1312. } else {
  1313. row_actions = @[@{
  1314. @"title": @"Ocean B/L info Detail",
  1315. @"module": @"detail",
  1316. @"url": @"https://ra.apexshipping.com/main_new.php?action=handset_search",
  1317. @"params": @{
  1318. @"id": @0,
  1319. }
  1320. }];
  1321. }
  1322. NSDictionary *resultDic = @{
  1323. @"result" : @RESULT_TRUE,
  1324. @"title" : title,
  1325. @"row_actions" : row_actions,
  1326. @"items" : arr,
  1327. @"menu" : menu
  1328. };
  1329. // for detail
  1330. // NSArray *actions = @[
  1331. // @"Detail",
  1332. // @"ISF LOG",
  1333. // @"AMS LOG",
  1334. // @"Tracing",
  1335. // @"Detail"
  1336. // ];
  1337. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1338. NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
  1339. NSMutableDictionary *json = [resultDic mutableCopy];
  1340. [json setValue:actions forKey:@"actions"];
  1341. NSLog(@"%@",[RAConvertor dict2string:json]);
  1342. return json;
  1343. }
  1344. + (NSDictionary *)fetchResultParameters:(NSMutableDictionary *)params {
  1345. // return [self mockResult:params];
  1346. params[@"action"]=@"handset_search";
  1347. NSData* json=[self get_json:URL_SEARCH_RESULT parameters:params file:nil];
  1348. if (json==nil)
  1349. {
  1350. return @{
  1351. @"result" : @RESULT_NET_ERROR,
  1352. @"err_msg" : MSG_NET_ERROR
  1353. };
  1354. }
  1355. NSMutableDictionary *resultDic = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  1356. // detail data in local database
  1357. NSString *module_name = [params objectForKey:@"module_name"];
  1358. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1359. NSArray *actions = [ApexMobileDB getActionsForFunction:module_name withUser:appDelegate.user];
  1360. [resultDic setValue:actions forKey:@"actions"];
  1361. return resultDic;
  1362. }
  1363. + (NSDictionary *)saveSearchParameters:(NSString *)paramStr forModule:(NSString *)module withName:(NSString *)name {
  1364. if (!paramStr || !module) {
  1365. return @{
  1366. @"result" : @RESULT_FALSE,
  1367. @"err_msg" : @"Sorry, something is wrong."
  1368. };
  1369. }
  1370. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1371. NSString *sql = [NSString stringWithFormat: @"insert into history(params,name,module_name,user) values('%@','%@','%@','%@')",paramStr,name,module,appDelegate.user];
  1372. __block BOOL out_success = NO;
  1373. [ApexMobileDB jk_sync_excute:sql completion:^(BOOL success) {
  1374. out_success = success;
  1375. }];
  1376. if (out_success) {
  1377. return @{
  1378. @"result" : @RESULT_TRUE,
  1379. @"err_msg" : @"save success."
  1380. };
  1381. } else {
  1382. return @{
  1383. @"result" : @RESULT_FALSE,
  1384. @"err_msg" : @"Sorry, something is wrong."
  1385. };
  1386. }
  1387. }
  1388. + (NSString *)getDisplayFieldsForFunction:(NSString *)function limit:(NSUInteger)limit {
  1389. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1390. return [ApexMobileDB getDisplayFieldsForFunction:function withUser:appDelegate.user limit:limit];
  1391. }
  1392. @end