RANetwork.m 67 KB

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