commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class AlibabaCloudException extends DaraException {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $statusCode;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $code;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $message;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $requestId;
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
$this->statusCode = $map['statusCode'];
|
||||
$this->code = $map['code'];
|
||||
$this->message = $map['message'];
|
||||
$this->description = $map['description'];
|
||||
$this->requestId = $map['requestId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
class ClientException extends AlibabaCloudException {
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
public $accessDeniedDetail;
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
$this->accessDeniedDetail = $map['accessDeniedDetail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getAccessDeniedDetail()
|
||||
{
|
||||
return $this->accessDeniedDetail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
class ServerException extends AlibabaCloudException {
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
class ThrottlingException extends AlibabaCloudException {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $retryAfter;
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
$this->retryAfter = $map['retryAfter'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRetryAfter()
|
||||
{
|
||||
return $this->retryAfter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use AlibabaCloud\Credentials\Credential;
|
||||
use Darabonba\OpenApi\Models\GlobalParameters;
|
||||
use AlibabaCloud\Dara\RetryPolicy\RetryOptions;
|
||||
/**
|
||||
* @remarks
|
||||
* Model for initing client
|
||||
*/
|
||||
class Config extends Model {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeyId;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeySecret;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $securityToken;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $bearerToken;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $protocol;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $method;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $regionId;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $readTimeout;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $connectTimeout;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $httpProxy;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $httpsProxy;
|
||||
/**
|
||||
* @var Credential
|
||||
*/
|
||||
public $credential;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpoint;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $noProxy;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $maxIdleConns;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $network;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $userAgent;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $suffix;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $socks5Proxy;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $socks5NetWork;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpointType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $openPlatformEndpoint;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $signatureVersion;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $signatureAlgorithm;
|
||||
/**
|
||||
* @var GlobalParameters
|
||||
*/
|
||||
public $globalParameters;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $cert;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ca;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
public $disableHttp2;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $tlsMinVersion;
|
||||
/**
|
||||
* @var RetryOptions
|
||||
*/
|
||||
public $retryOptions;
|
||||
protected $_name = [
|
||||
'accessKeyId' => 'accessKeyId',
|
||||
'accessKeySecret' => 'accessKeySecret',
|
||||
'securityToken' => 'securityToken',
|
||||
'bearerToken' => 'bearerToken',
|
||||
'protocol' => 'protocol',
|
||||
'method' => 'method',
|
||||
'regionId' => 'regionId',
|
||||
'readTimeout' => 'readTimeout',
|
||||
'connectTimeout' => 'connectTimeout',
|
||||
'httpProxy' => 'httpProxy',
|
||||
'httpsProxy' => 'httpsProxy',
|
||||
'credential' => 'credential',
|
||||
'endpoint' => 'endpoint',
|
||||
'noProxy' => 'noProxy',
|
||||
'maxIdleConns' => 'maxIdleConns',
|
||||
'network' => 'network',
|
||||
'userAgent' => 'userAgent',
|
||||
'suffix' => 'suffix',
|
||||
'socks5Proxy' => 'socks5Proxy',
|
||||
'socks5NetWork' => 'socks5NetWork',
|
||||
'endpointType' => 'endpointType',
|
||||
'openPlatformEndpoint' => 'openPlatformEndpoint',
|
||||
'type' => 'type',
|
||||
'signatureVersion' => 'signatureVersion',
|
||||
'signatureAlgorithm' => 'signatureAlgorithm',
|
||||
'globalParameters' => 'globalParameters',
|
||||
'key' => 'key',
|
||||
'cert' => 'cert',
|
||||
'ca' => 'ca',
|
||||
'disableHttp2' => 'disableHttp2',
|
||||
'tlsMinVersion' => 'tlsMinVersion',
|
||||
'retryOptions' => 'retryOptions',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(null !== $this->credential) {
|
||||
$this->credential->validate();
|
||||
}
|
||||
if(null !== $this->globalParameters) {
|
||||
$this->globalParameters->validate();
|
||||
}
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->accessKeyId) {
|
||||
$res['accessKeyId'] = $this->accessKeyId;
|
||||
}
|
||||
|
||||
if (null !== $this->accessKeySecret) {
|
||||
$res['accessKeySecret'] = $this->accessKeySecret;
|
||||
}
|
||||
|
||||
if (null !== $this->securityToken) {
|
||||
$res['securityToken'] = $this->securityToken;
|
||||
}
|
||||
|
||||
if (null !== $this->bearerToken) {
|
||||
$res['bearerToken'] = $this->bearerToken;
|
||||
}
|
||||
|
||||
if (null !== $this->protocol) {
|
||||
$res['protocol'] = $this->protocol;
|
||||
}
|
||||
|
||||
if (null !== $this->method) {
|
||||
$res['method'] = $this->method;
|
||||
}
|
||||
|
||||
if (null !== $this->regionId) {
|
||||
$res['regionId'] = $this->regionId;
|
||||
}
|
||||
|
||||
if (null !== $this->readTimeout) {
|
||||
$res['readTimeout'] = $this->readTimeout;
|
||||
}
|
||||
|
||||
if (null !== $this->connectTimeout) {
|
||||
$res['connectTimeout'] = $this->connectTimeout;
|
||||
}
|
||||
|
||||
if (null !== $this->httpProxy) {
|
||||
$res['httpProxy'] = $this->httpProxy;
|
||||
}
|
||||
|
||||
if (null !== $this->httpsProxy) {
|
||||
$res['httpsProxy'] = $this->httpsProxy;
|
||||
}
|
||||
|
||||
if (null !== $this->credential) {
|
||||
$res['credential'] = $this->credential;
|
||||
}
|
||||
|
||||
if (null !== $this->endpoint) {
|
||||
$res['endpoint'] = $this->endpoint;
|
||||
}
|
||||
|
||||
if (null !== $this->noProxy) {
|
||||
$res['noProxy'] = $this->noProxy;
|
||||
}
|
||||
|
||||
if (null !== $this->maxIdleConns) {
|
||||
$res['maxIdleConns'] = $this->maxIdleConns;
|
||||
}
|
||||
|
||||
if (null !== $this->network) {
|
||||
$res['network'] = $this->network;
|
||||
}
|
||||
|
||||
if (null !== $this->userAgent) {
|
||||
$res['userAgent'] = $this->userAgent;
|
||||
}
|
||||
|
||||
if (null !== $this->suffix) {
|
||||
$res['suffix'] = $this->suffix;
|
||||
}
|
||||
|
||||
if (null !== $this->socks5Proxy) {
|
||||
$res['socks5Proxy'] = $this->socks5Proxy;
|
||||
}
|
||||
|
||||
if (null !== $this->socks5NetWork) {
|
||||
$res['socks5NetWork'] = $this->socks5NetWork;
|
||||
}
|
||||
|
||||
if (null !== $this->endpointType) {
|
||||
$res['endpointType'] = $this->endpointType;
|
||||
}
|
||||
|
||||
if (null !== $this->openPlatformEndpoint) {
|
||||
$res['openPlatformEndpoint'] = $this->openPlatformEndpoint;
|
||||
}
|
||||
|
||||
if (null !== $this->type) {
|
||||
$res['type'] = $this->type;
|
||||
}
|
||||
|
||||
if (null !== $this->signatureVersion) {
|
||||
$res['signatureVersion'] = $this->signatureVersion;
|
||||
}
|
||||
|
||||
if (null !== $this->signatureAlgorithm) {
|
||||
$res['signatureAlgorithm'] = $this->signatureAlgorithm;
|
||||
}
|
||||
|
||||
if (null !== $this->globalParameters) {
|
||||
$res['globalParameters'] = null !== $this->globalParameters ? $this->globalParameters->toArray($noStream) : $this->globalParameters;
|
||||
}
|
||||
|
||||
if (null !== $this->key) {
|
||||
$res['key'] = $this->key;
|
||||
}
|
||||
|
||||
if (null !== $this->cert) {
|
||||
$res['cert'] = $this->cert;
|
||||
}
|
||||
|
||||
if (null !== $this->ca) {
|
||||
$res['ca'] = $this->ca;
|
||||
}
|
||||
|
||||
if (null !== $this->disableHttp2) {
|
||||
$res['disableHttp2'] = $this->disableHttp2;
|
||||
}
|
||||
|
||||
if (null !== $this->tlsMinVersion) {
|
||||
$res['tlsMinVersion'] = $this->tlsMinVersion;
|
||||
}
|
||||
|
||||
if (null !== $this->retryOptions) {
|
||||
$res['retryOptions'] = null !== $this->retryOptions ? $this->retryOptions->toArray($noStream) : $this->retryOptions;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['accessKeyId'])) {
|
||||
$model->accessKeyId = $map['accessKeyId'];
|
||||
}
|
||||
|
||||
if (isset($map['accessKeySecret'])) {
|
||||
$model->accessKeySecret = $map['accessKeySecret'];
|
||||
}
|
||||
|
||||
if (isset($map['securityToken'])) {
|
||||
$model->securityToken = $map['securityToken'];
|
||||
}
|
||||
|
||||
if (isset($map['bearerToken'])) {
|
||||
$model->bearerToken = $map['bearerToken'];
|
||||
}
|
||||
|
||||
if (isset($map['protocol'])) {
|
||||
$model->protocol = $map['protocol'];
|
||||
}
|
||||
|
||||
if (isset($map['method'])) {
|
||||
$model->method = $map['method'];
|
||||
}
|
||||
|
||||
if (isset($map['regionId'])) {
|
||||
$model->regionId = $map['regionId'];
|
||||
}
|
||||
|
||||
if (isset($map['readTimeout'])) {
|
||||
$model->readTimeout = $map['readTimeout'];
|
||||
}
|
||||
|
||||
if (isset($map['connectTimeout'])) {
|
||||
$model->connectTimeout = $map['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($map['httpProxy'])) {
|
||||
$model->httpProxy = $map['httpProxy'];
|
||||
}
|
||||
|
||||
if (isset($map['httpsProxy'])) {
|
||||
$model->httpsProxy = $map['httpsProxy'];
|
||||
}
|
||||
|
||||
if (isset($map['credential'])) {
|
||||
$model->credential = $map['credential'];
|
||||
}
|
||||
|
||||
if (isset($map['endpoint'])) {
|
||||
$model->endpoint = $map['endpoint'];
|
||||
}
|
||||
|
||||
if (isset($map['noProxy'])) {
|
||||
$model->noProxy = $map['noProxy'];
|
||||
}
|
||||
|
||||
if (isset($map['maxIdleConns'])) {
|
||||
$model->maxIdleConns = $map['maxIdleConns'];
|
||||
}
|
||||
|
||||
if (isset($map['network'])) {
|
||||
$model->network = $map['network'];
|
||||
}
|
||||
|
||||
if (isset($map['userAgent'])) {
|
||||
$model->userAgent = $map['userAgent'];
|
||||
}
|
||||
|
||||
if (isset($map['suffix'])) {
|
||||
$model->suffix = $map['suffix'];
|
||||
}
|
||||
|
||||
if (isset($map['socks5Proxy'])) {
|
||||
$model->socks5Proxy = $map['socks5Proxy'];
|
||||
}
|
||||
|
||||
if (isset($map['socks5NetWork'])) {
|
||||
$model->socks5NetWork = $map['socks5NetWork'];
|
||||
}
|
||||
|
||||
if (isset($map['endpointType'])) {
|
||||
$model->endpointType = $map['endpointType'];
|
||||
}
|
||||
|
||||
if (isset($map['openPlatformEndpoint'])) {
|
||||
$model->openPlatformEndpoint = $map['openPlatformEndpoint'];
|
||||
}
|
||||
|
||||
if (isset($map['type'])) {
|
||||
$model->type = $map['type'];
|
||||
}
|
||||
|
||||
if (isset($map['signatureVersion'])) {
|
||||
$model->signatureVersion = $map['signatureVersion'];
|
||||
}
|
||||
|
||||
if (isset($map['signatureAlgorithm'])) {
|
||||
$model->signatureAlgorithm = $map['signatureAlgorithm'];
|
||||
}
|
||||
|
||||
if (isset($map['globalParameters'])) {
|
||||
$model->globalParameters = GlobalParameters::fromMap($map['globalParameters']);
|
||||
}
|
||||
|
||||
if (isset($map['key'])) {
|
||||
$model->key = $map['key'];
|
||||
}
|
||||
|
||||
if (isset($map['cert'])) {
|
||||
$model->cert = $map['cert'];
|
||||
}
|
||||
|
||||
if (isset($map['ca'])) {
|
||||
$model->ca = $map['ca'];
|
||||
}
|
||||
|
||||
if (isset($map['disableHttp2'])) {
|
||||
$model->disableHttp2 = $map['disableHttp2'];
|
||||
}
|
||||
|
||||
if (isset($map['tlsMinVersion'])) {
|
||||
$model->tlsMinVersion = $map['tlsMinVersion'];
|
||||
}
|
||||
|
||||
if (isset($map['retryOptions'])) {
|
||||
$model->retryOptions = RetryOptions::fromMap($map['retryOptions']);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
class GlobalParameters extends Model {
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $headers;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $queries;
|
||||
protected $_name = [
|
||||
'headers' => 'headers',
|
||||
'queries' => 'queries',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(is_array($this->headers)) {
|
||||
Model::validateArray($this->headers);
|
||||
}
|
||||
if(is_array($this->queries)) {
|
||||
Model::validateArray($this->queries);
|
||||
}
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->headers) {
|
||||
if(is_array($this->headers)) {
|
||||
$res['headers'] = [];
|
||||
foreach($this->headers as $key1 => $value1) {
|
||||
$res['headers'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->queries) {
|
||||
if(is_array($this->queries)) {
|
||||
$res['queries'] = [];
|
||||
foreach($this->queries as $key1 => $value1) {
|
||||
$res['queries'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['headers'])) {
|
||||
if(!empty($map['headers'])) {
|
||||
$model->headers = [];
|
||||
foreach($map['headers'] as $key1 => $value1) {
|
||||
$model->headers[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['queries'])) {
|
||||
if(!empty($map['queries'])) {
|
||||
$model->queries = [];
|
||||
foreach($map['queries'] as $key1 => $value1) {
|
||||
$model->queries[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use GuzzleHttp\Psr7\Stream;
|
||||
class OpenApiRequest extends Model {
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $headers;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $query;
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $body;
|
||||
/**
|
||||
* @var Stream
|
||||
*/
|
||||
public $stream;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $hostMap;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpointOverride;
|
||||
protected $_name = [
|
||||
'headers' => 'headers',
|
||||
'query' => 'query',
|
||||
'body' => 'body',
|
||||
'stream' => 'stream',
|
||||
'hostMap' => 'hostMap',
|
||||
'endpointOverride' => 'endpointOverride',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(is_array($this->headers)) {
|
||||
Model::validateArray($this->headers);
|
||||
}
|
||||
if(is_array($this->query)) {
|
||||
Model::validateArray($this->query);
|
||||
}
|
||||
if(is_array($this->hostMap)) {
|
||||
Model::validateArray($this->hostMap);
|
||||
}
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->headers) {
|
||||
if(is_array($this->headers)) {
|
||||
$res['headers'] = [];
|
||||
foreach($this->headers as $key1 => $value1) {
|
||||
$res['headers'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->query) {
|
||||
if(is_array($this->query)) {
|
||||
$res['query'] = [];
|
||||
foreach($this->query as $key1 => $value1) {
|
||||
$res['query'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->body) {
|
||||
$res['body'] = $this->body;
|
||||
}
|
||||
|
||||
if (null !== $this->stream) {
|
||||
$res['stream'] = $this->stream;
|
||||
}
|
||||
|
||||
if (null !== $this->hostMap) {
|
||||
if(is_array($this->hostMap)) {
|
||||
$res['hostMap'] = [];
|
||||
foreach($this->hostMap as $key1 => $value1) {
|
||||
$res['hostMap'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->endpointOverride) {
|
||||
$res['endpointOverride'] = $this->endpointOverride;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['headers'])) {
|
||||
if(!empty($map['headers'])) {
|
||||
$model->headers = [];
|
||||
foreach($map['headers'] as $key1 => $value1) {
|
||||
$model->headers[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['query'])) {
|
||||
if(!empty($map['query'])) {
|
||||
$model->query = [];
|
||||
foreach($map['query'] as $key1 => $value1) {
|
||||
$model->query[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['body'])) {
|
||||
$model->body = $map['body'];
|
||||
}
|
||||
|
||||
if (isset($map['stream'])) {
|
||||
$model->stream = $map['stream'];
|
||||
}
|
||||
|
||||
if (isset($map['hostMap'])) {
|
||||
if(!empty($map['hostMap'])) {
|
||||
$model->hostMap = [];
|
||||
foreach($map['hostMap'] as $key1 => $value1) {
|
||||
$model->hostMap[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['endpointOverride'])) {
|
||||
$model->endpointOverride = $map['endpointOverride'];
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
class Params extends Model {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $action;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $version;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $protocol;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $pathname;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $method;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $authType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $bodyType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $reqBodyType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $style;
|
||||
protected $_name = [
|
||||
'action' => 'action',
|
||||
'version' => 'version',
|
||||
'protocol' => 'protocol',
|
||||
'pathname' => 'pathname',
|
||||
'method' => 'method',
|
||||
'authType' => 'authType',
|
||||
'bodyType' => 'bodyType',
|
||||
'reqBodyType' => 'reqBodyType',
|
||||
'style' => 'style',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
Model::validateRequired('action', $this->action, true);
|
||||
Model::validateRequired('version', $this->version, true);
|
||||
Model::validateRequired('protocol', $this->protocol, true);
|
||||
Model::validateRequired('pathname', $this->pathname, true);
|
||||
Model::validateRequired('method', $this->method, true);
|
||||
Model::validateRequired('authType', $this->authType, true);
|
||||
Model::validateRequired('bodyType', $this->bodyType, true);
|
||||
Model::validateRequired('reqBodyType', $this->reqBodyType, true);
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->action) {
|
||||
$res['action'] = $this->action;
|
||||
}
|
||||
|
||||
if (null !== $this->version) {
|
||||
$res['version'] = $this->version;
|
||||
}
|
||||
|
||||
if (null !== $this->protocol) {
|
||||
$res['protocol'] = $this->protocol;
|
||||
}
|
||||
|
||||
if (null !== $this->pathname) {
|
||||
$res['pathname'] = $this->pathname;
|
||||
}
|
||||
|
||||
if (null !== $this->method) {
|
||||
$res['method'] = $this->method;
|
||||
}
|
||||
|
||||
if (null !== $this->authType) {
|
||||
$res['authType'] = $this->authType;
|
||||
}
|
||||
|
||||
if (null !== $this->bodyType) {
|
||||
$res['bodyType'] = $this->bodyType;
|
||||
}
|
||||
|
||||
if (null !== $this->reqBodyType) {
|
||||
$res['reqBodyType'] = $this->reqBodyType;
|
||||
}
|
||||
|
||||
if (null !== $this->style) {
|
||||
$res['style'] = $this->style;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['action'])) {
|
||||
$model->action = $map['action'];
|
||||
}
|
||||
|
||||
if (isset($map['version'])) {
|
||||
$model->version = $map['version'];
|
||||
}
|
||||
|
||||
if (isset($map['protocol'])) {
|
||||
$model->protocol = $map['protocol'];
|
||||
}
|
||||
|
||||
if (isset($map['pathname'])) {
|
||||
$model->pathname = $map['pathname'];
|
||||
}
|
||||
|
||||
if (isset($map['method'])) {
|
||||
$model->method = $map['method'];
|
||||
}
|
||||
|
||||
if (isset($map['authType'])) {
|
||||
$model->authType = $map['authType'];
|
||||
}
|
||||
|
||||
if (isset($map['bodyType'])) {
|
||||
$model->bodyType = $map['bodyType'];
|
||||
}
|
||||
|
||||
if (isset($map['reqBodyType'])) {
|
||||
$model->reqBodyType = $map['reqBodyType'];
|
||||
}
|
||||
|
||||
if (isset($map['style'])) {
|
||||
$model->style = $map['style'];
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use AlibabaCloud\Dara\SSE\Event;
|
||||
class SSEResponse extends Model {
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $headers;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $statusCode;
|
||||
/**
|
||||
* @var Event
|
||||
*/
|
||||
public $event;
|
||||
protected $_name = [
|
||||
'headers' => 'headers',
|
||||
'statusCode' => 'statusCode',
|
||||
'event' => 'event',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(is_array($this->headers)) {
|
||||
Model::validateArray($this->headers);
|
||||
}
|
||||
Model::validateRequired('headers', $this->headers, true);
|
||||
Model::validateRequired('statusCode', $this->statusCode, true);
|
||||
Model::validateRequired('event', $this->event, true);
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->headers) {
|
||||
if(is_array($this->headers)) {
|
||||
$res['headers'] = [];
|
||||
foreach($this->headers as $key1 => $value1) {
|
||||
$res['headers'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->statusCode) {
|
||||
$res['statusCode'] = $this->statusCode;
|
||||
}
|
||||
|
||||
if (null !== $this->event) {
|
||||
$res['event'] = null !== $this->event ? $this->event->toArray($noStream) : $this->event;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['headers'])) {
|
||||
if(!empty($map['headers'])) {
|
||||
$model->headers = [];
|
||||
foreach($map['headers'] as $key1 => $value1) {
|
||||
$model->headers[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['statusCode'])) {
|
||||
$model->statusCode = $map['statusCode'];
|
||||
}
|
||||
|
||||
if (isset($map['event'])) {
|
||||
$model->event = Event::fromMap($map['event']);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1861
File diff suppressed because it is too large
Load Diff
+183
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi;
|
||||
|
||||
/**
|
||||
* SM3 cryptographic hash algorithm implementation
|
||||
* SM3 is a cryptographic hash function standard of China
|
||||
*/
|
||||
class Sm3
|
||||
{
|
||||
private static $IV = [
|
||||
0x7380166f, 0x4914b2b9, 0x172442d7, 0xda8a0600,
|
||||
0xa96f30bc, 0x163138aa, 0xe38dee4d, 0xb0fb0e4e
|
||||
];
|
||||
|
||||
private static $T_0_15 = 0x79cc4519;
|
||||
private static $T_16_63 = 0x7a879d8a;
|
||||
|
||||
/**
|
||||
* Calculate SM3 hash of the message
|
||||
*
|
||||
* @param string $message The message to hash
|
||||
* @return string The hexadecimal hash string
|
||||
*/
|
||||
public function sign($message)
|
||||
{
|
||||
$len = strlen($message);
|
||||
$bitLen = $len * 8;
|
||||
|
||||
// Padding
|
||||
$message .= "\x80";
|
||||
$padLen = (56 - (($len + 1) % 64)) % 64;
|
||||
$message .= str_repeat("\x00", $padLen);
|
||||
|
||||
// Append length
|
||||
$message .= pack('N', $bitLen >> 32);
|
||||
$message .= pack('N', $bitLen & 0xFFFFFFFF);
|
||||
|
||||
// Process message in 512-bit blocks
|
||||
$v = self::$IV;
|
||||
$blocks = str_split($message, 64);
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
$v = $this->cf($v, $block);
|
||||
}
|
||||
|
||||
// Convert to hex string
|
||||
$result = '';
|
||||
foreach ($v as $word) {
|
||||
$result .= sprintf('%08x', $word);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compression function
|
||||
*/
|
||||
private function cf($v, $block)
|
||||
{
|
||||
$w = [];
|
||||
$w1 = [];
|
||||
|
||||
// Expand message block
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$w[$i] = unpack('N', substr($block, $i * 4, 4))[1];
|
||||
}
|
||||
|
||||
for ($i = 16; $i < 68; $i++) {
|
||||
$w[$i] = $this->p1(
|
||||
$w[$i - 16] ^ $w[$i - 9] ^ $this->rotl($w[$i - 3], 15)
|
||||
) ^ $this->rotl($w[$i - 13], 7) ^ $w[$i - 6];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
$w1[$i] = $w[$i] ^ $w[$i + 4];
|
||||
}
|
||||
|
||||
// Compression
|
||||
$a = $v[0];
|
||||
$b = $v[1];
|
||||
$c = $v[2];
|
||||
$d = $v[3];
|
||||
$e = $v[4];
|
||||
$f = $v[5];
|
||||
$g = $v[6];
|
||||
$h = $v[7];
|
||||
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
$ss1 = $this->rotl(
|
||||
$this->add32(
|
||||
$this->add32($this->rotl($a, 12), $e),
|
||||
$this->rotl($this->t($i), $i)
|
||||
),
|
||||
7
|
||||
);
|
||||
|
||||
$ss2 = $ss1 ^ $this->rotl($a, 12);
|
||||
$tt1 = $this->add32(
|
||||
$this->add32(
|
||||
$this->add32($this->ff($a, $b, $c, $i), $d),
|
||||
$ss2
|
||||
),
|
||||
$w1[$i]
|
||||
);
|
||||
|
||||
$tt2 = $this->add32(
|
||||
$this->add32(
|
||||
$this->add32($this->gg($e, $f, $g, $i), $h),
|
||||
$ss1
|
||||
),
|
||||
$w[$i]
|
||||
);
|
||||
|
||||
$d = $c;
|
||||
$c = $this->rotl($b, 9);
|
||||
$b = $a;
|
||||
$a = $tt1;
|
||||
$h = $g;
|
||||
$g = $this->rotl($f, 19);
|
||||
$f = $e;
|
||||
$e = $this->p0($tt2);
|
||||
}
|
||||
|
||||
return [
|
||||
$a ^ $v[0],
|
||||
$b ^ $v[1],
|
||||
$c ^ $v[2],
|
||||
$d ^ $v[3],
|
||||
$e ^ $v[4],
|
||||
$f ^ $v[5],
|
||||
$g ^ $v[6],
|
||||
$h ^ $v[7]
|
||||
];
|
||||
}
|
||||
|
||||
private function ff($x, $y, $z, $j)
|
||||
{
|
||||
if ($j < 16) {
|
||||
return $x ^ $y ^ $z;
|
||||
}
|
||||
return ($x & $y) | ($x & $z) | ($y & $z);
|
||||
}
|
||||
|
||||
private function gg($x, $y, $z, $j)
|
||||
{
|
||||
if ($j < 16) {
|
||||
return $x ^ $y ^ $z;
|
||||
}
|
||||
return ($x & $y) | ((~$x) & $z);
|
||||
}
|
||||
|
||||
private function t($j)
|
||||
{
|
||||
if ($j < 16) {
|
||||
return self::$T_0_15;
|
||||
}
|
||||
return self::$T_16_63;
|
||||
}
|
||||
|
||||
private function rotl($x, $n)
|
||||
{
|
||||
$n = $n % 32;
|
||||
return (($x << $n) | ($x >> (32 - $n))) & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
private function p0($x)
|
||||
{
|
||||
return $x ^ $this->rotl($x, 9) ^ $this->rotl($x, 17);
|
||||
}
|
||||
|
||||
private function p1($x)
|
||||
{
|
||||
return $x ^ $this->rotl($x, 15) ^ $this->rotl($x, 23);
|
||||
}
|
||||
|
||||
private function add32($a, $b)
|
||||
{
|
||||
return ($a + $b) & 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
+770
@@ -0,0 +1,770 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Dara\Request;
|
||||
use AlibabaCloud\Dara\Util\BytesUtil;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
/**
|
||||
* @remarks
|
||||
* This is for OpenApi Util
|
||||
*/
|
||||
class Utils {
|
||||
|
||||
private static $defaultUserAgent = '';
|
||||
/**
|
||||
* @remarks
|
||||
* Convert all params of body other than type of readable into content
|
||||
*
|
||||
* @param Model $body
|
||||
* @param Model $content
|
||||
* @return void
|
||||
*/
|
||||
static public function convert($body, $content)
|
||||
{
|
||||
$map = $body->toMap();
|
||||
$map = self::exceptStream($map);
|
||||
$newContent = $content::fromMap($map);
|
||||
$class = new \ReflectionClass($newContent);
|
||||
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$name = $property->getName();
|
||||
if (!$property->isStatic()) {
|
||||
$content->{$name} = $property->getValue($newContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function exceptStream($map)
|
||||
{
|
||||
if ($map instanceof StreamInterface) {
|
||||
return null;
|
||||
} elseif (\is_array($map)) {
|
||||
$data = [];
|
||||
foreach ($map as $k => $v) {
|
||||
if (null !== $v) {
|
||||
$item = self::exceptStream($v);
|
||||
if (null !== $item) {
|
||||
$data[$k] = $item;
|
||||
}
|
||||
} else {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* If endpointType is internal, use internal endpoint
|
||||
* If serverUse is true and endpointType is accelerate, use accelerate endpoint
|
||||
* Default return endpoint
|
||||
*
|
||||
* @param string $endpoint The endpoint URL
|
||||
* @param boolean $useAccelerate Whether use accelerate endpoint
|
||||
* @param string $endpointType Value must be internal or accelerate
|
||||
* @return string The final endpoint
|
||||
*/
|
||||
static public function getEndpoint($endpoint, $useAccelerate, $endpointType)
|
||||
{
|
||||
if ('internal' == $endpointType) {
|
||||
$tmp = explode('.', $endpoint);
|
||||
$tmp[0] .= '-internal';
|
||||
$endpoint = implode('.', $tmp);
|
||||
}
|
||||
if ($useAccelerate && 'accelerate' == $endpointType) {
|
||||
return 'oss-accelerate.aliyuncs.com';
|
||||
}
|
||||
|
||||
return $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get throttling param
|
||||
*
|
||||
* @param string[] $headers The response headers
|
||||
* @return int Time left
|
||||
*/
|
||||
public static function getThrottlingTimeLeft(array $headers) {
|
||||
$rateLimitForUserApi = isset($headers["x-ratelimit-user-api"]) ? $headers["x-ratelimit-user-api"] : null;
|
||||
$rateLimitForUser = isset($headers["x-ratelimit-user"]) ? $headers["x-ratelimit-user"] : null;
|
||||
|
||||
$timeLeftForUserApi = self::getTimeLeft($rateLimitForUserApi);
|
||||
$timeLeftForUser = self::getTimeLeft($rateLimitForUser);
|
||||
|
||||
$maxValue = max($timeLeftForUserApi, $timeLeftForUser);
|
||||
return $maxValue !== null ? $maxValue : 0;
|
||||
}
|
||||
|
||||
|
||||
private static function getTimeLeft($rateLimit) {
|
||||
if ($rateLimit) {
|
||||
$pairs = explode(',', $rateLimit);
|
||||
foreach ($pairs as $pair) {
|
||||
$kv = explode(':', $pair);
|
||||
if (count($kv) === 2) {
|
||||
$key = trim($kv[0]);
|
||||
$value = trim($kv[1]);
|
||||
if ($key === 'TimeLeft') {
|
||||
$timeLeftValue = intval($value);
|
||||
if ($timeLeftValue === 0 && $value !== "0") { // 确认不是 "0"
|
||||
return null;
|
||||
}
|
||||
return $timeLeftValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Hash the raw data with signatureAlgorithm
|
||||
*
|
||||
* @param int[] $raw Hashing data
|
||||
* @param string $signatureAlgorithm The autograph method
|
||||
* @return string|array Hashed bytes
|
||||
*/
|
||||
static public function hash($raw, $signatureAlgorithm)
|
||||
{
|
||||
$str = BytesUtil::toString($raw);
|
||||
|
||||
switch ($signatureAlgorithm) {
|
||||
case 'ACS3-HMAC-SHA256':
|
||||
case 'ACS3-RSA-SHA256':
|
||||
$res = hash('sha256', $str, true);
|
||||
return $res;
|
||||
case 'ACS3-HMAC-SM3':
|
||||
$res = self::sm3($str);
|
||||
return hex2bin($res);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Generate a nonce string
|
||||
* @returns the nonce string
|
||||
* @return string
|
||||
*/
|
||||
static public function getNonce()
|
||||
{
|
||||
return md5(uniqid() . uniqid(md5(microtime(true)), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get the string to be signed according to request
|
||||
*
|
||||
* @param Request $request Which contains signed messages
|
||||
* @return string The signed string
|
||||
*/
|
||||
static public function getStringToSign($request)
|
||||
{
|
||||
$pathname = $request->pathname ?: '';
|
||||
$query = $request->query ?: [];
|
||||
|
||||
$accept = isset($request->headers['accept']) ? $request->headers['accept'] : '';
|
||||
$contentMD5 = isset($request->headers['content-md5']) ? $request->headers['content-md5'] : '';
|
||||
$contentType = isset($request->headers['content-type']) ? $request->headers['content-type'] : '';
|
||||
$date = isset($request->headers['date']) ? $request->headers['date'] : '';
|
||||
|
||||
$result = $request->method . "\n" .
|
||||
$accept . "\n" .
|
||||
$contentMD5 . "\n" .
|
||||
$contentType . "\n" .
|
||||
$date . "\n";
|
||||
|
||||
$canonicalizedHeaders = self::getCanonicalizedHeaders($request->headers);
|
||||
$canonicalizedResource = self::getCanonicalizedResource($pathname, $query);
|
||||
|
||||
return $result . $canonicalizedHeaders . $canonicalizedResource;
|
||||
}
|
||||
|
||||
private static function getCanonicalizedHeaders($headers, $prefix = 'x-acs-')
|
||||
{
|
||||
ksort($headers);
|
||||
$str = '';
|
||||
foreach ($headers as $k => $v) {
|
||||
if (0 === strpos(strtolower($k), $prefix)) {
|
||||
$str .= $k . ':' . trim(self::filter($v)) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
private static function getCanonicalizedResource($pathname, $query)
|
||||
{
|
||||
if (0 === \count($query)) {
|
||||
return $pathname;
|
||||
}
|
||||
ksort($query);
|
||||
$tmp = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (!empty($v)) {
|
||||
$tmp[] = $k . '=' . $v;
|
||||
} else {
|
||||
$tmp[] = $k;
|
||||
}
|
||||
}
|
||||
|
||||
return $pathname . '?' . implode('&', $tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get signature according to stringToSign, secret
|
||||
*
|
||||
* @param string $stringToSign The signed string
|
||||
* @param string $secret Accesskey secret
|
||||
* @return string The signature
|
||||
*/
|
||||
static public function getROASignature($stringToSign, $secret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse filter into a form string
|
||||
*
|
||||
* @param mixed[] $filter Object
|
||||
* @return string The string
|
||||
*/
|
||||
static public function toForm($filter)
|
||||
{
|
||||
$query = $filter;
|
||||
if (null === $query) {
|
||||
return '';
|
||||
}
|
||||
if ($query instanceof Model) {
|
||||
$query = $query->toMap();
|
||||
}
|
||||
$tmp = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (0 !== strpos($k, '_')) {
|
||||
$tmp[$k] = $v;
|
||||
}
|
||||
}
|
||||
$res = self::flatten($tmp);
|
||||
ksort($res);
|
||||
|
||||
return http_build_query($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get timestamp
|
||||
* @returns the timestamp string
|
||||
* @return string
|
||||
*/
|
||||
static public function getTimestamp()
|
||||
{
|
||||
return gmdate('Y-m-d\\TH:i:s\\Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get UTC string
|
||||
* @returns the UTC string
|
||||
* @return string
|
||||
*/
|
||||
static public function getDateUTCString()
|
||||
{
|
||||
return gmdate('D, d M Y H:i:s T');
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse filter into a object which's type is map[string]string
|
||||
*
|
||||
* @param mixed[] $filter Query param
|
||||
* @return string[] The object
|
||||
*/
|
||||
static public function query($filter)
|
||||
{
|
||||
if (null === $filter) {
|
||||
return [];
|
||||
}
|
||||
$dict = $filter;
|
||||
if ($dict instanceof Model) {
|
||||
$dict = $dict->toMap();
|
||||
}
|
||||
$tmp = [];
|
||||
foreach ($dict as $k => $v) {
|
||||
if (0 !== strpos($k, '_')) {
|
||||
$tmp[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return self::flatten($tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get signature according to signedParams, method and secret
|
||||
*
|
||||
* @param string[] $signedParams Params which need to be signed
|
||||
* @param string $method HTTP method e.g. GET
|
||||
* @param string $secret AccessKeySecret
|
||||
* @return string The signature
|
||||
*/
|
||||
static public function getRPCSignature($signedParams, $method, $secret)
|
||||
{
|
||||
$secret .= '&';
|
||||
$strToSign = self::getRpcStrToSign($method, $signedParams);
|
||||
|
||||
$signMethod = 'HMAC-SHA1';
|
||||
|
||||
return self::encode($signMethod, $strToSign, $secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse array into a string with specified style
|
||||
*
|
||||
* @param mixed $object The array
|
||||
* @param string $prefix The prefix string
|
||||
* @param string $style The style
|
||||
* @return string The string
|
||||
*/
|
||||
static public function arrayToStringWithSpecifiedStyle($object, $prefix, $style)
|
||||
{
|
||||
if (null === $object) {
|
||||
return '';
|
||||
}
|
||||
if ('repeatList' === $style) {
|
||||
return self::toForm([$prefix => $object]);
|
||||
}
|
||||
if ('simple' == $style || 'spaceDelimited' == $style || 'pipeDelimited' == $style) {
|
||||
$strs = self::flatten($object);
|
||||
|
||||
switch ($style) {
|
||||
case 'spaceDelimited':
|
||||
return implode(' ', $strs);
|
||||
|
||||
case 'pipeDelimited':
|
||||
return implode('|', $strs);
|
||||
|
||||
default:
|
||||
return implode(',', $strs);
|
||||
}
|
||||
} elseif ('json' === $style) {
|
||||
self::parse($object, $parsed);
|
||||
return json_encode($parsed);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Transform input as map.
|
||||
* @param mixed $input
|
||||
* @return mixed[]
|
||||
*/
|
||||
static public function parseToMap($input)
|
||||
{
|
||||
self::parse($input, $result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get the authorization
|
||||
*
|
||||
* @param Request $request Request params
|
||||
* @param string $signatureAlgorithm The autograph method
|
||||
* @param string $payload The hashed request
|
||||
* @param string $accesskey The accesskey string
|
||||
* @param string $accessKeySecret The accessKeySecret string
|
||||
* @return string Authorization string
|
||||
*/
|
||||
static public function getAuthorization($request, $signatureAlgorithm, $payload, $accesskey, $accessKeySecret)
|
||||
{
|
||||
$canonicalURI = $request->pathname ? $request->pathname : '/';
|
||||
$query = $request->query ?: [];
|
||||
$method = strtoupper($request->method);
|
||||
$canonicalQueryString = self::getCanonicalQueryString($query);
|
||||
$signHeaders = [];
|
||||
foreach ($request->headers as $k => $v) {
|
||||
$k = strtolower($k);
|
||||
if (0 === strpos($k, 'x-acs-') || 'host' === $k || 'content-type' === $k) {
|
||||
$signHeaders[$k] = $v;
|
||||
}
|
||||
}
|
||||
ksort($signHeaders);
|
||||
$headers = [];
|
||||
foreach ($request->headers as $k => $v) {
|
||||
$k = strtolower($k);
|
||||
if (0 === strpos($k, 'x-acs-') || 'host' === $k || 'content-type' === $k) {
|
||||
$headers[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
$canonicalHeaderString = '';
|
||||
ksort($headers);
|
||||
foreach ($headers as $k => $v) {
|
||||
$canonicalHeaderString .= $k . ':' . trim(self::filter($v)) . "\n";
|
||||
}
|
||||
if (empty($canonicalHeaderString)) {
|
||||
$canonicalHeaderString = "\n";
|
||||
}
|
||||
|
||||
$canonicalRequest = $method . "\n" . $canonicalURI . "\n" . $canonicalQueryString . "\n" .
|
||||
$canonicalHeaderString . "\n" . implode(';', array_keys($signHeaders)) . "\n" . $payload;
|
||||
$strtosign = $signatureAlgorithm . "\n" . bin2hex(self::hash(BytesUtil::from($canonicalRequest), $signatureAlgorithm));
|
||||
|
||||
$signature = self::sign($accessKeySecret, $strtosign, $signatureAlgorithm);
|
||||
$signature = bin2hex($signature);
|
||||
|
||||
return $signatureAlgorithm .
|
||||
' Credential=' . $accesskey .
|
||||
',SignedHeaders=' . implode(';', array_keys($signHeaders)) .
|
||||
',Signature=' . $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userAgent
|
||||
* @return string
|
||||
*/
|
||||
static public function getUserAgent($userAgent)
|
||||
{
|
||||
if (empty(self::$defaultUserAgent)) {
|
||||
self::$defaultUserAgent = sprintf('AlibabaCloud (%s; %s) PHP/%s Core/1.0 TeaDSL/2', PHP_OS, \PHP_SAPI, PHP_VERSION);
|
||||
}
|
||||
if (!empty($userAgent)) {
|
||||
return self::$defaultUserAgent . ' ' . $userAgent;
|
||||
}
|
||||
|
||||
return self::$defaultUserAgent;
|
||||
}
|
||||
|
||||
private static function filter($str)
|
||||
{
|
||||
return str_replace(["\t", "\n", "\r", "\f"], '', $str);
|
||||
}
|
||||
|
||||
public static function sign($secret, $str, $algorithm)
|
||||
{
|
||||
$result = '';
|
||||
switch ($algorithm) {
|
||||
case 'ACS3-HMAC-SHA256':
|
||||
$result = hash_hmac('sha256', $str, $secret, true);
|
||||
break;
|
||||
case 'ACS3-HMAC-SM3':
|
||||
$result = self::hmac_sm3($str, $secret, true);
|
||||
break;
|
||||
case 'ACS3-RSA-SHA256':
|
||||
$privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" . $secret . "\n-----END RSA PRIVATE KEY-----";
|
||||
@openssl_sign($str, $result, $privateKey, OPENSSL_ALGO_SHA256);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function hmac_sm3($data, $key, $raw_output = false)
|
||||
{
|
||||
$pack = 'H' . \strlen(self::sm3('test'));
|
||||
$blocksize = 64;
|
||||
if (\strlen($key) > $blocksize) {
|
||||
$key = pack($pack, self::sm3($key));
|
||||
}
|
||||
$key = str_pad($key, $blocksize, \chr(0x00));
|
||||
$ipad = $key ^ str_repeat(\chr(0x36), $blocksize);
|
||||
$opad = $key ^ str_repeat(\chr(0x5C), $blocksize);
|
||||
$hmac = self::sm3($opad . pack($pack, self::sm3($ipad . $data)));
|
||||
|
||||
return $raw_output ? pack($pack, $hmac) : $hmac;
|
||||
}
|
||||
|
||||
private static function sm3($message)
|
||||
{
|
||||
return (new Sm3())->sign($message);
|
||||
}
|
||||
|
||||
private static function encode($signMethod, $strToSign, $secret)
|
||||
{
|
||||
switch ($signMethod) {
|
||||
case 'HMAC-SHA256':
|
||||
return base64_encode(hash_hmac('sha256', $strToSign, $secret, true));
|
||||
default:
|
||||
return base64_encode(hash_hmac('sha1', $strToSign, $secret, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $items
|
||||
* @param string $delimiter
|
||||
* @param string $prepend
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function flatten($items = [], $delimiter = '.', $prepend = '')
|
||||
{
|
||||
$flatten = [];
|
||||
|
||||
foreach ($items as $key => $value) {
|
||||
$pos = \is_int($key) ? $key + 1 : $key;
|
||||
|
||||
if ($value instanceof Model) {
|
||||
$value = $value->toMap();
|
||||
} elseif (\is_object($value)) {
|
||||
$value = get_object_vars($value);
|
||||
}
|
||||
|
||||
if (\is_array($value) && !empty($value)) {
|
||||
$flatten = array_merge(
|
||||
$flatten,
|
||||
self::flatten($value, $delimiter, $prepend . $pos . $delimiter)
|
||||
);
|
||||
} else {
|
||||
if (\is_bool($value)) {
|
||||
$value = true === $value ? 'true' : 'false';
|
||||
}
|
||||
$flatten[$prepend . $pos] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $flatten;
|
||||
}
|
||||
|
||||
private static function parse($input, &$output)
|
||||
{
|
||||
if (null === $input || '' === $input) {
|
||||
$output = [];
|
||||
}
|
||||
$recursive = function ($input) use (&$recursive) {
|
||||
if ($input instanceof Model) {
|
||||
$input = $input->toMap();
|
||||
} elseif (\is_object($input)) {
|
||||
$input = get_object_vars($input);
|
||||
}
|
||||
if (!\is_array($input)) {
|
||||
return $input;
|
||||
}
|
||||
$data = [];
|
||||
foreach ($input as $k => $v) {
|
||||
$data[$k] = $recursive($v);
|
||||
}
|
||||
|
||||
return $data;
|
||||
};
|
||||
$output = $recursive($input);
|
||||
if (!\is_array($output)) {
|
||||
$output = [$output];
|
||||
}
|
||||
}
|
||||
|
||||
private static function getRpcStrToSign($method, $query)
|
||||
{
|
||||
ksort($query);
|
||||
|
||||
$params = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (null !== $v) {
|
||||
$k = rawurlencode($k);
|
||||
$v = rawurlencode($v);
|
||||
$params[] = $k . '=' . (string)$v;
|
||||
}
|
||||
}
|
||||
$str = implode('&', $params);
|
||||
|
||||
return $method . '&' . rawurlencode('/') . '&' . rawurlencode($str);
|
||||
}
|
||||
|
||||
private static function getCanonicalQueryString($query)
|
||||
{
|
||||
ksort($query);
|
||||
|
||||
$params = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (null === $v) {
|
||||
continue;
|
||||
}
|
||||
$str = rawurlencode($k);
|
||||
if ('' !== $v && null !== $v) {
|
||||
$str .= '=' . rawurlencode($v);
|
||||
} else {
|
||||
$str .= '=';
|
||||
}
|
||||
$params[] = $str;
|
||||
}
|
||||
|
||||
return implode('&', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform input as array.
|
||||
*
|
||||
* @param mixed $input
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toArray($input)
|
||||
{
|
||||
if (\is_array($input)) {
|
||||
foreach ($input as $k => &$v) {
|
||||
$v = self::toArray($v);
|
||||
}
|
||||
} elseif ($input instanceof Model) {
|
||||
$input = $input->toMap();
|
||||
foreach ($input as $k => &$v) {
|
||||
$v = self::toArray($v);
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the value of map.
|
||||
*
|
||||
* @param array $map
|
||||
*
|
||||
* @return array the new stringified map
|
||||
*/
|
||||
public static function stringifyMapValue($map)
|
||||
{
|
||||
if (null === $map) {
|
||||
return [];
|
||||
}
|
||||
foreach ($map as &$node) {
|
||||
if (is_numeric($node)) {
|
||||
$node = (string) $node;
|
||||
} elseif (null === $node) {
|
||||
$node = '';
|
||||
} elseif (\is_bool($node)) {
|
||||
$node = true === $node ? 'true' : 'false';
|
||||
} elseif (\is_object($node)) {
|
||||
$node = json_decode(json_encode($node), true);
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
/**
|
||||
* @param string $product
|
||||
* @param string $regionId
|
||||
* @param string $endpointRule
|
||||
* @param string $network
|
||||
* @param string $suffix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function getEndpointRules($product, $regionId, $endpointType, $network, $suffix = null) {
|
||||
$product = $product ?: "";
|
||||
$network = $network ?: "";
|
||||
|
||||
if ($endpointType == "regional") {
|
||||
if ($regionId === null || $regionId === "") {
|
||||
throw new RuntimeException("RegionId is empty, please set a valid RegionId");
|
||||
}
|
||||
$result = "<product><network>.<region_id>.aliyuncs.com";
|
||||
$result = str_replace("<region_id>", $regionId, $result);
|
||||
} else {
|
||||
$result = "<product><network>.aliyuncs.com";
|
||||
}
|
||||
|
||||
$result = str_replace("<product>", strtolower($product), $result);
|
||||
if ($network === "" || $network === "public") {
|
||||
$result = str_replace("<network>", "", $result);
|
||||
} else {
|
||||
$result = str_replace("<network>", "-" . $network, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $product
|
||||
* @param string $regionId
|
||||
* @param string $endpointRule
|
||||
* @param string $network
|
||||
* @param string $suffix
|
||||
* @param string[] $endpointMap
|
||||
* @param string $endpoint
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getProductEndpoint($product, $regionId, $endpointRule, $network, $suffix, $endpointMap, $endpoint)
|
||||
{
|
||||
if (null !== $endpoint) {
|
||||
return $endpoint;
|
||||
}
|
||||
|
||||
if (null !== $endpointMap && null !== @$endpointMap[$regionId]) {
|
||||
return @$endpointMap[$regionId];
|
||||
}
|
||||
|
||||
return self::getEndpointRules($product, $regionId, $endpointRule, $network, $suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a map to a flat style map where keys are prefixed with length info.
|
||||
* Map keys are transformed from "key" to "#length#key" format.
|
||||
*
|
||||
* @param mixed $input the input (can be an array, Model, or primitive type)
|
||||
* @return mixed the transformed input
|
||||
*/
|
||||
public static function mapToFlatStyle($input)
|
||||
{
|
||||
if ($input === null) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
// Handle array (list)
|
||||
if (\is_array($input) && array_keys($input) === range(0, count($input) - 1)) {
|
||||
$result = [];
|
||||
foreach ($input as $item) {
|
||||
$result[] = self::mapToFlatStyle($item);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Handle Model
|
||||
if ($input instanceof Model) {
|
||||
// Modify the original Model object's fields using reflection
|
||||
$reflection = new \ReflectionClass($input);
|
||||
$properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$propertyName = $property->getName();
|
||||
$value = $property->getValue($input);
|
||||
|
||||
if (\is_array($value) && !empty($value) && array_keys($value) !== range(0, count($value) - 1)) {
|
||||
// This is an associative array (dictionary), apply flat style to keys
|
||||
$flatMap = [];
|
||||
foreach ($value as $nestedKey => $nestedValue) {
|
||||
$flatKey = '#' . strlen($nestedKey) . '#' . $nestedKey;
|
||||
$flatMap[$flatKey] = self::mapToFlatStyle($nestedValue);
|
||||
}
|
||||
$property->setValue($input, $flatMap);
|
||||
} else {
|
||||
// Recursively process other fields
|
||||
$property->setValue($input, self::mapToFlatStyle($value));
|
||||
}
|
||||
}
|
||||
return $input; // Return the modified original Model
|
||||
}
|
||||
|
||||
// Handle associative array (dictionary)
|
||||
if (\is_array($input) && !empty($input)) {
|
||||
$flatMap = [];
|
||||
foreach ($input as $key => $value) {
|
||||
$flatKey = '#' . strlen($key) . '#' . $key;
|
||||
$flatMap[$flatKey] = self::mapToFlatStyle($value);
|
||||
}
|
||||
return $flatMap;
|
||||
}
|
||||
|
||||
// For primitive types, return as-is
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user