zwp 5 месяцев назад
Родитель
Сommit
230453dcfe

+ 1 - 1
AIIM/Common/CommonUI/TopPopupView.m

@@ -96,7 +96,7 @@ static const NSTimeInterval kPopupDisplayTime = 3.0;
     self.nicknameLabel.text = nickname;
     self.messageLabel.text = message;
     if (avatar) {
-        [self.avatar sd_setImageWithURL:getURL(avatar)];
+        [self.avatar sd_setImageWithURL:getURL(avatar) placeholderImage:kImageMake(@"Avatar")];
     }
     
     // 布局

+ 2 - 1
AIIM/Common/Network/aliOSS/OSSManager.h

@@ -26,9 +26,10 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, strong) NSDictionary *OSSInfo;
 @property (nonatomic,strong) NSMutableArray * _Nullable uploadTanck;
 
+@property (nonatomic) NSInteger initIme;
+
 + (instancetype)sharedManager;
 
--(void)getOSSInfo;
 //普通上传
 - (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime;
 

+ 103 - 18
AIIM/Common/Network/aliOSS/OSSManager.m

@@ -46,15 +46,10 @@
 }
 
 
--(void)getOSSInfo{
+-(void)getOSSInfo:(void (^_Nullable)(bool))success{
     if (!_uploadTanck) {
         _uploadTanck = [NSMutableArray new];
     }
-    NSDictionary *dic = [UDManager.shareInstance getDDManager:nkOSSinfo];
-    if(dic){
-        self.OSSInfo = dic.copy;
-        [self initmyAliyunOSS];
-    }
     
     [OssNetApi getOSSInfo:nil succ:^(int code, NSDictionary * res) {
         NSLog(@"res:%@",res);
@@ -62,12 +57,15 @@
         if(codeV.intValue==200){
             self.OSSInfo = res[@"data"];
             if(self.OSSInfo){
-                [self initmyAliyunOSS];
                 [UDManager.shareInstance setDDManager:self.OSSInfo key:nkOSSinfo];
+                success(true);
             }
         }
+        else{
+            success(false);
+        }
     } fail:^(NSError * _Nonnull error) {
-        
+        success(false);
     }];
 }
 
@@ -88,13 +86,18 @@
         
         id<OSSCredentialProvider> credentialProvider = [[OSSStsTokenCredentialProvider alloc] initWithAccessKeyId:accessKeyId secretKeyId:accessKeySecret securityToken:securityToken];
         OSSClientConfiguration *cfg = [[OSSClientConfiguration alloc] init];
-        cfg.maxRetryCount = 3;
+        cfg.maxRetryCount = 5;
         cfg.timeoutIntervalForRequest = 15;
         cfg.isHttpdnsEnable = NO;
         cfg.crc64Verifiable = YES;
         
         OSSClient *defaultClient = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credentialProvider clientConfiguration:cfg];
         [OSSManager sharedManager].defaultClient = defaultClient;
+        
+        NSDate *now = [NSDate date];
+        NSTimeInterval trt = [now timeIntervalSince1970];
+        self.initIme = trt;
+       
         //旧的图片服务
 //        OSSClient *defaultImgClient = [[OSSClient alloc] initWithEndpoint:oldimgendpoint credentialProvider:credentialProvider clientConfiguration:cfg];
 //        [OSSManager sharedManager].imageClient = defaultImgClient;
@@ -104,13 +107,40 @@
 
 //普通上传
 - (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
-    if([OSSManager sharedManager].defaultClient==nil){
-        [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
-        [self getOSSInfo];
-        return;
+    
+    if([self chectToken]){
+        if([OSSManager sharedManager].defaultClient==nil){
+            [self getOSSInfo:^(bool code){
+                if(code){
+                    [self initmyAliyunOSS];
+                    [self prasyncPutFile:objectKey localFilePath:filePath thrid:strtime];
+                }
+                else{
+                    [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
+                }
+            }];
+        }
+        else{
+            [self prasyncPutFile:objectKey localFilePath:filePath thrid:strtime];
+        }
     }
+    else{
+        [self getOSSInfo:^(bool code){
+            if(code){
+                [self initmyAliyunOSS];
+                [self prasyncPutFile:objectKey localFilePath:filePath thrid:strtime];
+            }
+            else{
+                [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
+            }
+        }];
+    }
+}
+
+
+-(void)prasyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
+    
     if (![objectKey oss_isNotEmpty]) {
-        NSError *error = [NSError errorWithDomain:NSInvalidArgumentException code:0 userInfo:@{NSLocalizedDescriptionKey: @"objectKey should not be nil"}];
         if(self.delegate){
             NSDictionary *dic=@{
                 @"state":@"3",
@@ -176,14 +206,44 @@
     });
 }
 
+
 //断点续传
 - (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
     
-    if([OSSManager sharedManager].defaultClient==nil){
-        [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
-        [self getOSSInfo];
-        return;
+    
+    if([self chectToken]){
+        if([OSSManager sharedManager].defaultClient==nil){
+            [self getOSSInfo:^(bool code){
+                if(code){
+                    [self initmyAliyunOSS];
+                    [self PrasyncResumableUploadFile:objectKey localFilePath:filePath thrid:strtime];
+                }
+                else{
+                    [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
+                }
+            }];
+        }
+        else{
+            [self PrasyncResumableUploadFile:objectKey localFilePath:filePath thrid:strtime];
+        }
     }
+    else{
+        [self getOSSInfo:^(bool code){
+            if(code){
+                [self initmyAliyunOSS];
+                [self PrasyncResumableUploadFile:objectKey localFilePath:filePath thrid:strtime];
+            }
+            else{
+                [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
+            }
+        }];
+    }
+    
+    
+}
+
+
+-(void)PrasyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
     
     // 获取UploadId上传文件。
     OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
@@ -254,6 +314,8 @@
 
 
 
+
+
 -(void)addUploadTanckobj:(OSSTask *)task thrid:(NSString *)thrid{
     NSDictionary *item = @{
         @"task":task,
@@ -372,5 +434,28 @@
 }
 
 
+-(BOOL)chectToken{
+    
+    if(self.initIme>0){
+        NSDate *now = [NSDate date];
+        NSTimeInterval trt = [now timeIntervalSince1970];
+        NSInteger time = trt;
+        time =time-self.initIme;
+        NSLog(@"chectToken------:%ld",(long)time);
+        if(time>2000){
+            return false;
+        }
+        else{
+            return true;
+        }
+    }
+    else{
+        return false;
+    }
+    
+    return false;
+}
+
+
 
 @end