短信验证 composer扩展
This commit is contained in:
37
vendor/alibabacloud/credentials/src/Request/AssumeRole.php
vendored
Normal file
37
vendor/alibabacloud/credentials/src/Request/AssumeRole.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Request;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\Provider;
|
||||
use AlibabaCloud\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
|
||||
/**
|
||||
* Retrieving assume role credentials.
|
||||
*/
|
||||
class AssumeRole extends Request
|
||||
{
|
||||
/**
|
||||
* AssumeRole constructor.
|
||||
*
|
||||
* @param RamRoleArnCredential $arnCredential
|
||||
*/
|
||||
public function __construct(RamRoleArnCredential $arnCredential)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->signature = new ShaHmac1Signature();
|
||||
$this->credential = $arnCredential;
|
||||
$this->uri = $this->uri->withHost('sts.aliyuncs.com');
|
||||
$this->options['verify'] = false;
|
||||
$this->options['query']['RoleArn'] = $arnCredential->getRoleArn();
|
||||
$this->options['query']['RoleSessionName'] = $arnCredential->getRoleSessionName();
|
||||
$this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
|
||||
$this->options['query']['AccessKeyId'] = $this->credential->getOriginalAccessKeyId();
|
||||
$this->options['query']['Version'] = '2015-04-01';
|
||||
$this->options['query']['Action'] = 'AssumeRole';
|
||||
$this->options['query']['RegionId'] = 'cn-hangzhou';
|
||||
if ($arnCredential->getPolicy()) {
|
||||
$this->options['query']['Policy'] = $arnCredential->getPolicy();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
vendor/alibabacloud/credentials/src/Request/GenerateSessionAccessKey.php
vendored
Normal file
33
vendor/alibabacloud/credentials/src/Request/GenerateSessionAccessKey.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Request;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\Provider;
|
||||
use AlibabaCloud\Credentials\RsaKeyPairCredential;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac256WithRsaSignature;
|
||||
|
||||
/**
|
||||
* Use the RSA key pair to complete the authentication (supported only on Japanese site)
|
||||
*/
|
||||
class GenerateSessionAccessKey extends Request
|
||||
{
|
||||
/**
|
||||
* GenerateSessionAccessKey constructor.
|
||||
*
|
||||
* @param RsaKeyPairCredential $credential
|
||||
*/
|
||||
public function __construct(RsaKeyPairCredential $credential)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->signature = new ShaHmac256WithRsaSignature();
|
||||
$this->credential = $credential;
|
||||
$this->uri = $this->uri->withHost('sts.ap-northeast-1.aliyuncs.com');
|
||||
$this->options['verify'] = false;
|
||||
$this->options['query']['Version'] = '2015-04-01';
|
||||
$this->options['query']['Action'] = 'GenerateSessionAccessKey';
|
||||
$this->options['query']['RegionId'] = 'cn-hangzhou';
|
||||
$this->options['query']['AccessKeyId'] = $credential->getPublicKeyId();
|
||||
$this->options['query']['PublicKeyId'] = $credential->getPublicKeyId();
|
||||
$this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
|
||||
}
|
||||
}
|
||||
155
vendor/alibabacloud/credentials/src/Request/Request.php
vendored
Normal file
155
vendor/alibabacloud/credentials/src/Request/Request.php
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Request;
|
||||
|
||||
use AlibabaCloud\Credentials\Credentials;
|
||||
use AlibabaCloud\Credentials\EcsRamRoleCredential;
|
||||
use AlibabaCloud\Credentials\Helper;
|
||||
use AlibabaCloud\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac256WithRsaSignature;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Middleware;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use AlibabaCloud\Tea\Response;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* RESTful RPC Request.
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
|
||||
/**
|
||||
* Request Connect Timeout
|
||||
*/
|
||||
const CONNECT_TIMEOUT = 5;
|
||||
|
||||
/**
|
||||
* Request Timeout
|
||||
*/
|
||||
const TIMEOUT = 10;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $config = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $options = [];
|
||||
|
||||
/**
|
||||
* @var Uri
|
||||
*/
|
||||
public $uri;
|
||||
|
||||
/**
|
||||
* @var EcsRamRoleCredential|RamRoleArnCredential
|
||||
*/
|
||||
protected $credential;
|
||||
|
||||
/**
|
||||
* @var ShaHmac256WithRsaSignature|ShaHmac1Signature
|
||||
*/
|
||||
protected $signature;
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->uri = (new Uri())->withScheme('https');
|
||||
$this->options['http_errors'] = false;
|
||||
$this->options['connect_timeout'] = self::CONNECT_TIMEOUT;
|
||||
$this->options['timeout'] = self::TIMEOUT;
|
||||
|
||||
// Turn on debug mode based on environment variable.
|
||||
if (strtolower(Helper::env('DEBUG')) === 'sdk') {
|
||||
$this->options['debug'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function request()
|
||||
{
|
||||
$this->options['query']['Format'] = 'JSON';
|
||||
$this->options['query']['SignatureMethod'] = $this->signature->getMethod();
|
||||
$this->options['query']['SignatureVersion'] = $this->signature->getVersion();
|
||||
$this->options['query']['SignatureNonce'] = self::uuid(json_encode($this->options['query']));
|
||||
$this->options['query']['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$this->options['query']['Signature'] = $this->signature->sign(
|
||||
self::signString('GET', $this->options['query']),
|
||||
$this->credential->getOriginalAccessKeySecret() . '&'
|
||||
);
|
||||
return self::createClient()->request('GET', (string)$this->uri, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $salt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function uuid($salt)
|
||||
{
|
||||
return md5($salt . uniqid(md5(microtime(true)), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function signString($method, array $parameters)
|
||||
{
|
||||
ksort($parameters);
|
||||
$canonicalized = '';
|
||||
foreach ($parameters as $key => $value) {
|
||||
$canonicalized .= '&' . self::percentEncode($key) . '=' . self::percentEncode($value);
|
||||
}
|
||||
|
||||
return $method . '&%2F&' . self::percentEncode(substr($canonicalized, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return null|string|string[]
|
||||
*/
|
||||
private static function percentEncode($string)
|
||||
{
|
||||
$result = rawurlencode($string);
|
||||
$result = str_replace(['+', '*'], ['%20', '%2A'], $result);
|
||||
$result = preg_replace('/%7E/', '~', $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createClient()
|
||||
{
|
||||
if (Credentials::hasMock()) {
|
||||
$stack = HandlerStack::create(Credentials::getMock());
|
||||
} else {
|
||||
$stack = HandlerStack::create();
|
||||
}
|
||||
|
||||
$stack->push(Middleware::mapResponse(static function (ResponseInterface $response) {
|
||||
return new Response($response);
|
||||
}));
|
||||
|
||||
self::$config['handler'] = $stack;
|
||||
|
||||
return new Client(self::$config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user