Browse Source

1.调试外网走nas服务器 未果

huangxiaodong 1 year ago
parent
commit
cc482ad63f

+ 2 - 1
创维盒子/双子星云手机/AppDelegate/AppDelegate.h

@@ -24,7 +24,8 @@
 @property (nonatomic, assign)BOOL isWebSockLinkOKAginType;//WebSock断开后或者链接上了
 
 @property (nonatomic, strong) NASMsgModel * NASMsgMod;
-@property (nonatomic, copy) NSString * NASFileService;
+@property (nonatomic, copy) NSString * NASFileService;//走公网的
+@property (nonatomic, copy) NSString * NASFileByBoxService;//本盒子的IP
 +(AppDelegate*)sharedAppDelegate;
 @end
 

+ 13 - 0
创维盒子/双子星云手机/AppDelegate/AppDelegate.m

@@ -313,4 +313,17 @@
     }
     return nil;
 }
+- (NSString*)NASFileByBoxService
+{
+    if(_NASMsgMod){
+        if([_NASMsgMod.data.domainName rangeOfString:@"http"].location != NSNotFound){
+            return  [[NSString alloc] initWithFormat:@"%@:%@/",_NASMsgMod.data.ip,@"9888"];
+            
+        }
+        else{
+            return  [[NSString alloc] initWithFormat:@"http://%@:%@/",_NASMsgMod.data.ip,@"9888"];
+        }
+    }
+    return nil;
+}
 @end

+ 7 - 2
创维盒子/双子星云手机/AppDelegate/PrefixHeader.pch

@@ -90,9 +90,14 @@ isBangsScreen; \
 //创维盒子 测试地址
 #define CloudService   @"http://14.18.190.141:1801"
 #define shareService   @"http://testprivacy.phone.armclouding.com:1801/h5/#/pages/fileSharing/index?productType=Private-X&token="
-#define NASService [NSString stringWithFormat:@"http://%@:9888",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip];
-//#define NASService [NSString stringWithFormat:@"http://%@:9888",@"192.168.11.248"]
 
+#define NASService [NSString stringWithFormat:@"http://%@:9888",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip]
+//#define NASService [NSString stringWithFormat:@"https://%@:9888",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip]
+
+//#define NASService @"http://127.0.0.1:9888";
+
+//#define NASService @"http://59.36.210.201:9888";
+//#define NASService @"http://172.17.0.2:9888";
 
 //生产环境
 //#define CloudService   @"http://hiboxde.armclouding.com:7780"

+ 16 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveDownloadRecordTableView.h

@@ -0,0 +1,16 @@
+//
+//  receiveDownloadRecordTableView.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface receiveDownloadRecordTableView : UITableView
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 20 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveDownloadRecordTableView.m

@@ -0,0 +1,20 @@
+//
+//  receiveDownloadRecordTableView.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import "receiveDownloadRecordTableView.h"
+
+@implementation receiveDownloadRecordTableView
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 16 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveHeadView.h

@@ -0,0 +1,16 @@
+//
+//  receiveHeadView.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface receiveHeadView : UIView
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 20 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveHeadView.m

@@ -0,0 +1,20 @@
+//
+//  receiveHeadView.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import "receiveHeadView.h"
+
+@implementation receiveHeadView
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 16 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveSaveRecordTableView.h

@@ -0,0 +1,16 @@
+//
+//  receiveSaveRecordTableView.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface receiveSaveRecordTableView : UITableView
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 20 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveSaveRecordTableView.m

@@ -0,0 +1,20 @@
+//
+//  receiveSaveRecordTableView.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import "receiveSaveRecordTableView.h"
+
+@implementation receiveSaveRecordTableView
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 16 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveView.h

@@ -0,0 +1,16 @@
+//
+//  receiveView.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface receiveView : UIView
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 20 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveView.m

@@ -0,0 +1,20 @@
+//
+//  receiveView.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/5/23.
+//
+
+#import "receiveView.h"
+
+@implementation receiveView
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 4 - 3
创维盒子/双子星云手机/connectDeviceManager/connectDeviceManager.m

@@ -330,11 +330,11 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
         /// 4. 创建 HttpService
         self.tcpPort = [RaylinkProxy.sharedManager createHttpService:sdnId];
         self.tcpPortStr = [[NSString alloc] initWithFormat:@"%ld",self.tcpPort];
-        
+        [[netWorkManager shareInstance] setAFHTTPSessionManagerFunBy:self.tcpPort];
         /// 5. 添加端口防火墙
         [RaylinkProxy.sharedManager addSdnId:sdnId ip:ruiyunlinkIp allowPort:9300];
         [RaylinkProxy.sharedManager addSdnId:sdnId ip:ruiyunlinkIp allowPort:9100];
-        
+        [RaylinkProxy.sharedManager addSdnId:sdnId ip:ruiyunlinkIp allowPort:9888];
         [cachesFileManager writeLogsWithMsg:@"onProxyConnected connectToHost"];
         
         /// 6. 等待连接成功回调,创建 TCP socket 连接 HttpService 的端口
@@ -439,9 +439,10 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
     NSString *sdnId = self.DeviceThirdIdMod.data.sdnId;
     self.tcpPort = [RaylinkProxy.sharedManager createHttpService:sdnId];
     self.tcpPortStr = [[NSString alloc] initWithFormat:@"%ld",self.tcpPort];
+    [[netWorkManager shareInstance] setAFHTTPSessionManagerFunBy:self.tcpPort];
     [RaylinkProxy.sharedManager addSdnId:sdnId ip:ruiyunlinkIp allowPort:9300];
     [RaylinkProxy.sharedManager addSdnId:sdnId ip:ruiyunlinkIp allowPort:9100];
-    
+    [RaylinkProxy.sharedManager addSdnId:sdnId ip:ruiyunlinkIp allowPort:9888];
 }
 
 //- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port {

+ 1 - 0
创维盒子/双子星云手机/netWork/netWorkManager.h

@@ -23,6 +23,7 @@ typedef void (^netWork_Faild) (NSError *error);
 @interface netWorkManager : NSObject
 
 +(netWorkManager *)shareInstance;
+- (void)setAFHTTPSessionManagerFunBy:(NSInteger)tcpPort;
 
 #pragma mark  afnetwork  post 请求
 - (void)CommonPostCallBackCode:(NSString*)code  Parameters:(NSDictionary*)dict success:(netWork_Success)success failure:(netWork_Faild)failure;

+ 81 - 2
创维盒子/双子星云手机/netWork/netWorkManager.m

@@ -16,6 +16,7 @@
     NSString *mCloudService;
     //NSString *mRequstAPI;
 
+    AFHTTPSessionManager *managerNAS;
 }
 
 @end
@@ -108,7 +109,7 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
     
     if ([mCloudService rangeOfString:@"https"].location != NSNotFound)
     {
-        //[manager setSecurityPolicy:[self customSecurityPolicy]];
+        [manager setSecurityPolicy:[self customSecurityPolicy]];
     }
     
     // 客户端是否信任非法证书
@@ -126,6 +127,82 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
     
 }
 
+- (void)setAFHTTPSessionManagerFunBy:(NSInteger)tcpPort
+{
+    NSString *ip = @"127.0.0.1";
+    NSNumber *proxyPort = [NSNumber numberWithInteger:tcpPort];
+    NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
+    config.connectionProxyDictionary = @
+        {
+            @"HTTPEnable":@YES,
+            @"HTTPProxy" : ip,
+            @"HTTPPort" : proxyPort,
+            @"HTTPSEnable":@YES,
+            @"HTTPSProxy": ip,
+            @"HTTPSPort": proxyPort
+        };
+
+    managerNAS = [[AFHTTPSessionManager alloc] initWithBaseURL:nil sessionConfiguration:config];
+    
+    managerNAS.requestSerializer = [AFJSONRequestSerializer serializer];
+    managerNAS.responseSerializer = [AFJSONResponseSerializer serializer];
+    [managerNAS.requestSerializer setHTTPShouldHandleCookies:NO];
+    [managerNAS.requestSerializer setHTTPShouldUsePipelining:NO];
+    managerNAS.responseSerializer.acceptableContentTypes  =  [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain",@"application/xml",@"image/png", @"audio/aac", @"text/x-vcard",nil];
+    
+    managerNAS.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", nil];
+    
+    if ([NASService rangeOfString:@"https"].location != NSNotFound)
+    {
+        [managerNAS setSecurityPolicy:[self customSecurityPolicy]];
+    }
+}
+
+#pragma - mark 证书相关
+- (AFSecurityPolicy*)customSecurityPolicy
+{
+//    // /先导入证书
+//    NSString *cerName = @"newrelease";
+//    if ([@"https://client.phone.androidscloud.com" isEqualToString:CloudService])
+//    {
+//        cerName = @"newrelease";
+//    }
+//    else if ([@"https://prese.phone.androidscloud.com" isEqualToString:CloudService])
+//    {
+//        cerName = @"newrelease";
+//    }
+//    NSString *cerPath = [[NSBundle mainBundle] pathForResource:cerName ofType:@"cer"];//证书的路径
+//    NSData *certData = [NSData dataWithContentsOfFile:cerPath];
+    
+    // AFSSLPinningModeCertificate 使用证书验证模式、、、//AFSSLPinningModeNone  不使用SSLPinning  //AFSSLPinningModeCertificate  使用SSLPinning
+    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
+    
+//    if ([@"https://test.androidscloud.com" isEqualToString:CloudService])
+//    {
+//        securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
+//    }
+//    else if ([@"https://pre.androidscloud.com" isEqualToString:CloudService])
+//    {
+//        securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
+//    }
+//    else if ([@"https://a.androidscloud.com" isEqualToString:CloudService])
+//    {
+//        securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
+//    }
+    
+    // allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO
+    // 如果是需要验证自建证书,需要设置为YES
+    securityPolicy.allowInvalidCertificates = NO;
+    //validatesDomainName 是否需要验证域名,默认为YES;
+    //假如证书的域名与你请求的域名不一致,需把该项设置为NO;如设成NO的话,即服务器使用其他可信任机构颁发的证书,也可以建立连接,这个非常危险,建议打开。
+    //置为NO,主要用于这种情况:客户端请求的是子域名,而证书上的是另外一个域名。因为SSL证书上的域名是独立的,假如证书上注册的域名是www.google.com,那么mail.google.com是无法验证通过的;当然,有钱可以注册通配符的域名*.google.com,但这个还是比较贵的。
+    //如置为NO,建议自己添加对应域名的校验逻辑。
+    securityPolicy.validatesDomainName = YES;
+    
+//    securityPolicy.pinnedCertificates = [[NSSet alloc] initWithObjects:certData, nil];
+    
+    return securityPolicy;
+}
 
 #pragma - mark 证书相关
 //- (AFSecurityPolicy*)customSecurityPolicy
@@ -360,7 +437,8 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
     NSString *url = [NSString stringWithFormat:@"%@/%@",curServer,code];
     HLog(@"地址:%@ \n接口名称:%@,\n 参数:%@\n",url,code,dict);
     
-    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
+    //managerNAS manager
+    [managerNAS.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
     
     if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
     {// 无网络状态
@@ -371,6 +449,7 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
         return;
     }
     
+    //managerNAS manager
     [manager GET:url parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         
         HLog(@"接口名称:%@ 接口返回:%@,\n ",code,responseObject);