meioco3/client

PHP 阿里云客户端 - 在您的 PHP 项目中使用阿里云

dev-master 2023-09-19 03:08 UTC

This package is auto-updated.

Last update: 2024-09-19 05:18:33 UTC


README

英文 | 简体中文

PHP 阿里云客户端

Latest Stable Version composer.lock Total Downloads License codecov PHP Version Require

PHP 阿里云客户端是一个帮助 PHP 开发者管理凭证和发送请求的客户端工具,此工具依赖于 阿里云 SDK for PHP

故障排除

故障排除 提供开放 API 诊断服务,帮助开发者快速定位问题,并通过 RequestID错误信息 提供解决方案。

在线演示

阿里云 OpenAPI 开发者门户 提供了在线调用云产品 OpenAPI 的能力,并动态生成 SDK 示例代码和快速检索接口,可以显著降低使用云 API 的难度。

先决条件

您的系统需要满足 先决条件,包括 PHP >= 5.5。我们强烈推荐编译时包含 cURL 扩展和 cURL 7.16.2+。

安装

如果您的系统已全局安装了 Composer,请在项目的根目录中运行以下命令来将 PHP 阿里云客户端作为依赖项安装

composer require alibabacloud/client

由于网络问题,某些用户可能无法安装,您可以尝试切换 Composer 镜像。

有关通过 Composer 和其他方式安装 PHP 阿里云客户端的详细信息,请参阅 安装

快速示例

开始之前,您需要注册阿里云账户并获取您的 凭证

创建客户端

<?php

use AlibabaCloud\Client\AlibabaCloud;

AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient();

请求

请求样式分为 ROARPC。不同产品的样式不同。请在使用前参考产品文档。建议使用 阿里云 SDK for PHP,其中细节已封装,您无需关心样式。

ROA 请求

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

try {
    $result = AlibabaCloud::roa()
                          ->regionId('cn-hangzhou') // Specify the requested regionId, if not specified, use the client regionId, then default regionId
                          ->product('CS') // Specify product
                          ->version('2015-12-15') // Specify product version
                          ->action('DescribeClusterServices') // Specify product interface
                          ->serviceCode('cs') // Set ServiceCode for addressing, optional
                          ->endpointType('openAPI') // Set type, optional
                          ->method('GET') // Set request method
                          ->host('cs.aliyun.com') // Location Service will not be enabled if the host is specified. For example, service with a Certification type-Bearer Token should be specified
                          ->pathPattern('/clusters/[ClusterId]/services') // Specify path rule with ROA-style
                          ->withClusterId('123456') // Assign values to parameters in the path. Method: with + Parameter
                          ->request(); // Make a request and return to result object. The request is to be placed at the end of the setting
                          
    print_r($result->toArray());
    
} catch (ClientException $exception) {
    print_r($exception->getErrorMessage());
} catch (ServerException $exception) {
    print_r($exception->getErrorMessage());
}

RPC 请求

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

try {
    $result = AlibabaCloud::rpc()
                          ->product('Cdn')
                          ->version('2014-11-11')
                          ->action('DescribeCdnService')
                          ->method('POST')
                          ->request();
    
    print_r($result->toArray());
    
} catch (ClientException $exception) {
    print_r($exception->getErrorMessage());
} catch (ServerException $exception) {
    print_r($exception->getErrorMessage());
}

文档

问题

提交问题,不符合指导原则的问题可能会立即关闭。

变更日志

每个版本的详细更改已在 发布说明 中记录。

贡献

在提交拉取请求之前,请务必阅读 贡献指南

参考文献

许可证

Apache-2.0

版权所有 (c) 2009-至今,阿里云。保留所有权利。