PHP code example of overtrue / laravel-qcloud-federation-token
1. Go to this page and download the library: Download overtrue/laravel-qcloud-federation-token library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
overtrue / laravel-qcloud-federation-token example snippets
$ php artisan vendor:publish --provider="Overtrue\\LaravelQCloudFederationToken\\QCloudFederationTokenServiceProvider"
return [
// 默认配置,strategies 下的每一个策略将合并此基础配置
'default' => [
'secret_id' => env('QCLOUD_COS_SECRET_ID', ''),
'secret_key' => env('QCLOUD_COS_SECRET_KEY', ''),
'region' => env('QCLOUD_COS_REGION', 'ap-guangzhou'),
"effect" => "allow",
// 全局变量,会被替换到所有策略中
'variables' => [
'uid' => env('QCLOUD_COS_APP_ID'),
'region' => env('QCLOUD_COS_REGION', 'ap-guangzhou'),
//...
],
],
// strategies
'strategies' => [
'cos' => [
// 策略名称,可选
'name' => 'cos-put',
// 临时凭证过期时间
'expires_in' => 1800,
// 将与默认配置合并
'variables' => [
'appid' => env('QCLOUD_COS_APP_ID'),
'bucket' => env('QCLOUD_COS_BUCKET', ''),
//...
],
// Statement 请参考:https://cloud.tencent.com/document/product/598/10603
"statements" => [
[
"action" => [
"cos:PutObject",
"cos:GetObject",
],
"resource" => [
"qcs::cos:ap-beijing:uid/<appid>:<bucket>-<appid>/<date>/<uuid>/*",
],
]
],
],
],
];
// config/federation-token.php
return [
// 默认配置,strategies 下的每一个策略将合并此基础配置
'default' => [
'secret_id' => env('QCLOUD_COS_SECRET_ID'),
'secret_key' => env('QCLOUD_COS_SECRET_KEY'),
'region' => env('QCLOUD_COS_REGION', 'ap-guangzhou'),
"effect" => "allow",
// 全局变量,会被替换到所有策略中
'variables' => [
'region' => env('QCLOUD_COS_REGION', 'ap-guangzhou'),
//...
],
],
// strategies
'strategies' => [
// 请参考:https://cloud.tencent.com/document/product/598/10603
'cos' => [
// 将与默认配置合并
'variables' => [
'appid' => env('QCLOUD_COS_APP_ID'),
'bucket' => env('QCLOUD_COS_BUCKET'),
//...
],
"statements" => [
[
"action" => [
"cos:PutObject",
"cos:GetObject",
],
"resource" => [
"qcs::cos:ap-beijing:uid/<appid>:<bucket>-<appid>/<date>/<uuid>/*",
],
]
],
],
],
];
use Overtrue\LaravelQCloudFederationToken\FederationToken;
// 使用默认策略(配置项 strategies 中第一个)
$token = FederationToken::createToken();
// 或者指定策略
$token = FederationToken::strategy('cos')->createToken();
$token->toArray();
// 'credentials' => [
// 'token' => 'kTRtHpOSOCUzTVWmzlPKweHffXjT9Izo7b61a142d6b56d31c0a7ace4d22bcff3zpbsXKTIrCo43dRRh7bDIKE1ZOE1KRYHEm0KNLjWG_aSF63YoQWchg',
// 'tmp_secret_id' => 'AKIDw7dwZbmFSup9CnAOraJ7skiPMybaV3WPP5B4oVMCIL5kLyphV_3IyAHFJ5QMCjE6',
// 'tmp_secret_key' => '/lvEo280/AlGt4orjDl9tWLIOMl5nkexS5Pg+xys7ps=',
// ],
// 'expired_at' => 1547696355,
$token->getStatements();