RANetwork.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. //
  2. // RANetwork.m
  3. // iShop
  4. //
  5. // Created by Rui Zhang on 12/18/23.
  6. //
  7. #import "RANetwork.h"
  8. @implementation RANetwork
  9. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  10. {
  11. if(RASingleton.sharedInstance.duid!=nil && params[@"udid"]==nil)
  12. params[@"udid"]=RASingleton.sharedInstance.duid;
  13. #if TARGET_IPHONE_SIMULATOR//模拟器
  14. params[@"udid"]=@"simulator";
  15. #endif
  16. # ifdef DEBUG
  17. [params setValue:@"true" forKey:@"is_debug"];
  18. # endif
  19. if(RASingleton.sharedInstance.user!=nil && params[@"user"]==nil)
  20. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  21. if(RASingleton.sharedInstance.password!=nil&& params[@"password"]==nil)
  22. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  23. if(RASingleton.sharedInstance.ipad_perm!=nil)
  24. [params setValue:RASingleton.sharedInstance.ipad_perm forKey:@"ipad_perm"];
  25. [params setValue:RASingleton.sharedInstance.build forKey:@"app_ver"];
  26. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  27. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  28. [params setValue:short_version forKey:@"app_short_ver"];
  29. #if TARGET_IPHONE_SIMULATOR//模拟器
  30. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  31. #elif TARGET_OS_IPHONE//真机
  32. UIDevice * dev = [UIDevice currentDevice];
  33. NSUUID* uuid =dev.identifierForVendor;
  34. [params setValue:uuid.UUIDString forKey:@"idfv"];
  35. #endif
  36. return params;
  37. }
  38. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  39. {
  40. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  41. AppDelegate *appDelegate = nil;
  42. //some UI methods ej
  43. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  44. if(RASingleton.sharedInstance.user!=nil)
  45. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  46. if(RASingleton.sharedInstance.contact_id!=nil)
  47. [params setValue:RASingleton.sharedInstance.contact_id forKey:@"contactId"];
  48. if(RASingleton.sharedInstance.password!=nil)
  49. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  50. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  51. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  52. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  53. return;
  54. }
  55. +(void)request_category:(resultHandler)result
  56. {
  57. AppDelegate *appDelegate = nil;
  58. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  59. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  60. }
  61. +(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
  62. {
  63. AppDelegate *appDelegate = nil;
  64. //some UI methods ej
  65. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  66. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  67. if(RASingleton.sharedInstance.user!=nil)
  68. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  69. // if(appDelegate.contact_id!=nil)
  70. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  71. if(RASingleton.sharedInstance.password!=nil)
  72. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  73. // if(appDelegate.order_code!=nil)
  74. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  75. [params setValue:alert forKey:@"alert"];
  76. [params setValue:qty forKey:@"sold_by_qty"];
  77. [params setValue:available forKey:@"available"];
  78. [params setValue:price forKey:@"price"];
  79. [params setValue:bestseller forKey:@"bestseller"];
  80. [params setValue:modelname forKey:@"modelName"];
  81. [params setValue:modeldescrip forKey:@"modelDescription"];
  82. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  83. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  84. [params setValue:category forKey:@"category"];
  85. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  86. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  87. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  88. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  89. [params setValue:filter forKey:@"filter"];
  90. [params setValue:keyword forKey:@"keyword"];
  91. // if (alert) {
  92. // [params setObject:@"Filter" forKey:kAction];
  93. // }
  94. // if ([RASingleton sharedInstance].homeItemClick) {
  95. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  96. // [RASingleton sharedInstance].homeItemClick = NO;
  97. //
  98. // NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  99. // [RASingleton sharedInstance].homeClickedItemName = nil;
  100. // [params setObject:extra forKey:kExtra];
  101. //
  102. // }
  103. //
  104. //
  105. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  106. return ;
  107. }
  108. +(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
  109. {
  110. // for debug
  111. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  112. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  113. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  114. AppDelegate *appDelegate = nil;
  115. //some UI methods ej
  116. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  117. if(RASingleton.sharedInstance.user!=nil)
  118. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  119. // if(appDelegate.contact_id!=nil)
  120. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  121. // if(RASingleton.sharedInstance.password!=nil)
  122. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  123. // if(appDelegate.order_code!=nil)
  124. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  125. //
  126. //
  127. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  128. // if (alert && qty && available && price && bestseller) {
  129. // [params setObject:@"Filter" forKey:kAction];
  130. // }
  131. // if ([RASingleton sharedInstance].homeItemClick) {
  132. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  133. // [RASingleton sharedInstance].homeItemClick = NO;
  134. //
  135. // NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  136. // [RASingleton sharedInstance].homeClickedItemName = nil;
  137. // [params setObject:extra forKey:kExtra];
  138. // }
  139. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  140. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  141. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  142. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  143. // [params setValue:filter forKey:@"filter"];
  144. [params setValue:covertype forKey:@"covertype"];
  145. [params setValue:ctgid forKey:@"ctgId"];
  146. [params setValue:modelname forKey:@"modelName"];
  147. [params setValue:modeldescrip forKey:@"modelDescription"];
  148. [params setValue:alert forKey:@"alert"];
  149. [params setValue:qty forKey:@"sold_by_qty"];
  150. [params setValue:available forKey:@"available"];
  151. [params setValue:price forKey:@"price"];
  152. [params setValue:bestseller forKey:@"bestseller"];
  153. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  154. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  155. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  156. }
  157. +(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
  158. {
  159. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  160. AppDelegate *appDelegate = nil;
  161. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  162. if(RASingleton.sharedInstance.user!=nil)
  163. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  164. // if(appDelegate.contact_id!=nil)
  165. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  166. if(RASingleton.sharedInstance.password!=nil)
  167. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  168. // if(appDelegate.order_code!=nil)
  169. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  170. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  171. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  172. if(use_name)
  173. [params setValue:model_name forKey:@"product_name"];
  174. else
  175. if(use_upc){
  176. params[@"search_upc"]=@true;
  177. [params setValue:upc_code forKey:@"upc_code"];
  178. }
  179. else
  180. [params setValue:item_id forKey:@"product_id"];
  181. [params setValue:category_id forKey:@"category"];
  182. if (model_name) {
  183. NSDictionary *extra = @{@"ModelName" : model_name};
  184. }
  185. if (groupName.length > 0) {
  186. [params setObject:groupName forKey:@"groupName"];
  187. }
  188. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  189. //
  190. // if(appDelegate.offline_mode)
  191. // return [OLDataProvider offline_model:params];
  192. //
  193. // if(![self IsNetworkAvailable])
  194. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  195. //
  196. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  197. // if(json==nil)
  198. // return nil;
  199. // NSError *error=nil;
  200. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  201. // return jsobj;
  202. }
  203. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  204. {
  205. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  206. // AppDelegate *appDelegate = nil;
  207. //
  208. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  209. // if(RASingleton.sharedInstance.user!=nil)
  210. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  211. // if(appDelegate.contact_id!=nil)
  212. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  213. // if(RASingleton.sharedInstance.password!=nil)
  214. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  215. // if(appDelegate.order_code!=nil)
  216. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  217. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  218. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  219. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  220. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  221. // [params setValue:filter forKey:@"filter"];
  222. [params setValue:keywords forKey:@"keyword"];
  223. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  224. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  225. if(matchfull)
  226. [params setValue:@"true" forKey:@"exactMatch"];
  227. else
  228. [params setValue:@"false" forKey:@"exactMatch"];
  229. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  230. }
  231. @end