English | 简体中文
阿里云服务 SDK ,支持 composer 扩展
QQ 群:521797692
- PHP 7.1+.
- CURL extension.
composer require axios/aliyun-sdk-core
use aliyun\sdk\core\lib\RpcRequest;
class Example
{
protected static $product = "<ProductName>";
protected static $service_code = "<ProductServiceCode>";
/**
* @var string
* @example \aliyun\sdk\core\credentials\AccessKeyCredential
* @example AccessKeyCredential
*/
protected static $credential = "<Credential>";
protected static $version = "<VersionDate>";
protected static $endpoints = [
"regions" => [],
"public" => [],
"internal" => []
];
/**
* @param $action
*
* @return Request
*/
public static function client($action = null)
{
$request = new RpcRequest(); // or RoaRequest
$request->product(self::$product);
$request->version(self::$version);
$request->action($action);
$request->endpoints(self::$endpoints);
$request->credential(self::$credential);
$request->serviceCode(self::$service_code);
$request->protocol("https");
return $request;
}
}
- 引用 composer 自动加载文件
require_once __DIR__. "/../vendor/autoload.php";
- 设置授权信息
$access_id = "testAccessKeyId";
$access_secret = "testAccessKeySecret";
\aliyun\sdk\Aliyun::auth($access_id, $access_secret);
- 设置区域
\aliyun\sdk\Aliyun::region('cn-hangzhou');
- 请求
$request = Example::client();
$request->method("POST");
$response = $request->params("key", "value")
->headers("header_name", "header_content")
->options("option_name", "option_value")
->request();
- 查看回调结果
$result = $response->getData();
licensed under the MIT License