axios/aliyun-sdk-core

SDK for aliyun service development

2.3.1 2021-04-01 07:01 UTC

This package is auto-updated.

Last update: 2024-10-29 05:16:53 UTC


README

English | 简体中文

Aliyun Cloud Service SDK Core, composer library.

CI Build Status Latest Stable Version License

Aliyun Cloud official documentation center

QQ Group:521797692

Env

  • PHP 7.1+.
  • CURL extension.

Install

composer require axios/aliyun-sdk-core

Customized Request

use aliyun\sdk\core\lib\RpcRequest;

class AliyunProduct
{

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

How to use

aliyun-sdk/example

  • require composer autoload
require_once __DIR__. "/../vendor/autoload.php";
  • Auth
$access_id = "<AccessKeyId>";
$access_secret = "<AccessKeySecret>";

\aliyun\sdk\Aliyun::auth($access_id, $access_secret);
  • Setting Region
\aliyun\sdk\Aliyun::region('cn-hangzhou');
  • request
$request = AliyunProduct::client();

$request->method("POST");

$response = $request->params("key", "value")
    ->headers("header_name", "header_content")
    ->options("option_name", "option_value")
    ->request();
  • Get Response Content
$result = $response->getData();

Request Option

License

licensed under the MIT License