Home >Backend Development >PHP Problem >How to use php's sdk development package

How to use php's sdk development package

王林
王林Original
2019-10-15 17:54:474952browse

How to use php's sdk development package

PHP sdk development package

Step 1. Create Alibaba Cloud Account

Step 2. Obtain Alibaba Cloud access key

In order to use AIRec PHP SDK, you must apply for Alibaba Cloud Cloud access key. Log in to the Alibaba Cloud key management page. Select an access key pair to use with the SDK. If not, create a new access key pair and make sure it is enabled.

Step 3. Install the PHP development environment

AIRec PHP SDK supports PHP 5.2.1 and above. You can install the SDK locally and Set up the corresponding PHP development environment.

Step 4. Start using the SDK

Take the instance creation method CreateInstance as an example to introduce the complete process of using the SDK, including IClientProfile and IAcsClient Two classes are included in the aliyun-php-sdk-core directory, and other classes are included in the aliyun-php-sdk-airec directory.

<?php
include_once &#39;aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config.php&#39;;
include_once &#39;vendor/autoload.php&#39;;
use Airec\Request\V20181012 as Airec;
// 1.创建 Profile。
// 生成 IClientProfile 的对象 profile,该对象存放 AccessKeyID 和 AccessKeySecret
// 和默认的地域信息, 如这里的 cn-beijing$iClientProfile = DefaultProfile::getProfile("cn-beijing", $accessKeyID, 
$accessSecret);
// 2.设置 Endpoint。// 调用 DefaultProfile 的 addEndpoint 方法,
// 传入 endpointName、regionId、product 名称、服务接入地址。
DefaultProfile::addEndpoint("cn-beijing", "cn-beijing", "Airec", "airec.cn-beijing.aliyuncs.com");
// 3.创建 Client。$client = new DefaultAcsClient($iClientProfile);
// 4.创建 Request// 创建一个对应方法的 Request,类的命名规则一般为 API 的方法名加上 Request。
// 如获取实例详情的 API 方法名为 CreateInstance,那么对应的请求类名就是 
CreateInstanceRequest$request = new Airec\CreateInstanceRequest();
// 5.设置 Request的参数。// 设置 Request 的参数。请求类生成好之后需要通过 Request 类的 setXxx 方法设置必要的信息,即 
API 参数中必须要提供的信息。
$content = "{\"chargeType\":\"PrePaid\",\"type\":\"Standard\",\"quota\":
{\"userCount\":1000000,\"qps\":20,\"itemCount\":1000000},\"paymentInfo\":
{\"duration\":1,\"pricingCycle\":\"Month\",\"autoRenew\":true}}";$request->setContent($content);
// 6.使用 Client 对应的方法传入 Request,获得 Response。$response = $client->getAcsResponse($request);//
 7.查看 Response 结果echo json_encode($response);

Recommended tutorial: PHP video tutorial

The above is the detailed content of How to use php's sdk development package. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn