cqpCow 8 bulan lalu
induk
melakukan
6f56151296
2 mengubah file dengan 6 tambahan dan 6 penghapusan
  1. 3 3
      app/Service/FileUploadService.php
  2. 3 3
      app/Service/OssService.php

+ 3 - 3
app/Service/FileUploadService.php

@@ -51,7 +51,7 @@ class FileUploadService extends Service
     }
 
     //获取文件的位置oss
-    public function getFileShow($file_name){
+    public function getFileShow($file_name,$expired = 3500){
         $path = "";
         if(empty($file_name)) return $path;
 
@@ -62,12 +62,12 @@ class FileUploadService extends Service
             $date = \DateTime::createFromFormat('Ymd', $timestamp);
             $date = $date->format('Y-m-d');
             $savePath = $document . $date . '/' . $file_name;
-            list($status,$path) = (new OssService())->getTemporaryUrl($savePath);
+            list($status,$path) = (new OssService())->getTemporaryUrl($savePath,$expired);
         }else{
             if(strpos($file_name, FileUploadService::string) !== false){
                 $file_name = str_replace(FileUploadService::string ,'', $file_name);
                 $savePath = $document . 'old/upload_files/' . $file_name;
-                list($status,$path) = (new OssService())->getTemporaryUrl($savePath);
+                list($status,$path) = (new OssService())->getTemporaryUrl($savePath,$expired);
             }
         }
 

+ 3 - 3
app/Service/OssService.php

@@ -73,7 +73,7 @@ class OssService extends Service
     }
 
     //生成临时文件
-    public function getTemporaryUrl($objectKey)
+    public function getTemporaryUrl($objectKey, $expired = 3500)
     {
         $timeStamp = time();
 
@@ -94,7 +94,7 @@ class OssService extends Service
             $url = $this->createUrl($objectKey);
             $set = [
                 'url' => $url,
-                'timestamp' => $timeStamp + 3500,
+                'timestamp' => $timeStamp + $expired,
             ];
             file_put_contents($localFilePath, json_encode($set));
         }else{
@@ -104,7 +104,7 @@ class OssService extends Service
                 $url = $this->createUrl($objectKey);
                 $set = [
                     'url' => $url,
-                    'timestamp' => $timeStamp + 3500,
+                    'timestamp' => $timeStamp + $expired,
                 ];
                 file_put_contents($localFilePath, json_encode($set));
             }else{