Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php的sdk开发包怎么使用

php的sdk开发包怎么使用

王林
王林asal
2019-10-15 17:54:474852semak imbas

php的sdk开发包怎么使用

PHP的sdk开发包

步骤1、创建阿里云账号

步骤2、获取阿里云访问密钥

为了使用 AIRec PHP SDK,您必须申请阿里云的访问秘钥。登录阿里云秘钥管理页面。选择一对用于 SDK 的访问密钥对。如果没有,请创建一对新访问密钥,且保证它处于启用状态。

步骤3、安装 PHP 开发环境

AIRec PHP SDK 支持 PHP 5.2.1 及以上版本,您可以在本地安装 SDK 并搭建好相应的 PHP 开发环境。

步骤4、开始使用SDK

以创建实例的方法 CreateInstance 为例,介绍 SDK 使用的完整流程,其中IClientProfile 和 IAcsClient 两个类包含在 aliyun-php-sdk-core 目录中,其他的类均包含在 aliyun-php-sdk-airec 目录中。

<?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);

推荐教程:PHP视频教程

Atas ialah kandungan terperinci php的sdk开发包怎么使用. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn