| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- //
- // RANetwork.m
- // iShop
- //
- // Created by Rui Zhang on 12/18/23.
- //
- #import "RANetwork.h"
- @implementation RANetwork
- +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
- {
-
- if(RASingleton.sharedInstance.duid!=nil && params[@"udid"]==nil)
- params[@"udid"]=RASingleton.sharedInstance.duid;
- #if TARGET_IPHONE_SIMULATOR//模拟器
- params[@"udid"]=@"simulator";
- #endif
-
- # ifdef DEBUG
- [params setValue:@"true" forKey:@"is_debug"];
- # endif
- if(RASingleton.sharedInstance.user!=nil && params[@"user"]==nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- if(RASingleton.sharedInstance.password!=nil&& params[@"password"]==nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
-
-
- if(RASingleton.sharedInstance.ipad_perm!=nil)
- [params setValue:RASingleton.sharedInstance.ipad_perm forKey:@"ipad_perm"];
-
- [params setValue:RASingleton.sharedInstance.build forKey:@"app_ver"];
-
- NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
- NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
- [params setValue:short_version forKey:@"app_short_ver"];
-
-
-
- #if TARGET_IPHONE_SIMULATOR//模拟器
- [params setValue:@"simulator_uuid" forKey:@"idfv"];
- #elif TARGET_OS_IPHONE//真机
- UIDevice * dev = [UIDevice currentDevice];
- NSUUID* uuid =dev.identifierForVendor;
- [params setValue:uuid.UUIDString forKey:@"idfv"];
- #endif
- return params;
- }
- +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
- {
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
-
- //some UI methods ej
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- if(RASingleton.sharedInstance.contact_id!=nil)
- [params setValue:RASingleton.sharedInstance.contact_id forKey:@"contactId"];
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
-
-
-
- [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
-
- return;
-
- }
- +(void)request_category:(resultHandler)result
- {
-
- AppDelegate *appDelegate = nil;
-
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
-
- }
- +(void)request_categorylist: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
-
- //some UI methods ej
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
-
- [params setValue:alert forKey:@"alert"];
- [params setValue:qty forKey:@"sold_by_qty"];
- [params setValue:available forKey:@"available"];
- [params setValue:price forKey:@"price"];
- [params setValue:bestseller forKey:@"bestseller"];
- [params setValue:modelname forKey:@"modelName"];
- [params setValue:modeldescrip forKey:@"modelDescription"];
-
- [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
- [params setValue:category forKey:@"category"];
- [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
- [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
- [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
- [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
- [params setValue:filter forKey:@"filter"];
- [params setValue:keyword forKey:@"keyword"];
-
-
- // if (alert) {
- // [params setObject:@"Filter" forKey:kAction];
- // }
- // if ([RASingleton sharedInstance].homeItemClick) {
- // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
- // [RASingleton sharedInstance].homeItemClick = NO;
- //
- // NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
- // [RASingleton sharedInstance].homeClickedItemName = nil;
- // [params setObject:extra forKey:kExtra];
- //
- // }
- //
- //
-
- [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
-
- return ;
-
-
- }
- +(void)request_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller completionHandler:(resultHandler)result
- {
-
- // for debug
- // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
- //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
-
-
- //some UI methods ej
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
- //
- //
- // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
- // if (alert && qty && available && price && bestseller) {
- // [params setObject:@"Filter" forKey:kAction];
- // }
- // if ([RASingleton sharedInstance].homeItemClick) {
- // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
- // [RASingleton sharedInstance].homeItemClick = NO;
- //
- // NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
- // [RASingleton sharedInstance].homeClickedItemName = nil;
- // [params setObject:extra forKey:kExtra];
- // }
-
-
- // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
- // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
- // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
- // [params setValue:filter forKey:@"filter"];
- [params setValue:covertype forKey:@"covertype"];
- [params setValue:ctgid forKey:@"ctgId"];
- [params setValue:modelname forKey:@"modelName"];
- [params setValue:modeldescrip forKey:@"modelDescription"];
- [params setValue:alert forKey:@"alert"];
- [params setValue:qty forKey:@"sold_by_qty"];
- [params setValue:available forKey:@"available"];
- [params setValue:price forKey:@"price"];
- [params setValue:bestseller forKey:@"bestseller"];
-
- [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
- [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
-
-
- [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
-
-
- }
- +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name upc_code:(NSString*) upc_code category_id:(NSString*) category_id use_name :(bool) use_name use_upc :(bool) use_upc groupName:(NSString *)groupName completionHandler:(resultHandler)result
- {
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
- // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
- if(use_name)
- [params setValue:model_name forKey:@"product_name"];
- else
- if(use_upc){
- params[@"search_upc"]=@true;
- [params setValue:upc_code forKey:@"upc_code"];
- }
- else
- [params setValue:item_id forKey:@"product_id"];
-
-
-
-
- [params setValue:category_id forKey:@"category"];
-
-
-
- if (model_name) {
- NSDictionary *extra = @{@"ModelName" : model_name};
-
- }
-
- if (groupName.length > 0) {
- [params setObject:groupName forKey:@"groupName"];
- }
-
-
-
- [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
-
- //
- // if(appDelegate.offline_mode)
- // return [OLDataProvider offline_model:params];
- //
- // if(![self IsNetworkAvailable])
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- //
- // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // return jsobj;
- }
- +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
- {
-
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // AppDelegate *appDelegate = nil;
- //
- // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(RASingleton.sharedInstance.user!=nil)
- // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- // if(RASingleton.sharedInstance.password!=nil)
- // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
- // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
- // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
- // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
- // [params setValue:filter forKey:@"filter"];
- [params setValue:keywords forKey:@"keyword"];
-
- [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
- [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
- if(matchfull)
- [params setValue:@"true" forKey:@"exactMatch"];
- else
- [params setValue:@"false" forKey:@"exactMatch"];
-
- [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
- }
- @end
|