xielin 6 роки тому
батько
коміт
566ab6ad49

+ 7 - 2
app/Http/Controllers/Controller.php

@@ -20,7 +20,7 @@ class Controller extends BaseController
         if ($data) {
             if (is_array($data)) {
                 //带有分页格式转换
-                if (isset($data['meta'], $data['data'])) {
+                if (isset($data['meta'])) {
                     // 更改元数据格式,全部包含在data下
                     $temp = array(
                         'data' => array(
@@ -29,8 +29,13 @@ class Controller extends BaseController
                         )
                     );
                     $response = array_merge($response, $temp);
-                } else {
+                } elseif(isset($data['data'])) {
                     $response = array_merge($response, $data);
+                }else{
+                    $temp = array(
+                        'data' => $data
+                    );
+                    $response = array_merge($response, $temp);
                 }
             } else {
                 $response['data'] = $data;

+ 34 - 0
app/Http/Controllers/UploadController.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
+
+class UploadController extends Controller
+{
+    public function uploadImage(Request $request)
+    {
+        if($request->hasFile('image') && $request->file('image')->isValid()){
+            $path = $request->get('path') ? $request->get('path').'/' : date('Ym').'/';
+            //获取文件的原文件名 包括扩展名
+//            $yuanname= $request->file('image')->getClientOriginalName();
+//            //获取文件的扩展名
+            $kuoname=$request->file('image')->getClientOriginalExtension();
+//            //获取文件的类型
+//            $type=$request->file('image')->getClientMimeType();
+//            //获取文件的绝对路径,但是获取到的在本地不能打开
+            $filePath=$request->file('image')->getRealPath();
+            //要保存的文件名 时间+扩展名
+            $filename=time() . '_' . uniqid() .'.'.$kuoname;
+            $imageUrl = Storage::put($path.$filename, file_get_contents($filePath));
+            if($imageUrl){
+                return $this->jsonSuccess(['url' => $path.$filename]);
+            }else{
+                return $this->jsonError('图片上传失败,请重试');
+            }
+        }else{
+            return $this->jsonError('图片上传失败,请重试');
+        }
+    }
+}

+ 1 - 0
bootstrap/app.php

@@ -81,6 +81,7 @@ $app->register(App\Providers\AuthServiceProvider::class);
 
 $app->register(Dingo\Api\Provider\LumenServiceProvider::class);
 $app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
+$app->register(\Junliuxian\AliOSS\AliOssServiceProvider::class);
 
 /*
 |--------------------------------------------------------------------------

+ 1 - 0
composer.json

@@ -8,6 +8,7 @@
         "php": ">=7.1.3",
         "dingo/api": "^2.2",
         "hhxsv5/laravel-s": "~3.4.0",
+        "junliuxian/ali-oss-storage": "~2.0",
         "laravel/lumen-framework": "5.8.*",
         "league/fractal": "^0.17.0",
         "tymon/jwt-auth": "1.0.0-rc.4.1",

+ 1 - 1
config/api.php

@@ -57,7 +57,7 @@ return [
     |
     */
 
-    'prefix' => env('API_PREFIX', 'api'),
+    'prefix' => env('API_PREFIX', '/'),
 
     /*
     |--------------------------------------------------------------------------

+ 82 - 0
config/filesystems.php

@@ -0,0 +1,82 @@
+<?php
+
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Default Filesystem Disk
+    |--------------------------------------------------------------------------
+    |
+    | Here you may specify the default filesystem disk that should be used
+    | by the framework. The "local" disk, as well as a variety of cloud
+    | based disks are available to your application. Just store away!
+    |
+    */
+
+    'default' => env('FILESYSTEM_DRIVER', 'oss'),
+
+    /*
+    |--------------------------------------------------------------------------
+    | Default Cloud Filesystem Disk
+    |--------------------------------------------------------------------------
+    |
+    | Many applications store files both locally and in the cloud. For this
+    | reason, you may specify a default "cloud" driver here. This driver
+    | will be bound as the Cloud disk implementation in the container.
+    |
+    */
+
+    'cloud' => env('FILESYSTEM_CLOUD', 's3'),
+
+    /*
+    |--------------------------------------------------------------------------
+    | Filesystem Disks
+    |--------------------------------------------------------------------------
+    |
+    | Here you may configure as many filesystem "disks" as you wish, and you
+    | may even configure multiple disks of the same driver. Defaults have
+    | been setup for each driver as an example of the required options.
+    |
+    | Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
+    |
+    */
+
+    'disks' => [
+
+        'local' => [
+            'driver' => 'local',
+            'root' => storage_path('app'),
+        ],
+
+        'public' => [
+            'driver' => 'local',
+            'root' => storage_path('app/public'),
+            'url' => env('APP_URL') . '/storage',
+            'visibility' => 'public',
+        ],
+
+        's3' => [
+            'driver' => 's3',
+            'key' => env('AWS_ACCESS_KEY_ID'),
+            'secret' => env('AWS_SECRET_ACCESS_KEY'),
+            'region' => env('AWS_DEFAULT_REGION'),
+            'bucket' => env('AWS_BUCKET'),
+            'url' => env('AWS_URL'),
+        ],
+
+        'oss' => [
+            'driver' => 'oss',
+            'access_id' => 'LTAIGTDKUOVQf2Ln',
+            'access_key' => 'HzY9r2gDPbURQ0Vp69A7THV0RmxMkb',
+            'bucket' => 'rainbowstar',
+            'endpoint' => 'oss-cn-zhangjiakou.aliyuncs.com', // OSS 外网节点或自定义外部域名
+//            'endpoint_internal' => '<internal endpoint [OSS内网节点] 如:oss-cn-shenzhen-internal.aliyuncs.com>', // v2.0.4 新增配置属性,如果为空,则默认使用 endpoint 配置(由于内网上传有点小问题未解决,请大家暂时不要使用内网节点上传,正在与阿里技术沟通中)
+            'cdnDomain' => '', // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn
+            'ssl' => false, // true to use 'https://' and false to use 'http://'. default is false,
+            'isCName' => false, // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url, false: 则使用外部节点生成url
+            'debug' => true,
+        ],
+
+    ],
+
+];

+ 1 - 1
config/laravels.php

@@ -8,7 +8,7 @@ return [
     'listen_port'              => env('LARAVELS_LISTEN_PORT', 18208),
     'socket_type'              => defined('SWOOLE_SOCK_TCP') ? SWOOLE_SOCK_TCP : 1,
     'enable_coroutine_runtime' => false,
-    'server'                   => env('LARAVELS_SERVER', 'LaravelS'),
+    'server'                   => env('LARAVELS_SERVER', 'config-service'),
     'handle_static'            => env('LARAVELS_HANDLE_STATIC', false),
     'laravel_base_path'        => env('LARAVEL_BASE_PATH', base_path()),
     'inotify_reload'           => [

+ 1 - 25
routes/api.php

@@ -16,31 +16,7 @@ $api = app('Dingo\Api\Routing\Router');
 $api->version('v1', [
     'namespace' => 'App\Http\Controllers',
 ], function ($api) {
-    //登录
-    $api->post('login', 'AuthController@authenticate');
-    //测试签名
-    $api->post('sign', 'IndexController@index4');
-    //测试支付宝 支付
-    $api->post('alipay', 'AlipayController@index');
-    //回调
-    $api->post('return', 'AlipayController@return');
-    //异步回调
-    $api->post('notify', 'AlipayController@notify');
-    //测试微信支付
-    $api->post('weixin', 'WeixinPayController@index');
-    //微信回调
-    $api->post('wxin_notify', 'WeixinPayController@notify');
-
-
-
-    $api->group(['middleware' => 'auth:api'], function ($api) {
-        //登出
-        $api->post('logout', 'AuthController@logout');
-        //刷新身份令牌
-        $api->post('refresh', 'AuthController@refresh');
-        //测试
-        $api->post('products', 'ProductsController@index');
-    });
+    $api->post('upload', 'UploadController@uploadImage');
 
     $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
         $api->get('user', 'IndexController@index');