in php/src/OpenApiClient.php [288:525]
public function doRPCRequest($action, $version, $protocol, $method, $authType, $bodyType, $request, $runtime)
{
$_runtime = [
'key' => ''.($runtime->key ? $runtime->key : $this->_key),
'cert' => ''.($runtime->cert ? $runtime->cert : $this->_cert),
'ca' => ''.($runtime->ca ? $runtime->ca : $this->_ca),
'readTimeout' => (($runtime->readTimeout ? $runtime->readTimeout : $this->_readTimeout) + 0),
'connectTimeout' => (($runtime->connectTimeout ? $runtime->connectTimeout : $this->_connectTimeout) + 0),
'httpProxy' => ''.($runtime->httpProxy ? $runtime->httpProxy : $this->_httpProxy),
'httpsProxy' => ''.($runtime->httpsProxy ? $runtime->httpsProxy : $this->_httpsProxy),
'noProxy' => ''.($runtime->noProxy ? $runtime->noProxy : $this->_noProxy),
'socks5Proxy' => ''.($runtime->socks5Proxy ? $runtime->socks5Proxy : $this->_socks5Proxy),
'socks5NetWork' => ''.($runtime->socks5NetWork ? $runtime->socks5NetWork : $this->_socks5NetWork),
'maxIdleConns' => (($runtime->maxIdleConns ? $runtime->maxIdleConns : $this->_maxIdleConns) + 0),
'retryOptions' => $this->_retryOptions,
'ignoreSSL' => $runtime->ignoreSSL,
'tlsMinVersion' => $this->_tlsMinVersion,
];
$_retriesAttempted = 0;
$_lastRequest = null;
$_lastResponse = null;
$_context = new RetryPolicyContext([
'retriesAttempted' => $_retriesAttempted,
]);
while (Dara::shouldRetry($_runtime['retryOptions'], $_context)) {
if ($_retriesAttempted > 0) {
$_backoffTime = Dara::getBackoffDelay($_runtime['retryOptions'], $_context);
if ($_backoffTime > 0) {
Dara::sleep($_backoffTime);
}
}
$_retriesAttempted++;
try {
$_request = new Request();
$_request->protocol = ''.($this->_protocol ? $this->_protocol : $protocol);
$_request->method = $method;
$_request->pathname = '/';
$globalQueries = [ ];
$globalHeaders = [ ];
if (!is_null($this->_globalParameters)) {
$globalParams = $this->_globalParameters;
if (!is_null($globalParams->queries)) {
$globalQueries = $globalParams->queries;
}
if (!is_null($globalParams->headers)) {
$globalHeaders = $globalParams->headers;
}
}
$extendsHeaders = [ ];
$extendsQueries = [ ];
if (!is_null($runtime->extendsParameters)) {
$extendsParameters = $runtime->extendsParameters;
if (!is_null($extendsParameters->headers)) {
$extendsHeaders = $extendsParameters->headers;
}
if (!is_null($extendsParameters->queries)) {
$extendsQueries = $extendsParameters->queries;
}
}
$_request->query = Dara::merge([
'Action' => $action,
'Format' => 'json',
'Version' => $version,
'Timestamp' => Utils::getTimestamp(),
'SignatureNonce' => Utils::getNonce(),
], $globalQueries, $extendsQueries, $request->query);
$headers = $this->getRpcHeaders();
if (is_null($headers)) {
// endpoint is setted in product client
$_request->headers = Dara::merge([
'host' => $this->_endpoint,
'x-acs-version' => $version,
'x-acs-action' => $action,
'user-agent' => Utils::getUserAgent($this->_userAgent),
], $globalHeaders, $extendsHeaders, $request->headers);
} else {
$_request->headers = Dara::merge([
'host' => $this->_endpoint,
'x-acs-version' => $version,
'x-acs-action' => $action,
'user-agent' => Utils::getUserAgent($this->_userAgent),
], $globalHeaders, $extendsHeaders, $request->headers, $headers);
}
if (!is_null($request->body)) {
$m = $request->body;
$tmp = Utils::query($m);
$_request->body = FormUtil::toFormString($tmp);
@$_request->headers['content-type'] = 'application/x-www-form-urlencoded';
}
if ($authType != 'Anonymous') {
if (is_null($this->_credential)) {
throw new ClientException([
'code' => 'InvalidCredentials',
'message' => 'Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.',
]);
}
$credentialModel = $this->_credential->getCredential();
if (!is_null($credentialModel->providerName)) {
@$_request->headers['x-acs-credentials-provider'] = $credentialModel->providerName;
}
$credentialType = $credentialModel->type;
if ($credentialType == 'bearer') {
$bearerToken = $credentialModel->bearerToken;
@$_request->query['BearerToken'] = $bearerToken;
@$_request->query['SignatureType'] = 'BEARERTOKEN';
} else {
$accessKeyId = $credentialModel->accessKeyId;
$accessKeySecret = $credentialModel->accessKeySecret;
$securityToken = $credentialModel->securityToken;
if (!is_null($securityToken) && $securityToken != '') {
@$_request->query['SecurityToken'] = $securityToken;
}
@$_request->query['SignatureMethod'] = 'HMAC-SHA1';
@$_request->query['SignatureVersion'] = '1.0';
@$_request->query['AccessKeyId'] = $accessKeyId;
$t = null;
if (!is_null($request->body)) {
$t = $request->body;
}
$signedParam = Dara::merge([
], $_request->query, Utils::query($t));
@$_request->query['Signature'] = Utils::getRPCSignature($signedParam, $_request->method, $accessKeySecret);
}
}
$_response = Dara::send($_request, $_runtime);
$_lastRequest = $_request;
$_lastResponse = $_response;
if (($_response->statusCode >= 400) && ($_response->statusCode < 600)) {
$_res = StreamUtil::readAsJSON($_response->body);
$err = $_res;
$requestId = (@$err['RequestId'] ? @$err['RequestId'] : @$err['requestId']);
$code = (@$err['Code'] ? @$err['Code'] : @$err['code']);
if (('' . (string)$code . '' == 'Throttling') || ('' . (string)$code . '' == 'Throttling.User') || ('' . (string)$code . '' == 'Throttling.Api')) {
throw new ThrottlingException([
'statusCode' => $_response->statusCode,
'code' => '' . (string)$code . '',
'message' => 'code: ' . (string)$_response->statusCode . ', ' . (string)(@$err['Message'] ? @$err['Message'] : @$err['message']) . ' request id: ' . (string)$requestId . '',
'description' => '' . (string)(@$err['Description'] ? @$err['Description'] : @$err['description']) . '',
'retryAfter' => Utils::getThrottlingTimeLeft($_response->headers),
'data' => $err,
'requestId' => '' . (string)$requestId . '',
]);
} else if (($_response->statusCode >= 400) && ($_response->statusCode < 500)) {
throw new ClientException([
'statusCode' => $_response->statusCode,
'code' => '' . (string)$code . '',
'message' => 'code: ' . (string)$_response->statusCode . ', ' . (string)(@$err['Message'] ? @$err['Message'] : @$err['message']) . ' request id: ' . (string)$requestId . '',
'description' => '' . (string)(@$err['Description'] ? @$err['Description'] : @$err['description']) . '',
'data' => $err,
'accessDeniedDetail' => $this->getAccessDeniedDetail($err),
'requestId' => '' . (string)$requestId . '',
]);
} else {
throw new ServerException([
'statusCode' => $_response->statusCode,
'code' => '' . (string)$code . '',
'message' => 'code: ' . (string)$_response->statusCode . ', ' . (string)(@$err['Message'] ? @$err['Message'] : @$err['message']) . ' request id: ' . (string)$requestId . '',
'description' => '' . (string)(@$err['Description'] ? @$err['Description'] : @$err['description']) . '',
'data' => $err,
'requestId' => '' . (string)$requestId . '',
]);
}
}
if ($bodyType == 'binary') {
$resp = [
'body' => $_response->body,
'headers' => $_response->headers,
'statusCode' => $_response->statusCode,
];
return $resp;
} else if ($bodyType == 'byte') {
$byt = StreamUtil::readAsBytes($_response->body);
return [
'body' => $byt,
'headers' => $_response->headers,
'statusCode' => $_response->statusCode,
];
} else if ($bodyType == 'string') {
$_str = StreamUtil::readAsString($_response->body);
return [
'body' => $_str,
'headers' => $_response->headers,
'statusCode' => $_response->statusCode,
];
} else if ($bodyType == 'json') {
$obj = StreamUtil::readAsJSON($_response->body);
$res = $obj;
return [
'body' => $res,
'headers' => $_response->headers,
'statusCode' => $_response->statusCode,
];
} else if ($bodyType == 'array') {
$arr = StreamUtil::readAsJSON($_response->body);
return [
'body' => $arr,
'headers' => $_response->headers,
'statusCode' => $_response->statusCode,
];
} else {
return [
'headers' => $_response->headers,
'statusCode' => $_response->statusCode,
];
}
} catch (DaraException $e) {
$_context = new RetryPolicyContext([
'retriesAttempted' => $_retriesAttempted,
'lastRequest' => $_lastRequest,
'lastResponse' => $_lastResponse,
'exception' => $e,
]);
continue;
}
}
throw new DaraUnableRetryException($_context);
}