xiaogang 4 سال پیش
والد
کامیت
a22ea72da3
6فایلهای تغییر یافته به همراه120 افزوده شده و 168 حذف شده
  1. 3 5
      app/Http/Controllers/Api/UploadController.php
  2. 0 161
      app/Services/OSS.php
  3. 1 1
      app/Services/PayService.php
  4. 1 0
      composer.json
  5. 113 1
      composer.lock
  6. 2 0
      config/app.php

+ 3 - 5
app/Http/Controllers/Api/UploadController.php

xqd xqd xqd
@@ -3,9 +3,8 @@
 
 namespace App\Http\Controllers\Api;
 
-
-use App\Services\OSS;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
 
 class UploadController extends Controller
 {
@@ -14,7 +13,6 @@ class UploadController extends Controller
         try {
             //获取上传的文件
             $file = $request->file('file');
-
             //获取上传图片的临时地址
             $tmppath = $file->getRealPath();
             //生成文件名
@@ -23,9 +21,9 @@ class UploadController extends Controller
             $pathName = 'chengluApp/'.date('Y-m/d').'/'.$fileName;
 
             //上传图片到阿里云OSS
-            OSS::publicUpload(env('ALI_OSS_BUCKET'), $pathName, $tmppath, ['ContentType' => $file->getClientMimeType()]);
+            Storage::putRemoteFile($pathName, $tmppath);
             //获取上传图片的Url链接
-            $Url = OSS::getPublicObjectURL(env('ALI_OSS_BUCKET'), $pathName);
+            $Url = Storage::url($pathName);
         }catch (\Exception $exception){
             return $this->response->errorForbidden($exception->getMessage());
         }

+ 0 - 161
app/Services/OSS.php

xqd
@@ -1,161 +0,0 @@
-<?php
-namespace App\Services;
-use Exception;
-use DateTime;
-use JohnLui\AliyunOSS;
-
-class OSS {
-    /* 城市名称:
-     *
-     *  经典网络下可选:杭州、上海、青岛、北京、张家口、深圳、香港、硅谷、弗吉尼亚、新加坡、悉尼、日本、法兰克福、迪拜
-     *  VPC 网络下可选:杭州、上海、青岛、北京、张家口、深圳、硅谷、弗吉尼亚、新加坡、悉尼、日本、法兰克福、迪拜
-     */
-    private $city = '杭州';
-    // 经典网络 or VPC
-    private $networkType = '经典网络';
-
-    private $AccessKeyId = "";
-    private $AccessKeySecret = "";
-    private $ossClient;
-    /**
-     * 私有初始化 API,非 API,不用关注
-     * @param boolean 是否使用内网
-     */
-    public function __construct($isInternal = false)
-    {
-        if ($this->networkType == 'VPC' && !$isInternal) {
-            throw new Exception("VPC 网络下不提供外网上传、下载等功能");
-        }
-        $this->ossClient = AliyunOSS::boot(
-            $this->city,
-            $this->networkType,
-            $isInternal,
-            env('ALI_OSS_ACCESS_ID'),
-            env('ALI_OSS_ACCESS_KEY')
-        );
-    }
-    /**
-     * 使用外网上传文件
-     * @param  string bucket名称
-     * @param  string 上传之后的 OSS object 名称
-     * @param  string 上传文件路径
-     * @return boolean 上传是否成功
-     */
-    public static function publicUpload($bucketName, $ossKey, $filePath, $options = [])
-    {
-        $oss = new OSS();
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->uploadFile($ossKey, $filePath, $options);
-    }
-    /**
-     * 使用阿里云内网上传文件
-     * @param  string bucket名称
-     * @param  string 上传之后的 OSS object 名称
-     * @param  string 上传文件路径
-     * @return boolean 上传是否成功
-     */
-    public static function privateUpload($bucketName, $ossKey, $filePath, $options = [])
-    {
-        $oss = new OSS(true);
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->uploadFile($ossKey, $filePath, $options);
-    }
-    /**
-     * 使用外网直接上传变量内容
-     * @param  string bucket名称
-     * @param  string 上传之后的 OSS object 名称
-     * @param  string 上传的变量
-     * @return boolean 上传是否成功
-     */
-    public static function publicUploadContent($bucketName, $ossKey, $content, $options = [])
-    {
-        $oss = new OSS();
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->uploadContent($ossKey, $content, $options);
-    }
-    /**
-     * 使用阿里云内网直接上传变量内容
-     * @param  string bucket名称
-     * @param  string 上传之后的 OSS object 名称
-     * @param  string 上传的变量
-     * @return boolean 上传是否成功
-     */
-    public static function privateUploadContent($bucketName, $ossKey, $content, $options = [])
-    {
-        $oss = new OSS(true);
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->uploadContent($ossKey, $content, $options);
-    }
-    /**
-     * 使用外网删除文件
-     * @param  string bucket名称
-     * @param  string 目标 OSS object 名称
-     * @return boolean 删除是否成功
-     */
-    public static function publicDeleteObject($bucketName, $ossKey)
-    {
-        $oss = new OSS();
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->deleteObject($bucketName, $ossKey);
-    }
-    /**
-     * 使用阿里云内网删除文件
-     * @param  string bucket名称
-     * @param  string 目标 OSS object 名称
-     * @return boolean 删除是否成功
-     */
-    public static function privateDeleteObject($bucketName, $ossKey)
-    {
-        $oss = new OSS(true);
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->deleteObject($bucketName, $ossKey);
-    }
-    /**
-     * -------------------------------------------------
-     *
-     *
-     *  下面不再分公网内网出 API,也不注释了,大家自行体会吧。。。
-     *
-     *
-     * -------------------------------------------------
-     */
-    public function copyObject($sourceBuckt, $sourceKey, $destBucket, $destKey)
-    {
-        $oss = new OSS();
-        return $oss->ossClient->copyObject($sourceBuckt, $sourceKey, $destBucket, $destKey);
-    }
-    public function moveObject($sourceBuckt, $sourceKey, $destBucket, $destKey)
-    {
-        $oss = new OSS();
-        return $oss->ossClient->moveObject($sourceBuckt, $sourceKey, $destBucket, $destKey);
-    }
-    // 获取公开文件的 URL
-    public static function getPublicObjectURL($bucketName, $ossKey)
-    {
-        $oss = new OSS();
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->getPublicUrl($ossKey);
-    }
-    // 获取私有文件的URL,并设定过期时间,如 \DateTime('+1 day')
-    public static function getPrivateObjectURLWithExpireTime($bucketName, $ossKey, DateTime $expire_time)
-    {
-        $oss = new OSS();
-        $oss->ossClient->setBucket($bucketName);
-        return $oss->ossClient->getUrl($ossKey, $expire_time);
-    }
-    public static function createBucket($bucketName)
-    {
-        $oss = new OSS();
-        return $oss->ossClient->createBucket($bucketName);
-    }
-    public static function getAllObjectKey($bucketName)
-    {
-        $oss = new OSS();
-        return $oss->ossClient->getAllObjectKey($bucketName);
-    }
-    public static function getObjectMeta($bucketName, $ossKey)
-    {
-        $oss = new OSS();
-        return $oss->ossClient->getObjectMeta($bucketName, $ossKey);
-    }
-}

+ 1 - 1
app/Services/PayService.php

xqd
@@ -36,7 +36,7 @@ class PayService
     public static function wx_config(){
         $config = [
             'appid' => 'wxb3fxxxxxxxxxxx', // APP APPID
-            'app_id' => 'wxb3fxxxxxxxxxxx', // 公众号 APPID
+            //'app_id' => 'wxb3fxxxxxxxxxxx', // 公众号 APPID
             //'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
             'mch_id' => '145776xxxx',
             'key' => 'mF2suE9sU6Mk1CxxxxIxxxxx',

+ 1 - 0
composer.json

xqd
@@ -12,6 +12,7 @@
         "fideloper/proxy": "^4.4",
         "fruitcake/laravel-cors": "^2.0",
         "guzzlehttp/guzzle": "^7.0.1",
+        "jacobcyl/ali-oss-storage": "2.1",
         "laravel/framework": "^8.40",
         "laravel/tinker": "^2.5",
         "liyu/dingo-serializer-switch": "^0.3.2",

+ 113 - 1
composer.lock

xqd xqd
@@ -4,8 +4,59 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "1cedd7f6b4a9a52ab91315cb7a09b0a2",
+    "content-hash": "f3829b02f8675b9295af662a517408f8",
     "packages": [
+        {
+            "name": "aliyuncs/oss-sdk-php",
+            "version": "v2.4.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/aliyun/aliyun-oss-php-sdk.git",
+                "reference": "0c9d902c33847c07efc66c4cdf823deaea8fc2b6"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/aliyun/aliyun-oss-php-sdk/zipball/0c9d902c33847c07efc66c4cdf823deaea8fc2b6",
+                "reference": "0c9d902c33847c07efc66c4cdf823deaea8fc2b6",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.3"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "*",
+                "satooshi/php-coveralls": "*"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "OSS\\": "src/OSS"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Aliyuncs",
+                    "homepage": "http://www.aliyun.com"
+                }
+            ],
+            "description": "Aliyun OSS SDK for PHP",
+            "homepage": "http://www.aliyun.com/product/oss/",
+            "support": {
+                "issues": "https://github.com/aliyun/aliyun-oss-php-sdk/issues",
+                "source": "https://github.com/aliyun/aliyun-oss-php-sdk/tree/v2.4.2"
+            },
+            "time": "2021-06-04T06:55:06+00:00"
+        },
         {
             "name": "asm89/stack-cors",
             "version": "v2.0.3",
@@ -1320,6 +1371,67 @@
             },
             "time": "2021-04-26T09:17:50+00:00"
         },
+        {
+            "name": "jacobcyl/ali-oss-storage",
+            "version": "2.1.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/jacobcyl/Aliyun-oss-storage.git",
+                "reference": "c0cb9ba1d3faf22a1e04a03602aac90a187b5959"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/jacobcyl/Aliyun-oss-storage/zipball/c0cb9ba1d3faf22a1e04a03602aac90a187b5959",
+                "reference": "c0cb9ba1d3faf22a1e04a03602aac90a187b5959",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "aliyuncs/oss-sdk-php": "~2.0"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Jacobcyl\\AliOSS\\AliOssServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Jacobcyl\\AliOSS\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "jacobcyl",
+                    "email": "cyl.jacob@gmail.com"
+                }
+            ],
+            "description": "aliyun oss filesystem storage for laravel 5+",
+            "homepage": "http://jacobcyl.github.io/Aliyun-oss-storage/",
+            "keywords": [
+                "aliyun",
+                "filesystems",
+                "laravel",
+                "oss",
+                "storage"
+            ],
+            "support": {
+                "issues": "https://github.com/jacobcyl/Aliyun-oss-storage/issues",
+                "source": "https://github.com/jacobcyl/Aliyun-oss-storage/tree/2.1.0"
+            },
+            "time": "2018-04-02T03:44:01+00:00"
+        },
         {
             "name": "laravel/framework",
             "version": "v8.48.1",

+ 2 - 0
config/app.php

xqd
@@ -175,6 +175,8 @@ return [
         App\Providers\EventServiceProvider::class,
         App\Providers\RouteServiceProvider::class,
         Dingo\Api\Provider\LaravelServiceProvider::class,
+
+        Jacobcyl\AliOSS\AliOssServiceProvider::class,
     ],
 
     /*