Skip to content

Latest commit

 

History

History
128 lines (88 loc) · 2.64 KB

README_CN.md

File metadata and controls

128 lines (88 loc) · 2.64 KB

English | 简体中文

阿里云服务 SDK ,支持 composer 扩展

CI Build Status Latest Stable Version License

阿里云官方文档中心

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;
    }
}

使用

aliyun-sdk/example

  • 引用 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();

请求选项

License

licensed under the MIT License