添加阿里云OSS上传配置
parent
97ffed1d49
commit
0c644ac8dc
10
.env.example
10
.env.example
|
|
@ -50,3 +50,13 @@ PUSHER_APP_CLUSTER=mt1
|
||||||
|
|
||||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
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 =
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class ArticleController extends AdminController
|
||||||
{
|
{
|
||||||
return Form::make(new Article(), function (Form $form) {
|
return Form::make(new Article(), function (Form $form) {
|
||||||
$form->display('id');
|
$form->display('id');
|
||||||
$form->select('category_id')->options(ArticleCategory::selectOptions());
|
$form->select('category_id')->options(ArticleCategory::selectOptions())->required();
|
||||||
$form->text('title')->required();
|
$form->text('title')->required();
|
||||||
// $form->text('author_name');
|
// $form->text('author_name');
|
||||||
$form->text('subtitle');
|
$form->text('subtitle');
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ class AliOssController extends Controller
|
||||||
public function sts(Request $request, AliStsService $aliStsService)
|
public function sts(Request $request, AliStsService $aliStsService)
|
||||||
{
|
{
|
||||||
return response()->json(array_merge([
|
return response()->json(array_merge([
|
||||||
'bucket'=>config('settings.aliyun_oss_bucket'),
|
'region_id'=> 'oss-'.config('filesystems.disks.aliyun.region'),
|
||||||
], $aliStsService->createSts($request->user()->phone)));
|
'bucket'=>config('filesystems.disks.aliyun.bucket'),
|
||||||
|
], $aliStsService->createSts($request->user()?->phone)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,25 @@ use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class AliStsService
|
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)
|
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参考》。
|
//设置参数,发起请求。关于参数含义和设置方法,请参见《API参考》。
|
||||||
try {
|
try {
|
||||||
$result = AlibabaCloud::rpc()
|
$result = AlibabaCloud::rpc()
|
||||||
|
|
@ -31,17 +45,16 @@ class AliStsService
|
||||||
->version('2015-04-01')
|
->version('2015-04-01')
|
||||||
->action('AssumeRole')
|
->action('AssumeRole')
|
||||||
->method('POST')
|
->method('POST')
|
||||||
->host('sts.cn-chengdu.aliyuncs.com')
|
->host(config('filesystems.disks.aliyun.sts_host'))
|
||||||
->options([
|
->options([
|
||||||
'query' => [
|
'query' => [
|
||||||
'RegionId' => 'cn-chengdu',
|
'RegionId' => $this->regionId,
|
||||||
'RoleArn' => config('settings.aliyun_oss_sts_arn'),
|
'RoleArn' => config('filesystems.disks.aliyun.sts_arn'),
|
||||||
'RoleSessionName' => $sessionName,
|
'RoleSessionName' => $sessionName,
|
||||||
'DurationSeconds' => $expireSeconds,
|
'DurationSeconds' => $expireSeconds,
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
->request();
|
->request();
|
||||||
// dd($result->toArray());
|
|
||||||
return Arr::get($result->toArray(), 'Credentials', []);
|
return Arr::get($result->toArray(), 'Credentials', []);
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
report($e);
|
report($e);
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ return [
|
||||||
'upload' => [
|
'upload' => [
|
||||||
|
|
||||||
// Disk in `config/filesystem.php`.
|
// Disk in `config/filesystem.php`.
|
||||||
'disk' => 'public',
|
'disk' => 'aliyun',
|
||||||
|
|
||||||
// Image and file upload path under the disk above.
|
// Image and file upload path under the disk above.
|
||||||
'directory' => [
|
'directory' => [
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,21 @@ return [
|
||||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
'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'),
|
||||||
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,6 @@ return [
|
||||||
// 应用名称
|
// 应用名称
|
||||||
'app_name' => '子春生',
|
'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,
|
'order_payment_expires_at' => 1800,
|
||||||
|
|
||||||
|
|
@ -57,5 +48,6 @@ return [
|
||||||
|
|
||||||
//app配置
|
//app配置
|
||||||
'user_center_is_open'=>true,
|
'user_center_is_open'=>true,
|
||||||
|
'search_hot_keys' => '搜索热词,分词1,分词2,分词3',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue