.gitignore000064400000000521147133776160006551 0ustar00composer.phar /vendor/ # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file composer.lock .vscode/ .idea .DS_Store cache/ *.cache runtime/ .php_cs.cache .php_cs.dist000064400000005666147133776160007017 0ustar00setRiskyAllowed(true) ->setIndent(' ') ->setRules([ '@PSR2' => true, '@PhpCsFixer' => true, '@Symfony:risky' => true, 'concat_space' => ['spacing' => 'one'], 'array_syntax' => ['syntax' => 'short'], 'array_indentation' => true, 'combine_consecutive_unsets' => true, 'method_separation' => true, 'single_quote' => true, 'declare_equal_normalize' => true, 'function_typehint_space' => true, 'hash_to_slash_comment' => true, 'include' => true, 'lowercase_cast' => true, 'no_multiline_whitespace_before_semicolons' => true, 'no_leading_import_slash' => true, 'no_multiline_whitespace_around_double_arrow' => true, 'no_spaces_around_offset' => true, 'no_unneeded_control_parentheses' => true, 'no_unused_imports' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'object_operator_without_whitespace' => true, 'single_blank_line_before_namespace' => true, 'single_class_element_per_statement' => true, 'space_after_semicolon' => true, 'standardize_not_equals' => true, 'ternary_operator_spaces' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true, 'no_extra_consecutive_blank_lines' => [ 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'throw', 'use', ], 'binary_operator_spaces' => [ 'align_double_arrow' => true, 'align_equals' => true, ], 'braces' => [ 'allow_single_line_closure' => true, ], ]) ->setFinder( PhpCsFixer\Finder::create() ->exclude('vendor') ->exclude('tests') ->in(__DIR__) ); README-CN.md000064400000001217147133776160006341 0ustar00[English](README.md) | 简体中文 ![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) ## Alibaba Cloud OpenApi Client ## 安装 ### Composer ```bash composer require alibabacloud/darabonba-openapi ``` ## 问题 [提交 Issue](https://github.com/aliyun/darabonba-openapi/issues/new),不符合指南的问题可能会立即关闭。 ## 发行说明 每个版本的详细更改记录在[发行说明](./ChangeLog.txt)中。 ## 相关 * [最新源码](https://github.com/aliyun/darabonba-openapi) ## 许可证 [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) Copyright (c) 2009-present, Alibaba Cloud All rights reserved. README.md000064400000001276147133776160006050 0ustar00English | [简体中文](README-CN.md) ![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) ## Alibaba Cloud OpenApi Client ## Installation ### Composer ```bash composer require alibabacloud/darabonba-openapi ``` ## Issues [Opening an Issue](https://github.com/aliyun/darabonba-openapi/issues/new), Issues not conforming to the guidelines may be closed immediately. ## Changelog Detailed changes for each release are documented in the [release notes](./ChangeLog.txt). ## References * [Latest Release](https://github.com/aliyun/darabonba-openapi) ## License [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) Copyright (c) 2009-present, Alibaba Cloud All rights reserved. autoload.php000064400000001053147133776160007103 0ustar005.5", "alibabacloud/tea-utils": "^0.2.21", "alibabacloud/credentials": "^1.1", "alibabacloud/openapi-util": "^0.1.10|^0.2.1", "alibabacloud/gateway-spi": "^1", "alibabacloud/tea-xml": "^0.2" }, "autoload": { "psr-4": { "Darabonba\\OpenApi\\": "src" } }, "scripts": { "fixer": "php-cs-fixer fix ./" }, "config": { "sort-packages": true, "preferred-install": "dist", "optimize-autoloader": true }, "prefer-stable": true }phpunit.xml000064400000002044147133776160006774 0ustar00 tests ./tests/Unit integration ./src src/Models/Config.php000064400000026334147133776160010523 0ustar00 '', 'accessKeySecret' => '', 'securityToken' => '', 'bearerToken' => '', 'protocol' => 'http', 'method' => '', 'regionId' => '', 'readTimeout' => '', 'connectTimeout' => '', 'httpProxy' => '', 'httpsProxy' => '', 'credential' => '', 'endpoint' => '', 'noProxy' => '', 'maxIdleConns' => '', 'network' => '', 'userAgent' => '', 'suffix' => '', 'socks5Proxy' => '', 'socks5NetWork' => '', 'endpointType' => '', 'openPlatformEndpoint' => '', 'type' => '', 'signatureVersion' => '', 'signatureAlgorithm' => '', 'key' => '', 'cert' => '', 'ca' => '', ]; public function validate() { } public function toMap() { $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'] = null !== $this->credential ? $this->credential->toMap() : null; } 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->toMap() : null; } 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; } return $res; } /** * @param array $map * @return Config */ 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 = Credential::fromMap($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']; } return $model; } /** * @description accesskey id * @var string */ public $accessKeyId; /** * @description accesskey secret * @var string */ public $accessKeySecret; /** * @description security token * @example a.txt * @var string */ public $securityToken; /** * @description bearer token * @example the-bearer-token * @var string */ public $bearerToken; /** * @description http protocol * @example http * @var string */ public $protocol; /** * @description http method * @example GET * @var string */ public $method; /** * @description region id * @example cn-hangzhou * @var string */ public $regionId; /** * @description read timeout * @example 10 * @var int */ public $readTimeout; /** * @description connect timeout * @example 10 * @var int */ public $connectTimeout; /** * @description http proxy * @example http://localhost * @var string */ public $httpProxy; /** * @description https proxy * @example https://localhost * @var string */ public $httpsProxy; /** * @description credential * @example * @var Credential */ public $credential; /** * @description endpoint * @example cs.aliyuncs.com * @var string */ public $endpoint; /** * @description proxy white list * @example http://localhost * @var string */ public $noProxy; /** * @description max idle conns * @example 3 * @var int */ public $maxIdleConns; /** * @description network for endpoint * @example public * @var string */ public $network; /** * @description user agent * @example Alibabacloud/1 * @var string */ public $userAgent; /** * @description suffix for endpoint * @example aliyun * @var string */ public $suffix; /** * @description socks5 proxy * @var string */ public $socks5Proxy; /** * @description socks5 network * @example TCP * @var string */ public $socks5NetWork; /** * @description endpoint type * @example internal * @var string */ public $endpointType; /** * @description OpenPlatform endpoint * @example openplatform.aliyuncs.com * @var string */ public $openPlatformEndpoint; /** * @description credential type * @example access_key * @deprecated * @var string */ public $type; /** * @description Signature Version * @example v1 * @var string */ public $signatureVersion; /** * @description Signature Algorithm * @example ACS3-HMAC-SHA256 * @var string */ public $signatureAlgorithm; /** * @description Global Parameters * @var GlobalParameters */ public $globalParameters; /** * @description privite key for client certificate * @example MIIEvQ * @var string */ public $key; /** * @description client certificate * @example -----BEGIN CERTIFICATE-----xxx-----END CERTIFICATE----- * @var string */ public $cert; /** * @description server certificate * @example -----BEGIN CERTIFICATE-----xxx-----END CERTIFICATE----- * @var string */ public $ca; /** * @description disable HTTP/2 * @example false * @var bool */ public $disableHttp2; } src/Models/GlobalParameters.php000064400000001603147133776160012532 0ustar00headers) { $res['headers'] = $this->headers; } if (null !== $this->queries) { $res['queries'] = $this->queries; } return $res; } /** * @param array $map * @return GlobalParameters */ public static function fromMap($map = []) { $model = new self(); if (isset($map['headers'])) { $model->headers = $map['headers']; } if (isset($map['queries'])) { $model->queries = $map['queries']; } return $model; } public $headers; public $queries; } src/Models/OpenApiRequest.php000064400000003344147133776160012216 0ustar00headers) { $res['headers'] = $this->headers; } if (null !== $this->query) { $res['query'] = $this->query; } if (null !== $this->body) { $res['body'] = $this->body; } if (null !== $this->stream) { $res['stream'] = $this->stream; } if (null !== $this->hostMap) { $res['hostMap'] = $this->hostMap; } if (null !== $this->endpointOverride) { $res['endpointOverride'] = $this->endpointOverride; } return $res; } /** * @param array $map * @return OpenApiRequest */ public static function fromMap($map = []) { $model = new self(); if (isset($map['headers'])) { $model->headers = $map['headers']; } if (isset($map['query'])) { $model->query = $map['query']; } if (isset($map['body'])) { $model->body = $map['body']; } if (isset($map['stream'])) { $model->stream = $map['stream']; } if (isset($map['hostMap'])) { $model->hostMap = $map['hostMap']; } if (isset($map['endpointOverride'])) { $model->endpointOverride = $map['endpointOverride']; } return $model; } public $headers; public $query; public $body; public $stream; public $hostMap; public $endpointOverride; } src/Models/Params.php000064400000006213147133776160010533 0ustar00action, 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); } public function toMap() { $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; } /** * @param array $map * @return Params */ 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; } /** * @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; public $style; } src/OpenApiClient.php000064400000166240147133776160010566 0ustar00 "ParameterMissing", "message" => "'config' can not be unset" ]); } if (!Utils::empty_($config->accessKeyId) && !Utils::empty_($config->accessKeySecret)) { if (!Utils::empty_($config->securityToken)) { $config->type = "sts"; } else { $config->type = "access_key"; } $credentialConfig = new Config([ "accessKeyId" => $config->accessKeyId, "type" => $config->type, "accessKeySecret" => $config->accessKeySecret ]); $credentialConfig->securityToken = $config->securityToken; $this->_credential = new Credential($credentialConfig); } else if (!Utils::empty_($config->bearerToken)) { $cc = new Config([ "type" => "bearer", "bearerToken" => $config->bearerToken ]); $this->_credential = new Credential($cc); } else if (!Utils::isUnset($config->credential)) { $this->_credential = $config->credential; } $this->_endpoint = $config->endpoint; $this->_endpointType = $config->endpointType; $this->_network = $config->network; $this->_suffix = $config->suffix; $this->_protocol = $config->protocol; $this->_method = $config->method; $this->_regionId = $config->regionId; $this->_userAgent = $config->userAgent; $this->_readTimeout = $config->readTimeout; $this->_connectTimeout = $config->connectTimeout; $this->_httpProxy = $config->httpProxy; $this->_httpsProxy = $config->httpsProxy; $this->_noProxy = $config->noProxy; $this->_socks5Proxy = $config->socks5Proxy; $this->_socks5NetWork = $config->socks5NetWork; $this->_maxIdleConns = $config->maxIdleConns; $this->_signatureVersion = $config->signatureVersion; $this->_signatureAlgorithm = $config->signatureAlgorithm; $this->_globalParameters = $config->globalParameters; $this->_key = $config->key; $this->_cert = $config->cert; $this->_ca = $config->ca; $this->_disableHttp2 = $config->disableHttp2; } /** * Encapsulate the request and invoke the network * @param string $action api name * @param string $version product version * @param string $protocol http or https * @param string $method e.g. GET * @param string $authType authorization type e.g. AK * @param string $bodyType response body type e.g. String * @param OpenApiRequest $request object of OpenApiRequest * @param RuntimeOptions $runtime which controls some details of call api, such as retry times * @return array the response * @throws TeaError * @throws Exception * @throws TeaUnableRetryError */ public function doRPCRequest($action, $version, $protocol, $method, $authType, $bodyType, $request, $runtime) { $request->validate(); $runtime->validate(); $_runtime = [ "timeouted" => "retry", "key" => Utils::defaultString($runtime->key, $this->_key), "cert" => Utils::defaultString($runtime->cert, $this->_cert), "ca" => Utils::defaultString($runtime->ca, $this->_ca), "readTimeout" => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout), "connectTimeout" => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout), "httpProxy" => Utils::defaultString($runtime->httpProxy, $this->_httpProxy), "httpsProxy" => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy), "noProxy" => Utils::defaultString($runtime->noProxy, $this->_noProxy), "socks5Proxy" => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy), "socks5NetWork" => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork), "maxIdleConns" => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns), "retry" => [ "retryable" => $runtime->autoretry, "maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3) ], "backoff" => [ "policy" => Utils::defaultString($runtime->backoffPolicy, "no"), "period" => Utils::defaultNumber($runtime->backoffPeriod, 1) ], "ignoreSSL" => $runtime->ignoreSSL ]; $_lastRequest = null; $_lastException = null; $_now = time(); $_retryTimes = 0; while (Tea::allowRetry(@$_runtime["retry"], $_retryTimes, $_now)) { if ($_retryTimes > 0) { $_backoffTime = Tea::getBackoffTime(@$_runtime["backoff"], $_retryTimes); if ($_backoffTime > 0) { Tea::sleep($_backoffTime); } } $_retryTimes = $_retryTimes + 1; try { $_request = new Request(); $_request->protocol = Utils::defaultString($this->_protocol, $protocol); $_request->method = $method; $_request->pathname = "/"; $globalQueries = []; $globalHeaders = []; if (!Utils::isUnset($this->_globalParameters)) { $globalParams = $this->_globalParameters; if (!Utils::isUnset($globalParams->queries)) { $globalQueries = $globalParams->queries; } if (!Utils::isUnset($globalParams->headers)) { $globalHeaders = $globalParams->headers; } } $extendsHeaders = []; $extendsQueries = []; if (!Utils::isUnset($runtime->extendsParameters)) { $extendsParameters = $runtime->extendsParameters; if (!Utils::isUnset($extendsParameters->headers)) { $extendsHeaders = $extendsParameters->headers; } if (!Utils::isUnset($extendsParameters->queries)) { $extendsQueries = $extendsParameters->queries; } } $_request->query = Tea::merge([ "Action" => $action, "Format" => "json", "Version" => $version, "Timestamp" => OpenApiUtilClient::getTimestamp(), "SignatureNonce" => Utils::getNonce() ], $globalQueries, $extendsQueries, $request->query); $headers = $this->getRpcHeaders(); if (Utils::isUnset($headers)) { // endpoint is setted in product client $_request->headers = Tea::merge([ "host" => $this->_endpoint, "x-acs-version" => $version, "x-acs-action" => $action, "user-agent" => $this->getUserAgent() ], $globalHeaders, $extendsHeaders); } else { $_request->headers = Tea::merge([ "host" => $this->_endpoint, "x-acs-version" => $version, "x-acs-action" => $action, "user-agent" => $this->getUserAgent() ], $globalHeaders, $extendsHeaders, $headers); } if (!Utils::isUnset($request->body)) { $m = Utils::assertAsMap($request->body); $tmp = Utils::anyifyMapValue(OpenApiUtilClient::query($m)); $_request->body = Utils::toFormString($tmp); $_request->headers["content-type"] = "application/x-www-form-urlencoded"; } if (!Utils::equalString($authType, "Anonymous")) { $credentialType = $this->getType(); if (Utils::equalString($credentialType, "bearer")) { $bearerToken = $this->getBearerToken(); $_request->query["BearerToken"] = $bearerToken; $_request->query["SignatureType"] = "BEARERTOKEN"; } else { $accessKeyId = $this->getAccessKeyId(); $accessKeySecret = $this->getAccessKeySecret(); $securityToken = $this->getSecurityToken(); if (!Utils::empty_($securityToken)) { $_request->query["SecurityToken"] = $securityToken; } $_request->query["SignatureMethod"] = "HMAC-SHA1"; $_request->query["SignatureVersion"] = "1.0"; $_request->query["AccessKeyId"] = $accessKeyId; $t = null; if (!Utils::isUnset($request->body)) { $t = Utils::assertAsMap($request->body); } $signedParam = Tea::merge($_request->query, OpenApiUtilClient::query($t)); $_request->query["Signature"] = OpenApiUtilClient::getRPCSignature($signedParam, $_request->method, $accessKeySecret); } } $_lastRequest = $_request; $_response = Tea::send($_request, $_runtime); if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) { $_res = Utils::readAsJSON($_response->body); $err = Utils::assertAsMap($_res); $requestId = self::defaultAny(@$err["RequestId"], @$err["requestId"]); @$err["statusCode"] = $_response->statusCode; throw new TeaError([ "code" => "" . (string) (self::defaultAny(@$err["Code"], @$err["code"])) . "", "message" => "code: " . (string) ($_response->statusCode) . ", " . (string) (self::defaultAny(@$err["Message"], @$err["message"])) . " request id: " . (string) ($requestId) . "", "data" => $err, "description" => "" . (string) (self::defaultAny(@$err["Description"], @$err["description"])) . "", "accessDeniedDetail" => self::defaultAny(@$err["AccessDeniedDetail"], @$err["accessDeniedDetail"]) ]); } if (Utils::equalString($bodyType, "binary")) { $resp = [ "body" => $_response->body, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; return $resp; } else if (Utils::equalString($bodyType, "byte")) { $byt = Utils::readAsBytes($_response->body); return [ "body" => $byt, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "string")) { $str = Utils::readAsString($_response->body); return [ "body" => $str, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "json")) { $obj = Utils::readAsJSON($_response->body); $res = Utils::assertAsMap($obj); return [ "body" => $res, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "array")) { $arr = Utils::readAsJSON($_response->body); return [ "body" => $arr, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else { return [ "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } } catch (Exception $e) { if (!($e instanceof TeaError)) { $e = new TeaError([], $e->getMessage(), $e->getCode(), $e); } if (Tea::isRetryable($e)) { $_lastException = $e; continue; } throw $e; } } throw new TeaUnableRetryError($_lastRequest, $_lastException); } /** * Encapsulate the request and invoke the network * @param string $action api name * @param string $version product version * @param string $protocol http or https * @param string $method e.g. GET * @param string $authType authorization type e.g. AK * @param string $pathname pathname of every api * @param string $bodyType response body type e.g. String * @param OpenApiRequest $request object of OpenApiRequest * @param RuntimeOptions $runtime which controls some details of call api, such as retry times * @return array the response * @throws TeaError * @throws Exception * @throws TeaUnableRetryError */ public function doROARequest($action, $version, $protocol, $method, $authType, $pathname, $bodyType, $request, $runtime) { $request->validate(); $runtime->validate(); $_runtime = [ "timeouted" => "retry", "key" => Utils::defaultString($runtime->key, $this->_key), "cert" => Utils::defaultString($runtime->cert, $this->_cert), "ca" => Utils::defaultString($runtime->ca, $this->_ca), "readTimeout" => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout), "connectTimeout" => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout), "httpProxy" => Utils::defaultString($runtime->httpProxy, $this->_httpProxy), "httpsProxy" => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy), "noProxy" => Utils::defaultString($runtime->noProxy, $this->_noProxy), "socks5Proxy" => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy), "socks5NetWork" => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork), "maxIdleConns" => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns), "retry" => [ "retryable" => $runtime->autoretry, "maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3) ], "backoff" => [ "policy" => Utils::defaultString($runtime->backoffPolicy, "no"), "period" => Utils::defaultNumber($runtime->backoffPeriod, 1) ], "ignoreSSL" => $runtime->ignoreSSL ]; $_lastRequest = null; $_lastException = null; $_now = time(); $_retryTimes = 0; while (Tea::allowRetry(@$_runtime["retry"], $_retryTimes, $_now)) { if ($_retryTimes > 0) { $_backoffTime = Tea::getBackoffTime(@$_runtime["backoff"], $_retryTimes); if ($_backoffTime > 0) { Tea::sleep($_backoffTime); } } $_retryTimes = $_retryTimes + 1; try { $_request = new Request(); $_request->protocol = Utils::defaultString($this->_protocol, $protocol); $_request->method = $method; $_request->pathname = $pathname; $globalQueries = []; $globalHeaders = []; if (!Utils::isUnset($this->_globalParameters)) { $globalParams = $this->_globalParameters; if (!Utils::isUnset($globalParams->queries)) { $globalQueries = $globalParams->queries; } if (!Utils::isUnset($globalParams->headers)) { $globalHeaders = $globalParams->headers; } } $extendsHeaders = []; $extendsQueries = []; if (!Utils::isUnset($runtime->extendsParameters)) { $extendsParameters = $runtime->extendsParameters; if (!Utils::isUnset($extendsParameters->headers)) { $extendsHeaders = $extendsParameters->headers; } if (!Utils::isUnset($extendsParameters->queries)) { $extendsQueries = $extendsParameters->queries; } } $_request->headers = Tea::merge([ "date" => Utils::getDateUTCString(), "host" => $this->_endpoint, "accept" => "application/json", "x-acs-signature-nonce" => Utils::getNonce(), "x-acs-signature-method" => "HMAC-SHA1", "x-acs-signature-version" => "1.0", "x-acs-version" => $version, "x-acs-action" => $action, "user-agent" => Utils::getUserAgent($this->_userAgent) ], $globalHeaders, $extendsHeaders, $request->headers); if (!Utils::isUnset($request->body)) { $_request->body = Utils::toJSONString($request->body); $_request->headers["content-type"] = "application/json; charset=utf-8"; } $_request->query = Tea::merge($globalQueries, $extendsQueries); if (!Utils::isUnset($request->query)) { $_request->query = Tea::merge($_request->query, $request->query); } if (!Utils::equalString($authType, "Anonymous")) { $credentialType = $this->getType(); if (Utils::equalString($credentialType, "bearer")) { $bearerToken = $this->getBearerToken(); $_request->headers["x-acs-bearer-token"] = $bearerToken; $_request->headers["x-acs-signature-type"] = "BEARERTOKEN"; } else { $accessKeyId = $this->getAccessKeyId(); $accessKeySecret = $this->getAccessKeySecret(); $securityToken = $this->getSecurityToken(); if (!Utils::empty_($securityToken)) { $_request->headers["x-acs-accesskey-id"] = $accessKeyId; $_request->headers["x-acs-security-token"] = $securityToken; } $stringToSign = OpenApiUtilClient::getStringToSign($_request); $_request->headers["authorization"] = "acs " . $accessKeyId . ":" . OpenApiUtilClient::getROASignature($stringToSign, $accessKeySecret) . ""; } } $_lastRequest = $_request; $_response = Tea::send($_request, $_runtime); if (Utils::equalNumber($_response->statusCode, 204)) { return [ "headers" => $_response->headers ]; } if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) { $_res = Utils::readAsJSON($_response->body); $err = Utils::assertAsMap($_res); $requestId = self::defaultAny(@$err["RequestId"], @$err["requestId"]); $requestId = self::defaultAny($requestId, @$err["requestid"]); @$err["statusCode"] = $_response->statusCode; throw new TeaError([ "code" => "" . (string) (self::defaultAny(@$err["Code"], @$err["code"])) . "", "message" => "code: " . (string) ($_response->statusCode) . ", " . (string) (self::defaultAny(@$err["Message"], @$err["message"])) . " request id: " . (string) ($requestId) . "", "data" => $err, "description" => "" . (string) (self::defaultAny(@$err["Description"], @$err["description"])) . "", "accessDeniedDetail" => self::defaultAny(@$err["AccessDeniedDetail"], @$err["accessDeniedDetail"]) ]); } if (Utils::equalString($bodyType, "binary")) { $resp = [ "body" => $_response->body, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; return $resp; } else if (Utils::equalString($bodyType, "byte")) { $byt = Utils::readAsBytes($_response->body); return [ "body" => $byt, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "string")) { $str = Utils::readAsString($_response->body); return [ "body" => $str, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "json")) { $obj = Utils::readAsJSON($_response->body); $res = Utils::assertAsMap($obj); return [ "body" => $res, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "array")) { $arr = Utils::readAsJSON($_response->body); return [ "body" => $arr, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else { return [ "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } } catch (Exception $e) { if (!($e instanceof TeaError)) { $e = new TeaError([], $e->getMessage(), $e->getCode(), $e); } if (Tea::isRetryable($e)) { $_lastException = $e; continue; } throw $e; } } throw new TeaUnableRetryError($_lastRequest, $_lastException); } /** * Encapsulate the request and invoke the network with form body * @param string $action api name * @param string $version product version * @param string $protocol http or https * @param string $method e.g. GET * @param string $authType authorization type e.g. AK * @param string $pathname pathname of every api * @param string $bodyType response body type e.g. String * @param OpenApiRequest $request object of OpenApiRequest * @param RuntimeOptions $runtime which controls some details of call api, such as retry times * @return array the response * @throws TeaError * @throws Exception * @throws TeaUnableRetryError */ public function doROARequestWithForm($action, $version, $protocol, $method, $authType, $pathname, $bodyType, $request, $runtime) { $request->validate(); $runtime->validate(); $_runtime = [ "timeouted" => "retry", "key" => Utils::defaultString($runtime->key, $this->_key), "cert" => Utils::defaultString($runtime->cert, $this->_cert), "ca" => Utils::defaultString($runtime->ca, $this->_ca), "readTimeout" => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout), "connectTimeout" => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout), "httpProxy" => Utils::defaultString($runtime->httpProxy, $this->_httpProxy), "httpsProxy" => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy), "noProxy" => Utils::defaultString($runtime->noProxy, $this->_noProxy), "socks5Proxy" => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy), "socks5NetWork" => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork), "maxIdleConns" => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns), "retry" => [ "retryable" => $runtime->autoretry, "maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3) ], "backoff" => [ "policy" => Utils::defaultString($runtime->backoffPolicy, "no"), "period" => Utils::defaultNumber($runtime->backoffPeriod, 1) ], "ignoreSSL" => $runtime->ignoreSSL ]; $_lastRequest = null; $_lastException = null; $_now = time(); $_retryTimes = 0; while (Tea::allowRetry(@$_runtime["retry"], $_retryTimes, $_now)) { if ($_retryTimes > 0) { $_backoffTime = Tea::getBackoffTime(@$_runtime["backoff"], $_retryTimes); if ($_backoffTime > 0) { Tea::sleep($_backoffTime); } } $_retryTimes = $_retryTimes + 1; try { $_request = new Request(); $_request->protocol = Utils::defaultString($this->_protocol, $protocol); $_request->method = $method; $_request->pathname = $pathname; $globalQueries = []; $globalHeaders = []; if (!Utils::isUnset($this->_globalParameters)) { $globalParams = $this->_globalParameters; if (!Utils::isUnset($globalParams->queries)) { $globalQueries = $globalParams->queries; } if (!Utils::isUnset($globalParams->headers)) { $globalHeaders = $globalParams->headers; } } $extendsHeaders = []; $extendsQueries = []; if (!Utils::isUnset($runtime->extendsParameters)) { $extendsParameters = $runtime->extendsParameters; if (!Utils::isUnset($extendsParameters->headers)) { $extendsHeaders = $extendsParameters->headers; } if (!Utils::isUnset($extendsParameters->queries)) { $extendsQueries = $extendsParameters->queries; } } $_request->headers = Tea::merge([ "date" => Utils::getDateUTCString(), "host" => $this->_endpoint, "accept" => "application/json", "x-acs-signature-nonce" => Utils::getNonce(), "x-acs-signature-method" => "HMAC-SHA1", "x-acs-signature-version" => "1.0", "x-acs-version" => $version, "x-acs-action" => $action, "user-agent" => Utils::getUserAgent($this->_userAgent) ], $globalHeaders, $extendsHeaders, $request->headers); if (!Utils::isUnset($request->body)) { $m = Utils::assertAsMap($request->body); $_request->body = OpenApiUtilClient::toForm($m); $_request->headers["content-type"] = "application/x-www-form-urlencoded"; } $_request->query = Tea::merge($globalQueries, $extendsQueries); if (!Utils::isUnset($request->query)) { $_request->query = Tea::merge($_request->query, $request->query); } if (!Utils::equalString($authType, "Anonymous")) { $credentialType = $this->getType(); if (Utils::equalString($credentialType, "bearer")) { $bearerToken = $this->getBearerToken(); $_request->headers["x-acs-bearer-token"] = $bearerToken; $_request->headers["x-acs-signature-type"] = "BEARERTOKEN"; } else { $accessKeyId = $this->getAccessKeyId(); $accessKeySecret = $this->getAccessKeySecret(); $securityToken = $this->getSecurityToken(); if (!Utils::empty_($securityToken)) { $_request->headers["x-acs-accesskey-id"] = $accessKeyId; $_request->headers["x-acs-security-token"] = $securityToken; } $stringToSign = OpenApiUtilClient::getStringToSign($_request); $_request->headers["authorization"] = "acs " . $accessKeyId . ":" . OpenApiUtilClient::getROASignature($stringToSign, $accessKeySecret) . ""; } } $_lastRequest = $_request; $_response = Tea::send($_request, $_runtime); if (Utils::equalNumber($_response->statusCode, 204)) { return [ "headers" => $_response->headers ]; } if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) { $_res = Utils::readAsJSON($_response->body); $err = Utils::assertAsMap($_res); @$err["statusCode"] = $_response->statusCode; throw new TeaError([ "code" => "" . (string) (self::defaultAny(@$err["Code"], @$err["code"])) . "", "message" => "code: " . (string) ($_response->statusCode) . ", " . (string) (self::defaultAny(@$err["Message"], @$err["message"])) . " request id: " . (string) (self::defaultAny(@$err["RequestId"], @$err["requestId"])) . "", "data" => $err, "description" => "" . (string) (self::defaultAny(@$err["Description"], @$err["description"])) . "", "accessDeniedDetail" => self::defaultAny(@$err["AccessDeniedDetail"], @$err["accessDeniedDetail"]) ]); } if (Utils::equalString($bodyType, "binary")) { $resp = [ "body" => $_response->body, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; return $resp; } else if (Utils::equalString($bodyType, "byte")) { $byt = Utils::readAsBytes($_response->body); return [ "body" => $byt, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "string")) { $str = Utils::readAsString($_response->body); return [ "body" => $str, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "json")) { $obj = Utils::readAsJSON($_response->body); $res = Utils::assertAsMap($obj); return [ "body" => $res, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($bodyType, "array")) { $arr = Utils::readAsJSON($_response->body); return [ "body" => $arr, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else { return [ "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } } catch (Exception $e) { if (!($e instanceof TeaError)) { $e = new TeaError([], $e->getMessage(), $e->getCode(), $e); } if (Tea::isRetryable($e)) { $_lastException = $e; continue; } throw $e; } } throw new TeaUnableRetryError($_lastRequest, $_lastException); } /** * Encapsulate the request and invoke the network * @param Params $params * @param OpenApiRequest $request object of OpenApiRequest * @param RuntimeOptions $runtime which controls some details of call api, such as retry times * @return array the response * @throws TeaError * @throws Exception * @throws TeaUnableRetryError */ public function doRequest($params, $request, $runtime) { $params->validate(); $request->validate(); $runtime->validate(); $_runtime = [ "timeouted" => "retry", "key" => Utils::defaultString($runtime->key, $this->_key), "cert" => Utils::defaultString($runtime->cert, $this->_cert), "ca" => Utils::defaultString($runtime->ca, $this->_ca), "readTimeout" => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout), "connectTimeout" => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout), "httpProxy" => Utils::defaultString($runtime->httpProxy, $this->_httpProxy), "httpsProxy" => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy), "noProxy" => Utils::defaultString($runtime->noProxy, $this->_noProxy), "socks5Proxy" => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy), "socks5NetWork" => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork), "maxIdleConns" => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns), "retry" => [ "retryable" => $runtime->autoretry, "maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3) ], "backoff" => [ "policy" => Utils::defaultString($runtime->backoffPolicy, "no"), "period" => Utils::defaultNumber($runtime->backoffPeriod, 1) ], "ignoreSSL" => $runtime->ignoreSSL ]; $_lastRequest = null; $_lastException = null; $_now = time(); $_retryTimes = 0; while (Tea::allowRetry(@$_runtime["retry"], $_retryTimes, $_now)) { if ($_retryTimes > 0) { $_backoffTime = Tea::getBackoffTime(@$_runtime["backoff"], $_retryTimes); if ($_backoffTime > 0) { Tea::sleep($_backoffTime); } } $_retryTimes = $_retryTimes + 1; try { $_request = new Request(); $_request->protocol = Utils::defaultString($this->_protocol, $params->protocol); $_request->method = $params->method; $_request->pathname = $params->pathname; $globalQueries = []; $globalHeaders = []; if (!Utils::isUnset($this->_globalParameters)) { $globalParams = $this->_globalParameters; if (!Utils::isUnset($globalParams->queries)) { $globalQueries = $globalParams->queries; } if (!Utils::isUnset($globalParams->headers)) { $globalHeaders = $globalParams->headers; } } $extendsHeaders = []; $extendsQueries = []; if (!Utils::isUnset($runtime->extendsParameters)) { $extendsParameters = $runtime->extendsParameters; if (!Utils::isUnset($extendsParameters->headers)) { $extendsHeaders = $extendsParameters->headers; } if (!Utils::isUnset($extendsParameters->queries)) { $extendsQueries = $extendsParameters->queries; } } $_request->query = Tea::merge($globalQueries, $extendsQueries, $request->query); // endpoint is setted in product client $_request->headers = Tea::merge([ "host" => $this->_endpoint, "x-acs-version" => $params->version, "x-acs-action" => $params->action, "user-agent" => $this->getUserAgent(), "x-acs-date" => OpenApiUtilClient::getTimestamp(), "x-acs-signature-nonce" => Utils::getNonce(), "accept" => "application/json" ], $globalHeaders, $extendsHeaders, $request->headers); if (Utils::equalString($params->style, "RPC")) { $headers = $this->getRpcHeaders(); if (!Utils::isUnset($headers)) { $_request->headers = Tea::merge($_request->headers, $headers); } } $signatureAlgorithm = Utils::defaultString($this->_signatureAlgorithm, "ACS3-HMAC-SHA256"); $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash(Utils::toBytes(""), $signatureAlgorithm)); if (!Utils::isUnset($request->stream)) { $tmp = Utils::readAsBytes($request->stream); $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash($tmp, $signatureAlgorithm)); $_request->body = $tmp; $_request->headers["content-type"] = "application/octet-stream"; } else { if (!Utils::isUnset($request->body)) { if (Utils::equalString($params->reqBodyType, "byte")) { $byteObj = Utils::assertAsBytes($request->body); $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash($byteObj, $signatureAlgorithm)); $_request->body = $byteObj; } else if (Utils::equalString($params->reqBodyType, "json")) { $jsonObj = Utils::toJSONString($request->body); $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash(Utils::toBytes($jsonObj), $signatureAlgorithm)); $_request->body = $jsonObj; $_request->headers["content-type"] = "application/json; charset=utf-8"; } else { $m = Utils::assertAsMap($request->body); $formObj = OpenApiUtilClient::toForm($m); $hashedRequestPayload = OpenApiUtilClient::hexEncode(OpenApiUtilClient::hash(Utils::toBytes($formObj), $signatureAlgorithm)); $_request->body = $formObj; $_request->headers["content-type"] = "application/x-www-form-urlencoded"; } } } $_request->headers["x-acs-content-sha256"] = $hashedRequestPayload; if (!Utils::equalString($params->authType, "Anonymous")) { $authType = $this->getType(); if (Utils::equalString($authType, "bearer")) { $bearerToken = $this->getBearerToken(); $_request->headers["x-acs-bearer-token"] = $bearerToken; if (Utils::equalString($params->style, "RPC")) { $_request->query["SignatureType"] = "BEARERTOKEN"; } else { $_request->headers["x-acs-signature-type"] = "BEARERTOKEN"; } } else { $accessKeyId = $this->getAccessKeyId(); $accessKeySecret = $this->getAccessKeySecret(); $securityToken = $this->getSecurityToken(); if (!Utils::empty_($securityToken)) { $_request->headers["x-acs-accesskey-id"] = $accessKeyId; $_request->headers["x-acs-security-token"] = $securityToken; } $_request->headers["Authorization"] = OpenApiUtilClient::getAuthorization($_request, $signatureAlgorithm, $hashedRequestPayload, $accessKeyId, $accessKeySecret); } } $_lastRequest = $_request; $_response = Tea::send($_request, $_runtime); if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) { $_res = Utils::readAsJSON($_response->body); $err = Utils::assertAsMap($_res); @$err["statusCode"] = $_response->statusCode; throw new TeaError([ "code" => "" . (string) (self::defaultAny(@$err["Code"], @$err["code"])) . "", "message" => "code: " . (string) ($_response->statusCode) . ", " . (string) (self::defaultAny(@$err["Message"], @$err["message"])) . " request id: " . (string) (self::defaultAny(@$err["RequestId"], @$err["requestId"])) . "", "data" => $err, "description" => "" . (string) (self::defaultAny(@$err["Description"], @$err["description"])) . "", "accessDeniedDetail" => self::defaultAny(@$err["AccessDeniedDetail"], @$err["accessDeniedDetail"]) ]); } if (Utils::equalString($params->bodyType, "binary")) { $resp = [ "body" => $_response->body, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; return $resp; } else if (Utils::equalString($params->bodyType, "byte")) { $byt = Utils::readAsBytes($_response->body); return [ "body" => $byt, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($params->bodyType, "string")) { $str = Utils::readAsString($_response->body); return [ "body" => $str, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($params->bodyType, "json")) { $obj = Utils::readAsJSON($_response->body); $res = Utils::assertAsMap($obj); return [ "body" => $res, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else if (Utils::equalString($params->bodyType, "array")) { $arr = Utils::readAsJSON($_response->body); return [ "body" => $arr, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } else { $anything = Utils::readAsString($_response->body); return [ "body" => $anything, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; } } catch (Exception $e) { if (!($e instanceof TeaError)) { $e = new TeaError([], $e->getMessage(), $e->getCode(), $e); } if (Tea::isRetryable($e)) { $_lastException = $e; continue; } throw $e; } } throw new TeaUnableRetryError($_lastRequest, $_lastException); } /** * Encapsulate the request and invoke the network * @param Params $params * @param OpenApiRequest $request object of OpenApiRequest * @param RuntimeOptions $runtime which controls some details of call api, such as retry times * @return array the response * @throws TeaError * @throws Exception * @throws TeaUnableRetryError */ public function execute($params, $request, $runtime) { $params->validate(); $request->validate(); $runtime->validate(); $_runtime = [ "timeouted" => "retry", "key" => Utils::defaultString($runtime->key, $this->_key), "cert" => Utils::defaultString($runtime->cert, $this->_cert), "ca" => Utils::defaultString($runtime->ca, $this->_ca), "readTimeout" => Utils::defaultNumber($runtime->readTimeout, $this->_readTimeout), "connectTimeout" => Utils::defaultNumber($runtime->connectTimeout, $this->_connectTimeout), "httpProxy" => Utils::defaultString($runtime->httpProxy, $this->_httpProxy), "httpsProxy" => Utils::defaultString($runtime->httpsProxy, $this->_httpsProxy), "noProxy" => Utils::defaultString($runtime->noProxy, $this->_noProxy), "socks5Proxy" => Utils::defaultString($runtime->socks5Proxy, $this->_socks5Proxy), "socks5NetWork" => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork), "maxIdleConns" => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns), "retry" => [ "retryable" => $runtime->autoretry, "maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3) ], "backoff" => [ "policy" => Utils::defaultString($runtime->backoffPolicy, "no"), "period" => Utils::defaultNumber($runtime->backoffPeriod, 1) ], "ignoreSSL" => $runtime->ignoreSSL, "disableHttp2" => self::defaultAny($this->_disableHttp2, false) ]; $_lastRequest = null; $_lastException = null; $_now = time(); $_retryTimes = 0; while (Tea::allowRetry(@$_runtime["retry"], $_retryTimes, $_now)) { if ($_retryTimes > 0) { $_backoffTime = Tea::getBackoffTime(@$_runtime["backoff"], $_retryTimes); if ($_backoffTime > 0) { Tea::sleep($_backoffTime); } } $_retryTimes = $_retryTimes + 1; try { $_request = new Request(); // spi = new Gateway();//Gateway implements SPI,这一步在产品 SDK 中实例化 $headers = $this->getRpcHeaders(); $globalQueries = []; $globalHeaders = []; if (!Utils::isUnset($this->_globalParameters)) { $globalParams = $this->_globalParameters; if (!Utils::isUnset($globalParams->queries)) { $globalQueries = $globalParams->queries; } if (!Utils::isUnset($globalParams->headers)) { $globalHeaders = $globalParams->headers; } } $extendsHeaders = []; $extendsQueries = []; if (!Utils::isUnset($runtime->extendsParameters)) { $extendsParameters = $runtime->extendsParameters; if (!Utils::isUnset($extendsParameters->headers)) { $extendsHeaders = $extendsParameters->headers; } if (!Utils::isUnset($extendsParameters->queries)) { $extendsQueries = $extendsParameters->queries; } } $requestContext = new \Darabonba\GatewaySpi\Models\InterceptorContext\request([ "headers" => Tea::merge($globalHeaders, $extendsHeaders, $request->headers, $headers), "query" => Tea::merge($globalQueries, $extendsQueries, $request->query), "body" => $request->body, "stream" => $request->stream, "hostMap" => $request->hostMap, "pathname" => $params->pathname, "productId" => $this->_productId, "action" => $params->action, "version" => $params->version, "protocol" => Utils::defaultString($this->_protocol, $params->protocol), "method" => Utils::defaultString($this->_method, $params->method), "authType" => $params->authType, "bodyType" => $params->bodyType, "reqBodyType" => $params->reqBodyType, "style" => $params->style, "credential" => $this->_credential, "signatureVersion" => $this->_signatureVersion, "signatureAlgorithm" => $this->_signatureAlgorithm, "userAgent" => $this->getUserAgent() ]); $configurationContext = new configuration([ "regionId" => $this->_regionId, "endpoint" => Utils::defaultString($request->endpointOverride, $this->_endpoint), "endpointRule" => $this->_endpointRule, "endpointMap" => $this->_endpointMap, "endpointType" => $this->_endpointType, "network" => $this->_network, "suffix" => $this->_suffix ]); $interceptorContext = new InterceptorContext([ "request" => $requestContext, "configuration" => $configurationContext ]); $attributeMap = new AttributeMap([]); // 1. spi.modifyConfiguration(context: SPI.InterceptorContext, attributeMap: SPI.AttributeMap); $this->_spi->modifyConfiguration($interceptorContext, $attributeMap); // 2. spi.modifyRequest(context: SPI.InterceptorContext, attributeMap: SPI.AttributeMap); $this->_spi->modifyRequest($interceptorContext, $attributeMap); $_request->protocol = $interceptorContext->request->protocol; $_request->method = $interceptorContext->request->method; $_request->pathname = $interceptorContext->request->pathname; $_request->query = $interceptorContext->request->query; $_request->body = $interceptorContext->request->stream; $_request->headers = $interceptorContext->request->headers; $_lastRequest = $_request; $_response = Tea::send($_request, $_runtime); $responseContext = new response([ "statusCode" => $_response->statusCode, "headers" => $_response->headers, "body" => $_response->body ]); $interceptorContext->response = $responseContext; // 3. spi.modifyResponse(context: SPI.InterceptorContext, attributeMap: SPI.AttributeMap); $this->_spi->modifyResponse($interceptorContext, $attributeMap); return [ "headers" => $interceptorContext->response->headers, "statusCode" => $interceptorContext->response->statusCode, "body" => $interceptorContext->response->deserializedBody ]; } catch (Exception $e) { if (!($e instanceof TeaError)) { $e = new TeaError([], $e->getMessage(), $e->getCode(), $e); } if (Tea::isRetryable($e)) { $_lastException = $e; continue; } throw $e; } } throw new TeaUnableRetryError($_lastRequest, $_lastException); } /** * @param Params $params * @param OpenApiRequest $request * @param RuntimeOptions $runtime * @return array * @throws TeaError */ public function callApi($params, $request, $runtime) { if (Utils::isUnset($params)) { throw new TeaError([ "code" => "ParameterMissing", "message" => "'params' can not be unset" ]); } if (Utils::isUnset($this->_signatureAlgorithm) || !Utils::equalString($this->_signatureAlgorithm, "v2")) { return $this->doRequest($params, $request, $runtime); } else if (Utils::equalString($params->style, "ROA") && Utils::equalString($params->reqBodyType, "json")) { return $this->doROARequest($params->action, $params->version, $params->protocol, $params->method, $params->authType, $params->pathname, $params->bodyType, $request, $runtime); } else if (Utils::equalString($params->style, "ROA")) { return $this->doROARequestWithForm($params->action, $params->version, $params->protocol, $params->method, $params->authType, $params->pathname, $params->bodyType, $request, $runtime); } else { return $this->doRPCRequest($params->action, $params->version, $params->protocol, $params->method, $params->authType, $params->bodyType, $request, $runtime); } } /** * Get user agent * @return string user agent */ public function getUserAgent() { $userAgent = Utils::getUserAgent($this->_userAgent); return $userAgent; } /** * Get accesskey id by using credential * @return string accesskey id */ public function getAccessKeyId() { if (Utils::isUnset($this->_credential)) { return ''; } $accessKeyId = $this->_credential->getAccessKeyId(); return $accessKeyId; } /** * Get accesskey secret by using credential * @return string accesskey secret */ public function getAccessKeySecret() { if (Utils::isUnset($this->_credential)) { return ''; } $secret = $this->_credential->getAccessKeySecret(); return $secret; } /** * Get security token by using credential * @return string security token */ public function getSecurityToken() { if (Utils::isUnset($this->_credential)) { return ''; } $token = $this->_credential->getSecurityToken(); return $token; } /** * Get bearer token by credential * @return string bearer token */ public function getBearerToken() { if (Utils::isUnset($this->_credential)) { return ''; } $token = $this->_credential->getBearerToken(); return $token; } /** * Get credential type by credential * @return string credential type e.g. access_key */ public function getType() { if (Utils::isUnset($this->_credential)) { return ''; } $authType = $this->_credential->getType(); return $authType; } /** * If inputValue is not null, return it or return defaultValue * @param mixed $inputValue users input value * @param mixed $defaultValue default value * @return any the final result */ public static function defaultAny($inputValue, $defaultValue) { if (Utils::isUnset($inputValue)) { return $defaultValue; } return $inputValue; } /** * If the endpointRule and config.endpoint are empty, throw error * @param \Darabonba\OpenApi\Models\Config $config config contains the necessary information to create a client * @return void * @throws TeaError */ public function checkConfig($config) { if (Utils::empty_($this->_endpointRule) && Utils::empty_($config->endpoint)) { throw new TeaError([ "code" => "ParameterMissing", "message" => "'config.endpoint' can not be empty" ]); } } /** * set gateway client * @param Client $spi * @return void */ public function setGatewayClient($spi) { $this->_spi = $spi; } /** * set RPC header for debug * @param string[] $headers headers for debug, this header can be used only once. * @return void */ public function setRpcHeaders($headers) { $this->_headers = $headers; } /** * get RPC header for debug * @return array */ public function getRpcHeaders() { $headers = $this->_headers; $this->_headers = null; return $headers; } } tests/OpenApiClientTest.php000064400000025632147133776160012000 0ustar00 [ "global-key" => "global-value" ], "queries" => [ "global-query" => "global-value" ] ]); $config = new Config([ "endpoint" => "config.endpoint", "endpointType" => "regional", "network" => "config.network", "suffix" => "config.suffix", "protocol" => "config.protocol", "method" => "config.method", "regionId" => "config.regionId", "userAgent" => "config.userAgent", "readTimeout" => 3000, "connectTimeout" => 3000, "httpProxy" => "config.httpProxy", "httpsProxy" => "config.httpsProxy", "noProxy" => "config.noProxy", "socks5Proxy" => "config.socks5Proxy", "socks5NetWork" => "config.socks5NetWork", "maxIdleConns" => 128, "signatureVersion" => "config.signatureVersion", "signatureAlgorithm" => "config.signatureAlgorithm", "globalParameters" => $globalParameters ]); $creConfig = new \AlibabaCloud\Credentials\Credential\Config([ "accessKeyId" => "accessKeyId", "accessKeySecret" => "accessKeySecret", "securityToken" => "securityToken", "type" => "sts" ]); $credential = new Credential($creConfig); $config->credential = $credential; $client = new OpenApiClient($config); $config->accessKeyId = "ak"; $config->accessKeySecret = "secret"; $config->securityToken = "token"; $config->type = "sts"; $client = new OpenApiClient($config); } /** * @return Config */ public static function createConfig(){ $globalParameters = new GlobalParameters([ "headers" => [ "global-key" => "global-value" ], "queries" => [ "global-query" => "global-value" ] ]); $config = new Config([ "accessKeyId" => "ak", "accessKeySecret" => "secret", "securityToken" => "token", "type" => "sts", "userAgent" => "config.userAgent", "readTimeout" => 3000, "connectTimeout" => 3000, "maxIdleConns" => 128, "signatureVersion" => "config.signatureVersion", "signatureAlgorithm" => "ACS3-HMAC-SHA256", "globalParameters" => $globalParameters ]); return $config; } /** * @return RuntimeOptions */ public static function createRuntimeOptions(){ $runtime = new RuntimeOptions([ "readTimeout" => 4000, "connectTimeout" => 4000, "maxIdleConns" => 100, "autoretry" => true, "maxAttempts" => 1, "backoffPolicy" => "no", "backoffPeriod" => 1, "ignoreSSL" => true ]); return $runtime; } /** * @return OpenApiRequest */ public static function createOpenApiRequest(){ $query = []; $query["key1"] = "value"; $query["key2"] = 1; $query["key3"] = true; $body = []; $body["key1"] = "value"; $body["key2"] = 1; $body["key3"] = true; $headers = [ "for-test" => "sdk" ]; $req = new OpenApiRequest([ "headers" => $headers, "query" => OpenApiUtilClient::query($query), "body" => OpenApiUtilClient::parseToMap($body) ]); return $req; } public function testCallApiForRPCWithV2Sign_AK_Form(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->signatureAlgorithm = "v2"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/", "method" => "POST", "authType" => "AK", "style" => "RPC", "reqBodyType" => "formData", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForRPCWithV2Sign_Anonymous_JSON(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->signatureAlgorithm = "v2"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/", "method" => "POST", "authType" => "Anonymous", "style" => "RPC", "reqBodyType" => "json", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForROAWithV2Sign_HTTPS_AK_Form(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->signatureAlgorithm = "v2"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/test", "method" => "POST", "authType" => "AK", "style" => "ROA", "reqBodyType" => "formData", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForROAWithV2Sign_Anonymous_JSON(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->signatureAlgorithm = "v2"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/test", "method" => "POST", "authType" => "Anonymous", "style" => "ROA", "reqBodyType" => "json", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForRPCWithV3Sign_AK_Form(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/", "method" => "POST", "authType" => "AK", "style" => "RPC", "reqBodyType" => "formData", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForRPCWithV3Sign_Anonymous_JSON(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/", "method" => "POST", "authType" => "Anonymous", "style" => "RPC", "reqBodyType" => "json", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForROAWithV3Sign_AK_Form(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/test", "method" => "POST", "authType" => "AK", "style" => "ROA", "reqBodyType" => "formData", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testCallApiForROAWithV3Sign_Anonymous_JSON(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/test", "method" => "POST", "authType" => "Anonymous", "style" => "ROA", "reqBodyType" => "json", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); } public function testResponseBodyType(){ $config = self::createConfig(); $runtime = self::createRuntimeOptions(); $config->protocol = "HTTP"; $config->endpoint = "test.aliyuncs.com"; $client = new OpenApiClient($config); $request = self::createOpenApiRequest(); $params = new Params([ "action" => "TestAPI", "version" => "2022-06-01", "protocol" => "HTTPS", "pathname" => "/test", "method" => "POST", "authType" => "AK", "style" => "ROA", "reqBodyType" => "formData", "bodyType" => "json" ]); $client->callApi($params, $request, $runtime); $params->bodyType = "array"; $client->callApi($params, $request, $runtime); $params->bodyType = "string"; $client->callApi($params, $request, $runtime); $params->bodyType = "byte"; $client->callApi($params, $request, $runtime); } } tests/bootstrap.php000064400000000151147133776160010450 0ustar00