level23/dynadot-api

Dynadot API 的实现

v2.0.2 2023-10-18 11:28 UTC

This package is auto-updated.

Last update: 2024-09-18 13:25:51 UTC


README

Build Code Coverage Minimum PHP Version Packagist Version Total Downloads Quality Score Software License

高级 Dynadot 域 API 的非官方实现

请注意,这是一个 beta API 实现,基于https://www.dynadot.com/domain/api3.html上的 API 描述

在您可以使用此 API 之前,您必须

  • 从 dynadot 后端获取 API 密钥
  • 将您的请求来源的 IP 地址列入白名单

默认情况下,我们将尝试连接到 Dynadoy API 30 秒。如果失败,将抛出 GuzzleHttp\Exception\ConnectException。您可能希望捕获这些异常以防出现错误。

目前仅实现了有限的功能集,并且此 API 上可用的确切方法和参数可能会在未来更改。

安装

使用以下命令安装最新版本

$ composer require level23/dynadot-api

要求

要使用此 API,您必须运行 PHP 8.2 或更高版本。

贡献

如果您想帮助我们改进此实现,请与我们联系。所有帮助都受欢迎!贡献的唯一要求是所有代码都是 100% 通过单元测试覆盖,并且它们实现了 PSR 标准。

许可

有关更多信息,请参阅文件 LICENSE。

示例用法

以下是一些基本的示例用法。

使用 getDomainInfo 获取域详情

<?php
use Level23\Dynadot\DynadotApi;

$apiKey = 'xxx YOUR API KEY xxx';

try {
    $api = new DynadotApi($apiKey);
    print_r($api->getDomainInfo('example.com'));
    
    // process your domain info here
} catch (Exception $e) {
    // ... handle exception
}

返回的对象将是 Level23\Dynadot\ResultObjects\DomainInfoResponses\Domain 的一个实例。

示例响应

Level23\Dynadot\ResultObjects\DomainResponse\Domain Object
(
    [Name] => example.com
    [Expiration] => 1514764799000
    [Registration] => 1291735572000
    [NameServerSettings] => Level23\Dynadot\ResultObjects\DomainResponse\NameServerSettings Object
        (
            [Type] => Name Servers
            [NameServers] => Array
                (
                    [0] => Array
                        (
                            [0] => Level23\Dynadot\ResultObjects\DomainResponse\NameServer Object
                                (
                                    [ServerId] => 1234
                                    [ServerName] => abc.org
                                )

                            [1] => Level23\Dynadot\ResultObjects\DomainResponse\NameServer Object
                                (
                                    [ServerId] => 12346
                                    [ServerName] => abc.com
                                )

                            [2] => Level23\Dynadot\ResultObjects\DomainResponse\NameServer Object
                                (
                                    [ServerId] => 1245
                                    [ServerName] => abc.co.uk
                                )

                            [3] => Level23\Dynadot\ResultObjects\DomainResponse\NameServer Object
                                (
                                    [ServerId] => 1267
                                    [ServerName] => abc.net
                                )

                        )

                )

            [WithAds] => false
        )

    [Whois] => Level23\Dynadot\ResultObjects\DomainResponse\Whois Object
        (
            [Registrant] => 1234
            [Admin] => 1234
            [Technical] => 1234
            [Billing] => 1234
        )

    [Locked] => true
    [Disabled] => false
    [UdrpLocked] => false
    [RegistrantUnverified] => false
    [Hold] => false
    [Privacy] => none
    [isForSale] => false
    [RenewOption] => auto-renew
    [Note] => 
    [Folder] => Level23\Dynadot\ResultObjects\DomainResponse\Folder Object
        (
            [FolderId] => 1234
            [FolderName] => Other
        )

)

Whois 容器将返回此特定域的联系人 ID。可以通过使用此 ID 通过 getContactInfo API 调用来获取完整的联系人详情。

使用 getDomainList 列出所有域

<?php

use Level23\Dynadot\DynadotApi;

$apiKey = 'xxx YOUR API KEY xxx';


try {
    $api = new DynadotApi($apiKey);
    $list = $api->getDomainList();

    print_r( $list );
} catch (Exception $e) {
    // ... handle exception
}

这将返回一个包含 Level23\Dynadot\ResultObjects\DomainInfoResponses\Domain 对象的数组。当出现错误时将抛出异常。

使用 setNameserversForDomain 为域设置名称服务器

<?php

use Level23\Dynadot\DynadotApi;

$apiKey = 'xxx YOUR API KEY xxx';

try {
    $api = new DynadotApi($apiKey);
    $api->setNameserversForDomain('exmple.com', ['ns01.example.com', 'ns2.example.net', 'ns03.example.org']);
    // ...
} catch (Exception $e) {
    // ... handle exception
}

默认情况下,setNameserversForDomain 方法不会提供响应。当出现错误时将抛出异常。

使用 getContactInfo 获取联系人信息

<?php
use Level23\Dynadot\DynadotApi;

$apiKey = 'xxx YOUR API KEY xxx';

try {
    $api = new DynadotApi($apiKey);
    print_r($api->getContactInfo(1234)); // 1234 = the contact id, for example returned by the getDomainInfo call.
} catch (Exception $e) {
    echo $e->getMessage();
}

当出现错误时将抛出异常。

示例响应

Level23\Dynadot\ResultObjects\GetContactResponse\Contact Object
(
    [ContactId] => 12345
    [Organization] => org
    [Name] => name
    [Email] => example@example.com
    [PhoneCc] => 0
    [PhoneNum] => phone number
    [FaxCc] => example faxcc
    [FaxNum] => example faxnum
    [Address1] => address1
    [Address2] => address2
    [City] => city
    [State] => state
    [ZipCode] => zipcode
    [Country] => country
)

使用 setRenewOption 设置续费选项

<?php

use Level23\Dynadot\DynadotApi;

$apiKey = 'xxx YOUR API KEY xxx';

try {
    $api = new DynadotApi($apiKey);
    $api->setRenewOption('example.com', 'auto');
    // ...
} catch (Exception $e) {
    // ... handle exception
}

setRenewOption 允许您设置域的续费设置。第二个参数($renewOption)的值可以是 "donot"、"auto"、"reset"。当成功设置续费选项时,该方法将返回 true

常见问题解答

我总是遇到超时!

请确保您的 IP 地址已在 Dynadot 后端列入白名单。IP 地址列入白名单可能需要一些时间(最长可达 1 小时)。

我被 Dynadot API 禁止了!

Dynadot API 只允许同时进行 1 个 API 调用。不允许进行并发 API 调用。如果您同时请求多个 API 调用,可能会被禁止。禁止时间为 10 到 15 分钟。
通过 dynadot 聊天获得的信息