Bläddra i källkod

Common
添加网络请求常驻参数注入接口
修复请求后无返回问题

apex mobile
完成news 请求接口
完成announcement 请求接口
完成service location 请求接口
增加login 请求接口,未完成。

!!! 此为中间版本,无法正常运行 !!!

Ray Zhang 6 år sedan
förälder
incheckning
420e262a2d

+ 74 - 0
Apex Mobile/Apex Mobile/LocationViewController.m

@@ -481,6 +481,80 @@
     //    self.grid.hidden = true;
     //
     //    [UIView commitAnimations];
+    
+    
+
+    [RANetwork request_servicelocatin:^(NSMutableDictionary *result) {
+        NSDictionary* locationJson=result;
+
+//        {
+                    int result_code = [locationJson[@"result"] intValue];
+                    if(result_code==RESULT_TRUE) {
+
+                            NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:@"service_location.json"];
+//                            if(jsobj!=nil&&[jsobj[@"result"] intValue]!=RESULT_NET_ERROR&&[jsobj[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
+//                            {
+                                // 本地缓存,加快下次加载速度;
+                                [locationJson writeToFile:path atomically:YES];
+                        //        return ret;
+//                            }
+
+
+        //                if (self.useGoogleMap) {
+        //                    [self addLocation];
+        //                } else{
+                        self.locationjson = [locationJson mutableCopy];
+                        [self addOfficeLocation];
+        //                }
+                    }
+                    else
+                    {
+
+                    }
+
+
+
+                    //            if(bupdate==true)
+                    //            {
+                    //
+                    //            }
+                    //            else
+                    //            {
+                    //
+                    //            }
+                    //            if(self.recordCount>=0)
+                    //            {
+                    //                if(self.recordCount<2000)
+                    //                    self.countView.title = [NSString stringWithFormat:@"%ld records",self.recordCount];
+                    //                else
+                    //                    self.countView.title = @"2000+ records";
+                    //            }
+                    //            else
+                    //            {
+                    //                self.countView.title = @"Net error!";
+                    //            }
+                    //            if(self.offset<self.pageData.get_count||self.offset==0)
+                    //                self.prepageButton.enabled=false;
+                    //            else
+                    //                self.prepageButton.enabled=true;
+                    //            if(self.offset+self.pageData.get_count>=self.recordCount)
+                    //                self.nextpageButton.enabled=false;
+                    //            else
+                    //                self.nextpageButton.enabled=true;
+                    //            [self.grid initgrid :self.pageData];
+                    //
+                    //            CGPoint p = self.grid.frame.origin;
+                    //
+                    //
+                    //            self.mum.hidden = true;
+                    //            self.grid.hidden = false;
+                    //            [UIView commitAnimations];
+
+//                }
+    }];
+    
+    return;
+    
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 
         NSDictionary* locationJson=[RANetwork RequestServiceLocation];

+ 45 - 4
Apex Mobile/Apex Mobile/NewsViewController.m

@@ -54,12 +54,53 @@
     
     //    [UIView commitAnimations];
     
-    NSData* data=nil;
+//    NSData* data=nil;
     if([self.module_name isEqualToString:@"Announcements"])
-        [RANetwork get_announcements:self.lastid limit:self.limit];
+//        [RANetwork get_announcements:self.lastid limit:self.limit];
+    [RANetwork request_announcements:self.lastid limit:self.limit completionHandler:^(NSMutableDictionary *result) {
+                self.tableview.hidden =false;
+                self.mum.hidden = true;
+                if(result != nil)
+                {
+                    [self.data append_jsondata: result];
+                    self.lastid = self.data._id;
+                    self.btnrefresh.hidden = false;
+                    if(self.data.finishload==true)
+                    {
+                        
+    //                    int i =self.btnrefresh.state;
+                        self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more",nil);
+                        //                    [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
+                    }
+                    else
+                    {
+                        self.btnrefresh.enabled = true;
+                        self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
+                        //                    [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
+                    }
+                    
+                    [self.tableview reloadData ];
+                    if (finish) {
+                        finish(2);
+                    }
+                }
+                else
+                {
+                    self.btnrefresh.enabled = true;
+                    [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
+                    if (finish) {
+                        finish(0);
+                    }
+                }
+                
+                
+                
+                
+                
+            }];
     else
         [RANetwork request_marketnews:self.lastid limit:self.limit completionHandler:^(NSMutableDictionary *result) {
-                    dispatch_async(dispatch_get_main_queue(), ^{
+//                    dispatch_async(dispatch_get_main_queue(), ^{
                         self.tableview.hidden =false;
                         self.mum.hidden = true;
                         if(result != nil)
@@ -99,7 +140,7 @@
                         
                         
                         
-                    });
+//                    });
         }];
     
     return;

+ 3 - 2
Apex Mobile/Apex Mobile/RANetwork.h

@@ -53,6 +53,7 @@
 
 
 // 新接口逐步替换以前的网络请求,2020
-+(void)request_marketnews : (NSString*) id limit: (int) limit completionHandler:(resultHandler)result;
-
++(void)request_marketnews : (NSString*) lastid limit: (int) limit completionHandler:(resultHandler)result;
++(void)request_announcements : (NSString*) lastid limit: (int) limit completionHandler:(resultHandler)result;
++(void) request_servicelocatin:(resultHandler)result;
 @end

+ 113 - 7
Apex Mobile/Apex Mobile/RANetwork.m

@@ -1267,6 +1267,9 @@
 
 + (NSDictionary *)collectErrMsg:(NSString *)errMsg DeviceInfo:(NSString *)deviceInfo Time:(NSString *)time {
     
+    
+    if(URL_ERR_LOG.length==0)
+        return nil;
     NSMutableDictionary *params = [@{
                               @"device_info" : deviceInfo == nil ? @"" : deviceInfo,
                               @"crash_info" : errMsg == nil ? @"" : errMsg,
@@ -1716,12 +1719,8 @@
     return [ApexMobileDB getDisplayFieldsForFunction:function withUser:appDelegate.user limit:limit];
 }
 
-
-
-
-#pragma mark new interface
-
-+(void)request_marketnews : (NSString*) id limit: (int) limit completionHandler:(resultHandler)result
+#pragma mark new_interface
++(void)request_marketnews : (NSString*) lastid limit: (int) limit completionHandler:(resultHandler)result
 {
     if(![NetworkUtils IsNetworkAvailable])
         return ;//RESULT_NET_NOTAVAILABLE;
@@ -1729,7 +1728,7 @@
     NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
     [params setValue:@"Market News" forKey:@"module_name"];
     [params setValue:@"search" forKey:@"action_type"];
-    [params setValue:id forKey:@"id"];
+    [params setValue:lastid forKey:@"id"];
     [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
     
     
@@ -1744,5 +1743,112 @@
     
     
     
+}
+
+
++(void)request_announcements : (NSString*) lastid limit: (int) limit completionHandler:(resultHandler)result
+{
+    if(![NetworkUtils IsNetworkAvailable])
+        return ;//RESULT_NET_NOTAVAILABLE;
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    [params setValue:@"Announcements" forKey:@"module_name"];
+    [params setValue:@"search" forKey:@"action_type"];
+    [params setValue:lastid forKey:@"id"];
+    [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
+  
+    [self request_interface:URL_ANNOUNCEMENTS parameters:params err_record_url:nil completionHandler:result retry:0];
+//    NSData* json=[self get_json:URL_ANNOUNCEMENTS parameters:params file:nil];
+//    if (json==nil)
+//    {
+//        DebugLog(@"json is wrong");
+//        return nil;
+//    }
+//    return json;
+    
+    
+    
+}
+
+
++(void) request_servicelocatin:(resultHandler)result
+{
+    if(![NetworkUtils IsNetworkAvailable])
+        return ;//RESULT_NET_NOTAVAILABLE;
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    [params setValue:@"Location" forKey:@"module_name"];
+    [params setValue:@"search" forKey:@"action_type"];
+    [params setValue:@"999" forKey:@"limit"];
+    
+    [self request_interface:URL_LOCATIONS parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+//    NSData* json=[self get_json:URL_LOCATIONS parameters:params file:nil];
+//    if (json==nil)
+//    {
+//        return @{
+//                 @"result" : @RESULT_NET_ERROR,
+//                 @"err_msg" : MSG_NET_ERROR
+//                 };
+//    }
+//
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//
+//
+//    NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:@"service_location.json"];
+//    if(jsobj!=nil&&[jsobj[@"result"] intValue]!=RESULT_NET_ERROR&&[jsobj[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
+//    {
+//
+//        [jsobj writeToFile:path atomically:YES];
+////        return ret;
+//    }
+//
+//    return jsobj;
+    
+   
+    
+}
+
+
++(void)request_login : (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
+{
+    
+    if(![NetworkUtils IsNetworkAvailable])
+        return ;
+    //    if(![RANetwork IsHostAvailable:URL_UPDATE_AUTH])
+    //        return RESULT_NET_ERROR;
+    
+    
+    __block long ver = 0;
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    
+    dispatch_async(dispatch_get_main_queue(), ^{
+        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+        ver = appDelegate.authVer;
+        if(appDelegate.duid !=nil)
+            [params setValue:appDelegate.duid forKey:@"udid"];
+    });
+    
+    [params setValue:@"handset_login" forKey:@"action"];
+    //    [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
+    
+    [params setValue:user forKey:@"user"];
+    [params setValue:password forKey:@"password"];
+    [params setValue:[NSString stringWithFormat:@"%ld",ver]  forKey:@"auth_ver"];
+#ifdef TEST
+    [params setValue:@"true" forKey:@"is_debug"];
+#else
+    [params setValue:@"false" forKey:@"is_debug"];
+#endif
+    NSData* json=[self get_json:URL_UPDATE_AUTH parameters:params  file:nil];
+    if(json==nil)
+        return ;
+    
+    int ret = [self parse_authinfo:json user:user password:password];
+    DebugLog(@"parse_authinfo return %d ",ret);
+    
+    
+    return ;
+    
 }
 @end

+ 28 - 3
common/NetworkUtils.m

@@ -555,11 +555,29 @@ repeat:
 
 #pragma mark new interface
 
++(NSMutableDictionary*) prepare_addtional_params:(NSMutableDictionary* ) params
+{
+
+//
+//    NSString *userAction = [params valueForKey:kAction];
+//    NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
+//    if ([userAction isEqualToString:@"Login"]) {
+//        if (!extra) {
+//            extra = [NSMutableDictionary dictionary];
+//        }
+//        [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
+//    }
+    
+    return params;
+}
+
+
 +(NSData*)request_interface : (NSString*) url parameters:(NSMutableDictionary *) params  err_record_url:(NSString* )recorder_url completionHandler:(resultHandler)result retry:(int) retry
 {
 //    __block int retry = 0;
     
 
+    params = [self prepare_addtional_params:params];
     
     
 //repeat:
@@ -730,6 +748,7 @@ repeat:
                             {
                                 int new_retry=retry+1;
                                 [self request_interface:url parameters:params err_record_url:recorder_url completionHandler:result retry:new_retry];
+                                return;
             //                    retry++;
             //                    goto repeat;
 
@@ -758,11 +777,17 @@ repeat:
                             {
                                 [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
                             }
-                            return ;
+                            return result([[RAConvertor data2dict:jsonData] mutableCopy]);
 
                         }
-
-                        return ;
+                        else
+                        {
+                            NSDictionary* dict =[RAConvertor data2dict:responseData];
+                            dispatch_async(dispatch_get_main_queue(), ^{
+                                return result([[RAConvertor data2dict:responseData] mutableCopy]);
+                            });
+                            
+                        }
                     
         }];
 //         NSURLSessionDataTask *dataTask = [urlSession dataTaskWithRequest:request ];