Просмотр исходного кода

fix: 修改华为云和天翼云

Gosowong 2 лет назад
Родитель
Сommit
3fc91fdf9f

+ 1 - 0
crmeb/crmeb/services/upload/Upload.php

@@ -21,6 +21,7 @@ use think\facade\Config;
  * @mixin \crmeb\services\upload\storage\COS
  * @mixin \crmeb\services\upload\storage\Qiniu
  * @mixin \crmeb\services\upload\storage\Jdoss
+ * @mixin \crmeb\services\upload\storage\Tyoss
  */
 class Upload extends BaseManager
 {

+ 2 - 1
crmeb/crmeb/services/upload/extend/obs/Client.php

@@ -368,7 +368,8 @@ class Client extends BaseClient
      */
     protected function getRequestUrl(string $bucket, string $region)
     {
-        return $bucket . '.obs.' . $region . '.myhuaweicloud.com';
+//        return $bucket . '.obs.' . $region . '.myhuaweicloud.com';  // 华为
+        return $bucket . '.obs.' . $region . '.ctyun.cn';  // 天翼
     }
 
     /**

+ 30 - 76
crmeb/crmeb/services/upload/storage/Obs.php

@@ -160,15 +160,6 @@ class Obs extends BaseUpload
         }
         $this->storageRegion = $region;
         $app = $this->app();
-        //检测桶
-        try {
-            $app->headBucket($name, $region);
-        } catch (\Throwable $e) {
-            //桶不存在返回404
-            if (strstr('404', $e->getMessage())) {
-                return $this->setError('COS:' . $e->getMessage());
-            }
-        }
         //创建桶
         try {
             $res = $app->createBucket($name, $region, $acl);
@@ -185,72 +176,7 @@ class Obs extends BaseUpload
 
     public function getRegion()
     {
-        return [
-            [
-                'value' => 'oos-hazz',
-                'label' => '郑州'
-            ],
-            [
-                'value' => 'oos-lnsy',
-                'label' => '沈阳'
-            ],
-            [
-                'value' => 'oos-sccd',
-                'label' => '四川成都'
-            ],
-            [
-                'value' => 'oos-xjwlmq',
-                'label' => '乌鲁木齐'
-            ],
-            [
-                'value' => 'oos-xjwlmq',
-                'label' => '乌鲁木齐'
-            ],
-            [
-                'value' => 'oos-gslz',
-                'label' => '甘肃兰州'
-            ],
-            [
-                'value' => 'oos-sdqd',
-                'label' => '山东青岛'
-            ],
-            [
-                'value' => 'oos-gzgy',
-                'label' => '贵州贵阳'
-            ],
-            [
-                'value' => 'oos-hbwh',
-                'label' => '湖北武汉'
-            ],
-            [
-                'value' => 'oos-xzls',
-                'label' => '西藏拉萨'
-            ],
-            [
-                'value' => 'oos-hbwh',
-                'label' => '湖北武汉'
-            ],
-            [
-                'value' => 'oos-ahwh',
-                'label' => '安徽芜湖'
-            ],
-            [
-                'value' => 'oos-gdsz',
-                'label' => '广东深圳'
-            ],
-            [
-                'value' => 'oos-jssz',
-                'label' => '江苏苏州'
-            ],
-            [
-                'value' => 'oos-sh2',
-                'label' => '上海2'
-            ],
-            [
-                'value' => 'cn-snxy1',
-                'label' => '西安2'
-            ]
-        ];
+        return $this->app()->getRegion();
     }
 
     public function deleteBucket(string $name, string $region = '')
@@ -263,9 +189,37 @@ class Obs extends BaseUpload
         }
     }
 
+    public function getDomian($name, $region)
+    {
+        try {
+            $res = $this->app()->GetBucketDomain($name, $region);
+            $domainRules = $res->toArray()['ListBucketCustomDomainsResult '];
+            return array_column($domainRules, 'Name');
+        } catch (\Throwable $e) {
+        }
+        return [];
+    }
+
     public function bindDomian(string $name, string $domain, string $region = null)
     {
-        // TODO: Implement bindDomian() method.
+        $parseDomin = parse_url($domain);
+        try {
+            $res = $this->app()->putBucketDomain($name, '', [
+                'domainname' => $parseDomin['host'],
+            ]);
+            if (method_exists($res, 'toArray')) {
+                $res = $res->toArray();
+            }
+            if ($res['RequestId'] ?? null) {
+                return true;
+            }
+        } catch (\Throwable $e) {
+            if ($message = $this->setMessage($e->getMessage())) {
+                return $this->setError($message);
+            }
+            return $this->setError($e->getMessage());
+        }
+        return false;
     }
 
     public function setBucketCors(string $name, string $region)

+ 4 - 14
crmeb/crmeb/services/upload/storage/Tyoss.php

@@ -160,24 +160,10 @@ class Tyoss extends BaseUpload
         }
         $this->storageRegion = $region;
         $app = $this->app();
-        //检测桶
-        try {
-            $app->headBucket($name, $region);
-        } catch (\Throwable $e) {
-            //桶不存在返回404
-            if (strstr('404', $e->getMessage())) {
-                return $this->setError('COS:' . $e->getMessage());
-            }
-        }
         //创建桶
         try {
             $res = $app->createBucket($name, $region, $acl);
         } catch (\Throwable $e) {
-            if (strstr('[curl] 6', $e->getMessage())) {
-                return $this->setError('COS:无效的区域!!');
-            } else if (strstr('Access Denied.', $e->getMessage())) {
-                return $this->setError('COS:无权访问');
-            }
             return $this->setError('COS:' . $e->getMessage());
         }
         return $res;
@@ -245,6 +231,10 @@ class Tyoss extends BaseUpload
             [
                 'value' => 'oos-sh2',
                 'label' => '上海2'
+            ],
+            [
+                'value' => 'cn-snxy1',
+                'label' => '西安2'
             ]
         ];
     }