rkljw 3 months ago
parent
commit
6a2f2bfc42
6 changed files with 327 additions and 2 deletions
  1. 2 1
      .env
  2. 37 0
      app/Controller/MinioController.php
  3. 65 0
      app/Service/MinioService.php
  4. 1 0
      composer.json
  5. 219 1
      composer.lock
  6. 3 0
      config/api/public.php

+ 2 - 1
.env

@@ -35,4 +35,5 @@ WECHAT = https://api.weixin.qq.com/
 APPID = wx830ada852dd1707f
 #小程序SECRET
 APP_SECRET = 09d1ac9287cb6f3c5e81aa27a6b7138e
-#12
+#12
+ENDPOINT =http://123.57.1.253:9527

+ 37 - 0
app/Controller/MinioController.php

@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Controller;
+
+use App\Service\MinioService;
+use Hyperf\HttpServer\Annotation\Controller;
+use Hyperf\HttpServer\Annotation\RequestMapping;
+use Psr\Http\Message\ResponseInterface;
+use function Sodium\version_string;
+
+
+class MinioController extends AbstractController
+{
+    /**
+     * @Inject
+     * @var MinioService
+     */
+    protected $minioService;
+
+    /**
+     * 获取所有MinIO存储桶列表
+     *
+     * @RequestMapping(path="buckets", methods="get")
+     */
+    public function listBuckets()
+    {
+        var_dump("====");
+        $a = new MinioService();
+        // 调用服务层的方法获取存储桶列表
+        $bucketsResponse =$a->listBuckets();
+        var_dump("试试:",$bucketsResponse);
+        // 直接返回服务层生成的响应
+        return $bucketsResponse;
+    }
+}

+ 65 - 0
app/Service/MinioService.php

@@ -0,0 +1,65 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Service;
+
+use Aws\S3\S3Client;
+use Hyperf\Di\Annotation\Inject;
+use Hyperf\HttpServer\Annotation\Controller;
+use Hyperf\HttpServer\Annotation\RequestMapping;
+use Hyperf\HttpServer\Contract\ResponseInterface;
+use function Hyperf\Support\env;
+class MinioService
+{
+    /**
+     * @Inject
+     * @var ResponseInterface
+     */
+    protected $response;
+
+    public function listBuckets()
+    {
+        // MinIO 配置
+        $config = [
+            'version' => 'latest',
+            'region'  => 'us-east-1', // 对于MinIO,这个参数通常不重要,但SDK可能需要它
+            'endpoint' => env("ENDPOINT"), // 替换为您的MinIO服务器地址
+            'use_path_style_endpoint' => true, // 对于MinIO,通常需要将此设置为true
+            'credentials' => [
+                'key'    => 'Kr2gB8Lo3nRvm39naO43',
+                'secret' => '2cPcnAOs3YKiLEMonx62uRN3Ep4u1HYPeSNv1HzG',
+            ],
+        ];
+        var_dump("配置信息:",$config);
+        // 创建 MinIO 客户端
+        $minioClient = new S3Client($config);
+//        var_dump("连接:",$minioClient);
+        try {
+            // 获取所有存储桶列表
+            $result = $minioClient->listBuckets();
+            var_dump($result);
+            // 提取存储桶名称
+            $buckets = array_column($result['Buckets'], 'Name');
+
+            // 返回响应
+            return $this->response->json([
+                'success' => true,
+                'buckets' => $buckets,
+            ]);
+        } catch (\Aws\Exception\AwsException $e) {
+            var_dump("错误:",$e->getMessage());
+            // 处理AWS异常
+            return $this->response->withStatus(500)->json([
+                'success' => false,
+                'error' => $e->getMessage(),
+            ]);
+        } catch (\Exception $e) {
+            // 处理其他异常
+            return $this->response->withStatus(500)->json([
+                'success' => false,
+                'error' => 'An unexpected error occurred: ' . $e->getMessage(),
+            ]);
+        }
+    }
+}

+ 1 - 0
composer.json

@@ -13,6 +13,7 @@
     "license": "Apache-2.0",
     "require": {
         "php": ">=8.1",
+        "aws/aws-sdk-php": "^3.336",
         "death_satan/hyperf-validate": "^3.71",
         "doctrine/annotations": "^2.0",
         "easyswoole/verifycode": "3.x",

+ 219 - 1
composer.lock

@@ -4,8 +4,160 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "52cb6d820556611bfba432f00741d784",
+    "content-hash": "1720e871d24f37be6d7a2842f61de2fc",
     "packages": [
+        {
+            "name": "aws/aws-crt-php",
+            "version": "v1.2.7",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/awslabs/aws-crt-php.git",
+                "reference": "d71d9906c7bb63a28295447ba12e74723bd3730e"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/awslabs/aws-crt-php/zipball/d71d9906c7bb63a28295447ba12e74723bd3730e",
+                "reference": "d71d9906c7bb63a28295447ba12e74723bd3730e",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.5"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35||^5.6.3||^9.5",
+                "yoast/phpunit-polyfills": "^1.0"
+            },
+            "suggest": {
+                "ext-awscrt": "Make sure you install awscrt native extension to use any of the functionality."
+            },
+            "type": "library",
+            "autoload": {
+                "classmap": [
+                    "src/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "AWS SDK Common Runtime Team",
+                    "email": "aws-sdk-common-runtime@amazon.com"
+                }
+            ],
+            "description": "AWS Common Runtime for PHP",
+            "homepage": "https://github.com/awslabs/aws-crt-php",
+            "keywords": [
+                "amazon",
+                "aws",
+                "crt",
+                "sdk"
+            ],
+            "support": {
+                "issues": "https://github.com/awslabs/aws-crt-php/issues",
+                "source": "https://github.com/awslabs/aws-crt-php/tree/v1.2.7"
+            },
+            "time": "2024-10-18T22:15:13+00:00"
+        },
+        {
+            "name": "aws/aws-sdk-php",
+            "version": "3.336.6",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/aws/aws-sdk-php.git",
+                "reference": "0a99dab427f0a1c082775301141aeac3558691ad"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/0a99dab427f0a1c082775301141aeac3558691ad",
+                "reference": "0a99dab427f0a1c082775301141aeac3558691ad",
+                "shasum": ""
+            },
+            "require": {
+                "aws/aws-crt-php": "^1.2.3",
+                "ext-json": "*",
+                "ext-pcre": "*",
+                "ext-simplexml": "*",
+                "guzzlehttp/guzzle": "^6.5.8 || ^7.4.5",
+                "guzzlehttp/promises": "^1.4.0 || ^2.0",
+                "guzzlehttp/psr7": "^1.9.1 || ^2.4.5",
+                "mtdowling/jmespath.php": "^2.6",
+                "php": ">=7.2.5",
+                "psr/http-message": "^1.0 || ^2.0"
+            },
+            "require-dev": {
+                "andrewsville/php-token-reflection": "^1.4",
+                "aws/aws-php-sns-message-validator": "~1.0",
+                "behat/behat": "~3.0",
+                "composer/composer": "^1.10.22",
+                "dms/phpunit-arraysubset-asserts": "^0.4.0",
+                "doctrine/cache": "~1.4",
+                "ext-dom": "*",
+                "ext-openssl": "*",
+                "ext-pcntl": "*",
+                "ext-sockets": "*",
+                "nette/neon": "^2.3",
+                "paragonie/random_compat": ">= 2",
+                "phpunit/phpunit": "^5.6.3 || ^8.5 || ^9.5",
+                "psr/cache": "^1.0 || ^2.0 || ^3.0",
+                "psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
+                "sebastian/comparator": "^1.2.3 || ^4.0",
+                "yoast/phpunit-polyfills": "^1.0"
+            },
+            "suggest": {
+                "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications",
+                "doctrine/cache": "To use the DoctrineCacheAdapter",
+                "ext-curl": "To send requests using cURL",
+                "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
+                "ext-sockets": "To use client-side monitoring"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.0-dev"
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src/functions.php"
+                ],
+                "psr-4": {
+                    "Aws\\": "src/"
+                },
+                "exclude-from-classmap": [
+                    "src/data/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "Amazon Web Services",
+                    "homepage": "http://aws.amazon.com"
+                }
+            ],
+            "description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project",
+            "homepage": "http://aws.amazon.com/sdkforphp",
+            "keywords": [
+                "amazon",
+                "aws",
+                "cloud",
+                "dynamodb",
+                "ec2",
+                "glacier",
+                "s3",
+                "sdk"
+            ],
+            "support": {
+                "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
+                "issues": "https://github.com/aws/aws-sdk-php/issues",
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.336.6"
+            },
+            "time": "2024-12-28T04:16:13+00:00"
+        },
         {
             "name": "carbonphp/carbon-doctrine-types",
             "version": "3.2.0",
@@ -5538,6 +5690,72 @@
             ],
             "time": "2024-12-05T17:15:07+00:00"
         },
+        {
+            "name": "mtdowling/jmespath.php",
+            "version": "2.8.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/jmespath/jmespath.php.git",
+                "reference": "a2a865e05d5f420b50cc2f85bb78d565db12a6bc"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/a2a865e05d5f420b50cc2f85bb78d565db12a6bc",
+                "reference": "a2a865e05d5f420b50cc2f85bb78d565db12a6bc",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.2.5 || ^8.0",
+                "symfony/polyfill-mbstring": "^1.17"
+            },
+            "require-dev": {
+                "composer/xdebug-handler": "^3.0.3",
+                "phpunit/phpunit": "^8.5.33"
+            },
+            "bin": [
+                "bin/jp.php"
+            ],
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.8-dev"
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src/JmesPath.php"
+                ],
+                "psr-4": {
+                    "JmesPath\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Graham Campbell",
+                    "email": "hello@gjcampbell.co.uk",
+                    "homepage": "https://github.com/GrahamCampbell"
+                },
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                }
+            ],
+            "description": "Declaratively specify how to extract elements from a JSON document",
+            "keywords": [
+                "json",
+                "jsonpath"
+            ],
+            "support": {
+                "issues": "https://github.com/jmespath/jmespath.php/issues",
+                "source": "https://github.com/jmespath/jmespath.php/tree/2.8.0"
+            },
+            "time": "2024-09-04T18:46:31+00:00"
+        },
         {
             "name": "nesbot/carbon",
             "version": "2.72.5",

+ 3 - 0
config/api/public.php

@@ -4,6 +4,7 @@ declare (strict_types = 1);
 use App\Controller\PublicController;
 use App\Middleware\Auth\FooMiddleware;
 use Hyperf\HttpServer\Router\Router;
+use App\Controller\MinioController;
 
 Router::addRoute(['GET', 'POST'], '/verifyCode', 'App\Controller\IndexController@verifyCode');
 
@@ -57,5 +58,7 @@ Router::addGroup(
         Router::get('/getLetterType', [PublicController::class, 'getLetterType']);
         //获取子类型
         Router::get('/getLetterTypeChildren', [PublicController::class, 'getLetterTypeChildren']);
+
+        Router::post('/buckets', [MinioController::class, 'listBuckets']);
     }
 );