balfour/domains-coza-api

此包已废弃且不再维护。未建议替代包。

与domains.co.za经销商API的集成

0.0.1-alpha 2020-02-24 11:31 UTC

This package is auto-updated.

Last update: 2022-11-24 17:49:31 UTC


README

与domains.co.za经销商API的集成。

此库处于早期发布阶段,正在等待单元测试。

目录

安装

composer require balfour/domains-coza-api

用法

请参阅https://www.domains.co.za/api/latest_api.pdf以获取完整的API文档。

创建客户端

use GuzzleHttp\Client as Guzzle;
use Balfour\DomainsResellerAPI\Client;

$guzzle = new Guzzle();
$client = new Client($guzzle, 'your-api-key');

注册域名

$response = $client->registerDomain(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    'dns-admin@moo.com',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape',
    1, // years - max of 1 year for co.za domains
    true, // use managed nameservers
    [],
    'TEST1' // optional external ref
);

// using custom nameservers
$response = $client->registerDomain(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    'dns-admin@moo.com',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape',
    1, // years - max of 1 year for co.za domains
    false, // not using managed nameservers
    [
        'ns1.foo.bar',
        'ns2.foo.bar',
        'ns3.foo.bar',
        'ns4.foo.bar',
        'ns5.foo.bar',
    ],
    'TEST1' // optional external ref
);

// you can also register a domain using an implementation of RegistrantInterface
// eg: assuming $registrant is an implementation
$response = $client->registerDomainForRegistrant('mydomain.co.za', $registrant);

检查域名可用性

$isAvailable = $client->isDomainAvailable('mydomain.co.za');

删除域名

$response = $client->deleteDomain('mydomain.co.za');

更新域名注册人

$response = $client->updateDomainRegistrant(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    'dns-admin@moo.com',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape'
);

// you can also use an implementation of RegistrantInterface
$client->updateDomainRegistrantFromRegistrant('mydomain.co.za', $registrant);

续费域名

$response = $client->renewDomain('mydomain.co.za', 1);

域名转移

$response = $client->transferDomain(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    'dns-admin@moo.com',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape',
    null, // epp key (if required for tld)
    'keep', // possible values are keep, managed or custom
    [], // cusotm nameservers - only used if dns type is set to 'custom'
    'TEST1' // optional external ref
);

// you can also use an implementation of RegistrantInterface
$client->transferDomainForRegistrant(
    'mydomain.co.za',
    $registrant,
    null, // epp key (if required for tld)
    'keep', // possible values are keep, managed or custom
    [], // cusotm nameservers - only used if dns type is set to 'custom'
    'TEST1' // optional external ref
);

暂停域名

$response = $client->suspendDomain('mydomain.co.za');

恢复域名

$response = $client->unsuspendDomain('mydomain.co.za');

检查多个TLD的可用性

$response = $client->checkMultipleTLDAvailability('mydomain');
var_dump($response->getTLDs());
var_dump($response->getAvailableTLDs());
var_dump($response->getAvailableTLDs());
var_dump($response->getTakenTLDs());
var_dump($response->getTLD('co.za'));
var_dump($response->isTLDAvailable('co.za'));

检索域名信息

$response = $client->getDomain('mydomain.co.za');

$contacts = $response->getContacts();
var_dump($contacts);

$registrant = $response->getRegistrant();
var_dump($registrant->getContactNumber());
var_dump($registrant->hasPendingUpdate());
var_dump($registrant->getPendingUpdate()->getExpectedChangeDate());

var_dump($response->getNameservers());

var_dump($response->getCreationDate());

更新DNS服务器

// use managed dns
$response = $client->updateNameservers('mydomain.co.za', true);

// use custom nameservers
$response = $client->updateNameservers(
    'mydomain.co.za',
    false,
    [
        'ns1.foo.bar',
        'ns2.foo.bar',
        'ns3.foo.bar',
        'ns4.foo.bar',
        'ns5.foo.bar',
    ]
);

检索域名EPP授权密钥

$response = $client->getDomainEPPAuthKey('mydomain.co.za');
var_dump($response->getEPPKey());

取消域名更新

$response = $client->cancelDomainUpdate('mydomain.co.za');

取消域名删除

$response = $client->cancelDomainDelete('mydomain.co.za');

设置域名自动续费

$response = $client->setDomainAutoRenew('mydomain.co.za', true);
$response = $client->setDomainAutoRenew('mydomain.co.za', false);
$response = $client->enableDomainAutoRenew('mydomain.co.za');
$response = $client->disableDomainAutoRenew('mydomain.co.za');

检查域名转移

$response = $client->checkDomainTransfer('mydomain.co.za');
var_dump($response->getRequestDate());
var_dump($response->getStatus());
var_dump($response->isComplete());

取消域名转移

$response = $client->cancelDomainTransfer('mydomain.co.za');

检索域名总数摘要

$response = $client->getDomainTotalsSummary();
var_dump($response->getSummary());
var_dump($response->getTotalTransfersIn());

列出域名

$response = $client->getDomains();

// using limit and offset
$response = $client->getDomains(15, 0);

// sorting results
$response = $client->getDomains(15, 0, 'dateRegistered');
$response = $client->getDomains(15, 0, 'dateRegistered', 'descending');

// filtering results
$response = $client->getDomains(15, 0, 'name', 'ascending', 'expiring90');

var_dump($response->getTotal());

foreach ($response->getDomains() as $domain) {
    var_dump($domain->getName());
    var_dump($domain->isPremiumDNSEnabled());
    var_dump($domain->getCreationDate());
    var_dump($domain->getNameservers());
}

搜索域名

$response = $client->searchDomains('mydomain');

foreach ($response->getDomains() as $domain) {
    var_dump($domain->getName());
    var_dump($domain->getStatus());
}

检索DNS记录

use Badcow\DNS\AlignedBuilder;

$response = $client->getDNSRecords('mydomain.co.za');

var_dump($response->toArray());

foreach ($response->getRecords() as $record) {
    var_dump($record->getType());
    var_dump($record->getName());
    var_dump($record->getContent());
    var_dump($record->getPriority()); // only applicable to MX records
    var_dump($record->getTTL());
}

// filter by type of record
$records = $response->getRecordsByType('MX');

// the records can be formatted as a zone file
$zone = $response->getZone();
echo AlignedBuilder::build($zone);

更新DNS记录

请注意

  1. API只支持A、AAAA、CNAME、MX和TXT记录。
  2. 每次更新都会完全替换区域文件。
use Badcow\DNS\Rdata\Factory;
use Badcow\DNS\ResourceRecord;

// this example assumes no existing records
$a = new ResourceRecord;
$a->setName('sub.domain');
$a->setTtl(3600);
$a->setRdata(Factory::A('127.0.0.1'));

$mx = new ResourceRecord();
$mx->setName('@');
$mx->setRdata(Factory::Mx(10, 'mail-gw1.example.net.'));

$response = $client->updateDNSRecords('mydomain.co.za', [$a, $mx]);

// here, we first fetch the existing records, add a new record to the zone, then update passing in the zone
$response = $client->getDNSRecords('mydomain.co.za');
$zone = $response->getZone();

$a = new ResourceRecord;
$a->setName('sub.domain');
$a->setTtl(3600);
$a->setRdata(Factory::A('127.0.0.1'));

$zone->addResourceRecord($a);

// notice how we're just passing in a 
$client->updateDNSRecordsFromZone($zone);

// you can also update the records from a local zone file
$client->updateDNSRecordsFromZoneFile('mydomain.co.za', '/path/to/zonefile');