本文提供了PHP SDK安装包的下载地址及操作示例。

PHP SDK安装包下载地址

PHP SDK示例

<?php
namespace AlibabaCloud\Tests\Feature;
use AlibabaCloud\Sts\Sts;
use PHPUnit\Framework\TestCase;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Sts\V20150401\AssumeRole;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Client\Exception\ClientException;
/**
 * Class StsTest
 *
 * @package   AlibabaCloud\Tests\Feature
 */
class StsTest extends TestCase
{    
    /**
     * @expectedException \AlibabaCloud\Client\Exception\ServerException
     * @expectedExceptionMessageRegExp /EntityNotExist.Role: The specified Role not exists/
     * @throws ClientException
     * @throws ServerException
     */
    //构建AssumeRole请求
    public function testSts()
    {
        //构建阿里云client时需要设置AccessKey ID和AccessKey Secret      
        AlibabaCloud::accessKeyClient('LTAI4Ftm6BWGjEuusQzg****', 'W4ePhh5ArgySotqktAwXsSayQX****');
        Sts::v20150401()
           ->assumeRole()
           //指定角色ARN
           ->withRoleArn('acs:ram::151266687691****:role/cloud')
           //RoleSessionName即临时身份的会话名称,用于区分不同的临时身份
           ->withRoleSessionName('client_name')
           //设置Policy以进一步限制角色的权限
           //以下权限策略表示拥有所有OSS的只读权限
           ->withPolicy('{
             "Statement":[
                {
                     "Action":
                 [
                     "oss:Get*",
                     "oss:List*"
                     ],
                      "Effect": "Allow",
                      "Resource": "*"
                }
                   ],
          "Version": "1"
        }')
           ->connectTimeout(60)
           ->timeout(65)
           ->request();
    }
}
说明