bigbug-gg/zenlayer

Zenlayer Cloud API PHP SDK

0.0.4 2024-06-20 03:30 UTC

This package is auto-updated.

Last update: 2024-09-20 04:10:24 UTC


README

非官方 Zenlayer Cloud API 软件开发工具包 (SDK),

目前,已经实现了虚拟机相关接口的集成。如果需要,其他接口可以自行改进,或帮助改进这个包。

要求

  • 您必须使用 PHP 8.3.x 或更高版本。
  • 已创建 Zenlayer Cloud 账户,并创建了访问密钥 ID 和访问密钥密码。有关更多详细信息,请参阅“生成 API 访问密钥”。

安装

使用 composer

composer require bigbug-gg/zenlayer

快速示例

// test.php
require_once ("vendor/autoload.php");

use BigbugGg\Zenlayer\Instance;

$appId = 'YOUR-APP-ID';
$secretKey = 'YOUR-SECRET-KEY';
$instance = new Instance($appId, $secretKey);

$zoneId = 'PAR-A';
$data = $instance->describeZones([$zoneId]);
var_dump($data);

输出

 php .\test.php
array(1) {
  [0]=>
  object(BigbugGg\Zenlayer\Value\ZoneValue)#6 (2) {
    ["zoneId"]=>
    string(5) "PAR-A"
    ["zoneName"]=>
    string(5) "Paris"
  }
}

如何扩展其他接口

继承 Fetch 类,该类封装了签名和请求

require_once ("vendor/autoload.php");

use BigbugGg\Zenlayer\Fetch;

class SimpleExample extends Fetch
{
    /**
     * @throws JsonException
     */
    public function zenlayerCallName(): array
    {
        $dataArr = $this->fetch('ZenlayerCallName', [
            // Parameters  => Values
        ]);
        // other logic codes
        return $dataArr;
    }
}

用法

$appId = 'YOUR-APP-ID';
$secretKey = 'YOUR-SECRET-KEY';
$instance = new SimpleExample($appId, $secretKey);
$data = $instance->zenlayerCallName();
var_dump($data);