init commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?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
|
||||
*/
|
||||
protected $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 getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class ClientException extends DaraException {
|
||||
/**
|
||||
* @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,15 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class ServerException extends DaraException {
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class ThrottlingException extends DaraException {
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
1867
addons/wdsxh/library/alibabacloud/openapi-core/src/OpenApiClient.php
Normal file
1867
addons/wdsxh/library/alibabacloud/openapi-core/src/OpenApiClient.php
Normal file
File diff suppressed because it is too large
Load Diff
684
addons/wdsxh/library/alibabacloud/openapi-core/src/Utils.php
Normal file
684
addons/wdsxh/library/alibabacloud/openapi-core/src/Utils.php
Normal file
@@ -0,0 +1,684 @@
|
||||
<?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;
|
||||
/**
|
||||
* @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 body - source Model
|
||||
* @param content - target Model
|
||||
* @returns void
|
||||
* @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 serverUse - whether use accelerate endpoint
|
||||
* @param endpointType - value must be internal or accelerate
|
||||
* @returns the final endpoint
|
||||
* @param string $endpoint
|
||||
* @param boolean $useAccelerate
|
||||
* @param string $endpointType
|
||||
* @return string
|
||||
*/
|
||||
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 the - response headers
|
||||
* @returns time left
|
||||
* @param string[] $headers
|
||||
* @return int
|
||||
*/
|
||||
public static function getThrottlingTimeLeft(array $headers): int {
|
||||
$rateLimitForUserApi = $headers["x-ratelimit-user-api"] ?? null;
|
||||
$rateLimitForUser = $headers["x-ratelimit-user"] ?? null;
|
||||
|
||||
$timeLeftForUserApi = self::getTimeLeft($rateLimitForUserApi);
|
||||
$timeLeftForUser = self::getTimeLeft($rateLimitForUser);
|
||||
|
||||
return max($timeLeftForUserApi, $timeLeftForUser);
|
||||
}
|
||||
|
||||
|
||||
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 raw - hashing data
|
||||
* @param signatureAlgorithm - the autograph method
|
||||
* @returns hashed bytes
|
||||
* @param int[] $raw
|
||||
* @param string $signatureAlgorithm
|
||||
* @return int[]
|
||||
*/
|
||||
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 - which contains signed messages
|
||||
* @returns the signed string
|
||||
* @param Request $request
|
||||
* @return 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 stringToSign - the signed string
|
||||
* @param secret - accesskey secret
|
||||
* @returns the signature
|
||||
* @param string $stringToSign
|
||||
* @param string $secret
|
||||
* @return string
|
||||
*/
|
||||
static public function getROASignature($stringToSign, $secret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse filter into a form string
|
||||
*
|
||||
* @param filter - object
|
||||
* @returns the string
|
||||
* @param mixed[] $filter
|
||||
* @return 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 filter - query param
|
||||
* @returns the object
|
||||
* @param mixed[] $filter
|
||||
* @return string[]
|
||||
*/
|
||||
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 signedParams - params which need to be signed
|
||||
* @param method - http method e.g. GET
|
||||
* @param secret - AccessKeySecret
|
||||
* @returns the signature
|
||||
* @param string[] $signedParams
|
||||
* @param string $method
|
||||
* @param string $secret
|
||||
* @return string
|
||||
*/
|
||||
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 array - the array
|
||||
* @param prefix - the prefix string
|
||||
* @returns the string
|
||||
* @param mixed $array_
|
||||
* @param string $prefix
|
||||
* @param string $style
|
||||
* @return 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 params
|
||||
* @param signatureAlgorithm - the autograph method
|
||||
* @param payload - the hashed request
|
||||
* @param acesskey - the acesskey string
|
||||
* @param accessKeySecret - the accessKeySecret string
|
||||
* @returns authorization string
|
||||
* @param Request $request
|
||||
* @param string $signatureAlgorithm
|
||||
* @param string $payload
|
||||
* @param string $acesskey
|
||||
* @param string $accessKeySecret
|
||||
* @return 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user