Explorar el Código

fix: 修改京东云驱动 使用aws插件

Gosowong hace 2 años
padre
commit
ee194ab467
Se han modificado 1 ficheros con 25 adiciones y 11 borrados
  1. 25 11
      crmeb/crmeb/services/upload/storage/Jdoss.php

+ 25 - 11
crmeb/crmeb/services/upload/storage/Jdoss.php

@@ -2,8 +2,9 @@
 
 
 namespace crmeb\services\upload\storage;
 namespace crmeb\services\upload\storage;
 
 
+use Aws\S3\S3Client;
+use crmeb\exceptions\UploadException;
 use crmeb\services\upload\BaseUpload;
 use crmeb\services\upload\BaseUpload;
-use crmeb\services\upload\extend\jdoss\Client as CrmebClient;
 
 
 /**
 /**
  * 京东云COS文件上传
  * 京东云COS文件上传
@@ -34,7 +35,7 @@ class Jdoss extends BaseUpload
 
 
     /**
     /**
      * 句柄
      * 句柄
-     * @var CrmebClient
+     * @var S3Client
      */
      */
     protected $handle;
     protected $handle;
 
 
@@ -95,17 +96,25 @@ class Jdoss extends BaseUpload
     }
     }
 
 
     /**
     /**
-     * 实例化cos
-     * @return CrmebClient
+     * @return S3Client
+     *
+     * @date 2023/06/05
+     * @author yyw
      */
      */
     protected function app()
     protected function app()
     {
     {
-        $this->handle = new CrmebClient([
-            'accessKey' => $this->accessKey,
-            'secretKey' => $this->secretKey,
+        if (!$this->accessKey || !$this->secretKey) {
+            throw new UploadException(400721);
+        }
+        $this->handle = new S3Client([
+            'version' => 'latest',
             'region' => $this->storageRegion,
             'region' => $this->storageRegion,
-            'bucket' => $this->storageName,
-            'uploadUrl' => $this->uploadUrl
+            'endpoint' => "http://s3.{$this->storageRegion}.jdcloud-oss.com",
+            'signature_version' => 'v4',
+            'credentials' => [
+                'key' => $this->accessKey,
+                'secret' => $this->secretKey,
+            ],
         ]);
         ]);
         return $this->handle;
         return $this->handle;
     }
     }
@@ -147,7 +156,9 @@ class Jdoss extends BaseUpload
         $app = $this->app();
         $app = $this->app();
         //检测桶
         //检测桶
         try {
         try {
-            $app->headBucket($name);
+            $app->headBucket([
+                'Bucket' => $name
+            ]);
         } catch (\Throwable $e) {
         } catch (\Throwable $e) {
             //桶不存在返回404
             //桶不存在返回404
             if (strstr('404', $e->getMessage())) {
             if (strstr('404', $e->getMessage())) {
@@ -156,7 +167,10 @@ class Jdoss extends BaseUpload
         }
         }
         //创建桶
         //创建桶
         try {
         try {
-            $res = $app->createBucket($name, $region, $acl);
+            $res = $app->createBucket([
+                'Bucket' => $name,
+                'ACL' => $acl,
+            ]);
         } catch (\Throwable $e) {
         } catch (\Throwable $e) {
             if (strstr('[curl] 6', $e->getMessage())) {
             if (strstr('[curl] 6', $e->getMessage())) {
                 return $this->setError('COS:无效的区域!!');
                 return $this->setError('COS:无效的区域!!');