diff --git a/.env.example b/.env.example index 57379ec3..9e15b488 100644 --- a/.env.example +++ b/.env.example @@ -50,3 +50,13 @@ PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +ALIYUN_OSS_ACCESS_ID = +ALIYUN_OSS_ACCESS_KEY= +ALIYUN_OSS_BUCKET = +ALIYUN_OSS_REGION = +ALIYUN_OSS_ENDPOINT = +ALIYUN_OSS_DOMAIN = +ALIYUN_OSS_USE_SSL = +ALIYUN_OSS_STS_ARN = +ALIYUN_OSS_STS_HOST = diff --git a/app/Admin/Controllers/ArticleController.php b/app/Admin/Controllers/ArticleController.php index dd4d0a41..b5c4e493 100644 --- a/app/Admin/Controllers/ArticleController.php +++ b/app/Admin/Controllers/ArticleController.php @@ -120,7 +120,7 @@ class ArticleController extends AdminController { return Form::make(new Article(), function (Form $form) { $form->display('id'); - $form->select('category_id')->options(ArticleCategory::selectOptions()); + $form->select('category_id')->options(ArticleCategory::selectOptions())->required(); $form->text('title')->required(); // $form->text('author_name'); $form->text('subtitle'); diff --git a/app/Endpoint/Api/Http/Controllers/AliOssController.php b/app/Endpoint/Api/Http/Controllers/AliOssController.php index a4de3f90..275f3cda 100644 --- a/app/Endpoint/Api/Http/Controllers/AliOssController.php +++ b/app/Endpoint/Api/Http/Controllers/AliOssController.php @@ -14,7 +14,8 @@ class AliOssController extends Controller public function sts(Request $request, AliStsService $aliStsService) { return response()->json(array_merge([ - 'bucket'=>config('settings.aliyun_oss_bucket'), - ], $aliStsService->createSts($request->user()->phone))); + 'region_id'=> 'oss-'.config('filesystems.disks.aliyun.region'), + 'bucket'=>config('filesystems.disks.aliyun.bucket'), + ], $aliStsService->createSts($request->user()?->phone))); } } diff --git a/app/Services/AliStsService.php b/app/Services/AliStsService.php index f56fefbf..0f07d0b6 100644 --- a/app/Services/AliStsService.php +++ b/app/Services/AliStsService.php @@ -9,6 +9,25 @@ use Illuminate\Support\Arr; class AliStsService { + protected $accessId; + + protected $accessKey; + + protected $regionId; + + public function __construct() + { + $this->accessId = config('filesystems.disks.aliyun.access_id', ''); + $this->accessKey = config('filesystems.disks.aliyun.access_key', ''); + $this->regionId = config('filesystems.disks.aliyun.region', ''); + + //构建一个阿里云客户端,用于发起请求。 + //构建阿里云客户端时需要设置AccessKey ID和AccessKey Secret。 + AlibabaCloud::accessKeyClient($this->accessId, $this->accessKey) + ->regionId($this->regionId) + ->asDefaultClient(); + } + /** * 创建临时凭证 * @@ -18,11 +37,6 @@ class AliStsService */ public function createSts(string $sessionName, int $expireSeconds = 3600) { - //构建一个阿里云客户端,用于发起请求。 - //构建阿里云客户端时需要设置AccessKey ID和AccessKey Secret。 - AlibabaCloud::accessKeyClient(config('settings.aliyun_oss_access_id'), config('settings.aliyun_oss_access_key')) - ->regionId('cn-chengdu') - ->asDefaultClient(); //设置参数,发起请求。关于参数含义和设置方法,请参见《API参考》。 try { $result = AlibabaCloud::rpc() @@ -31,17 +45,16 @@ class AliStsService ->version('2015-04-01') ->action('AssumeRole') ->method('POST') - ->host('sts.cn-chengdu.aliyuncs.com') + ->host(config('filesystems.disks.aliyun.sts_host')) ->options([ 'query' => [ - 'RegionId' => 'cn-chengdu', - 'RoleArn' => config('settings.aliyun_oss_sts_arn'), + 'RegionId' => $this->regionId, + 'RoleArn' => config('filesystems.disks.aliyun.sts_arn'), 'RoleSessionName' => $sessionName, 'DurationSeconds' => $expireSeconds, ], ]) ->request(); - // dd($result->toArray()); return Arr::get($result->toArray(), 'Credentials', []); } catch (ClientException $e) { report($e); diff --git a/config/admin.php b/config/admin.php index 4dedd667..8b5bff70 100644 --- a/config/admin.php +++ b/config/admin.php @@ -263,7 +263,7 @@ return [ 'upload' => [ // Disk in `config/filesystem.php`. - 'disk' => 'public', + 'disk' => 'aliyun', // Image and file upload path under the disk above. 'directory' => [ diff --git a/config/filesystems.php b/config/filesystems.php index 760ef972..6966f84d 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -53,6 +53,21 @@ return [ 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), ], + 'aliyun' => [ + 'driver' => 'aliyun', + 'access_id' => env('ALIYUN_OSS_ACCESS_ID'), // For example: LTAI4**************qgcsA + 'access_key' => env('ALIYUN_OSS_ACCESS_KEY'), // For example: PkT4F********************Bl9or + 'bucket' => env('ALIYUN_OSS_BUCKET'), // For example: my-storage + 'endpoint' => env('ALIYUN_OSS_ENDPOINT'), // For example: oss-cn-shanghai.aliyuncs.com + 'internal' => env('ALIYUN_OSS_INTERNAL', null), // For example: oss-cn-shanghai-internal.aliyuncs.com + 'domain' => env('ALIYUN_OSS_DOMAIN', null), // For example: oss.my-domain.com + 'use_ssl' => env('ALIYUN_OSS_USE_SSL', false), // Whether to use https + 'region' => env('ALIYUN_OSS_REGION'), + 'prefix' => env('ALIYUN_OSS_PREFIX', null), // The prefix of the store path + 'sts_arn' => env('ALIYUN_OSS_STS_ARN'), + 'sts_host' => env('ALIYUN_OSS_STS_HOST'), + ], + ], /* diff --git a/config/settings.php b/config/settings.php index c6792bf1..0f3c2be3 100644 --- a/config/settings.php +++ b/config/settings.php @@ -4,15 +4,6 @@ return [ // 应用名称 'app_name' => '子春生', - //阿里云OSS信息 - 'aliyun_oss_access_id' => 'LTAI5tFMaynxgZ9aDMNLxpU9', - 'aliyun_oss_access_key' => 'pecJA3LX2sQyWxWDMUUb5NhsMe4Czu', - 'aliyun_oss_bucket' => 'zcs-mall', - 'aliyun_oss_endpoint' => 'oss-cn-chengdu.aliyuncs.com', - 'aliyun_oss_domain' => 'cdn.zichunsheng.cn', - 'aliyun_oss_use_ssl' => true, - 'aliyun_oss_sts_arn' => 'acs:ram::1367535826984495:role/ossstsrole', - // 订单支付过期时间(秒) 'order_payment_expires_at' => 1800, @@ -57,5 +48,6 @@ return [ //app配置 'user_center_is_open'=>true, + 'search_hot_keys' => '搜索热词,分词1,分词2,分词3', ];