PHP code example of axios / aliyun-sdk-core
1. Go to this page and download the library: Download axios/aliyun-sdk-core library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
axios / aliyun-sdk-core example snippets
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;
}
}
$access_id = "<AccessKeyId>";
$access_secret = "<AccessKeySecret>";
\aliyun\sdk\Aliyun::auth($access_id, $access_secret);
\aliyun\sdk\Aliyun::region('cn-hangzhou');
$request = AliyunProduct::client();
$request->method("POST");
$response = $request->params("key", "value")
->headers("header_name", "header_content")
->options("option_name", "option_value")
->request();
$result = $response->getData();