PHP code example of wlfpanda1012 / aliyun-sts
1. Go to this page and download the library: Download wlfpanda1012/aliyun-sts 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/ */
wlfpanda1012 / aliyun-sts example snippets
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Wlfpanda1012\AliyunSts\StsService;
$effect = 'Allow';
$action = ['*'];
$resource = ['*'];
$condition = null;
$roleSessionName = 'session_name';
$service = \Hyperf\Support\make(StsService::class, ['option' => \Hyperf\Config\config('sts')]);
// 具体Statement参数请查询阿里云官方文档
$assumeRoleRequest = $service->generateAssumeRoleRequest($service->generatePolicy($service->generateStatement($effect, $action, $resource, $condition)), $roleSessionName);
$credentials = $service->getCredentials($service->assumeRole($assumeRoleRequest));
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Wlfpanda1012\AliyunSts\Constants\OSSAction;
use Wlfpanda1012\AliyunSts\Oss\OssRamService;
$service = \Hyperf\Support\make(OssRamService::class, ['option' => \Hyperf\Config\config('sts')]);
/**
* 如果你想获得下载文件的token,可以使用以下代码
* 支持数组和字符串.
*/
$token = $service->allowGetObject('path/to/file');
$token = $service->allowGetObject('path/to/file', 3600);
$token = $service->allowGetObject(['path/to/file1', 'path/to/file2'], 3600);
/**
* 如果你不想使用通配行为.
*/
$token = $service->allowGetObject(['path/to/file1', 'path/to/file2'], 3600, ['actions' => OSSAction::GET_OBJECT]);
$token = $service->allowGetObject(['path/to/file1', 'path/to/file2'], 3600, ['actions' => [OSSAction::GET_OBJECT, OSSAction::GET_OBJECT_ACL]]);
/**
* allowPutObject
* denyPutObject
* denyGetObject
* 功能同上.
*/
bash
php bin/hyperf.php vendor:publish wlfpanda1012/aliyun-sts