This topic describes how to install SDKs for PHP and provides sample code.

Background information

  • Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
  • For more information about Resource Management API operations, see List of operations by function.

Installation

For information about how to install the SDKs for PHP, see Quick start.

You can download the installation packages of the SDKs for PHP from the following links:

Example

The following example shows how to use Resource Management SDK for PHP to call the CreateResourceAccount API operation. You can visit OpenAPI Explorer to debug other API operations and obtain their sample code.

<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Construct an Alibaba Cloud client that is used to initiate requests.
// When you construct the client, specify your AccessKey ID and AccessKey secret.
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
                        ->regionId('cn-hangzhou')
                        ->asDefaultClient();
// Configure parameters and initiate a request.
try {
    $result = AlibabaCloud::rpc()
                          ->product('ResourceManager')
                          // ->scheme('https') // https | http
                          ->version('2020-03-31')
                          ->action('CreateResourceAccount')
                          ->method('POST')
                          ->host('resourcemanager.aliyuncs.com')
                          ->options([
                                        'query' => [
                                          'RegionId' => "cn-hangzhou",
                                          'DisplayName' => "<DisplayName>",
                                        ],
                                    ])
                          ->request();
    print_r($result->toArray());
} catch (ClientException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
}