PHP mã nguồn mở

Registrar API

Một thư viện PHP duy nhất để quản lý tên miền trên NameSilo, GoDaddy, Namecheap và Dynadot — cùng một adapter Cloudflare cho zone, DNS và cache. Kiểm tra khả dụng, đăng ký, gia hạn, chuyển nhượng, bản ghi DNS và máy chủ tên, tất cả qua một giao diện nhất quán.

composer require josuamarcelc/registrar-api

Adapter

Các nhà đăng ký được hỗ trợ

Chọn adapter theo chuỗi tên thương hiệu. Tất cả adapter dùng chung cùng chữ ký phương thức, nên bạn có thể đổi nhà đăng ký mà không cần viết lại mã.

NameSilo'namesilo'
GoDaddy'godaddy'
Namecheap'namecheap'
Dynadot'dynadot'
CloudflareDNS / zones

Demo trực tiếp

Kiểm tra tên miền còn trống

Chạy một lệnh gọi checkAvailability() thật qua adapter NameSilo ở phía máy chủ. Nhập tối đa 10 tên miền, cách nhau bằng dấu phẩy, khoảng trắng hoặc dòng mới. Giới hạn 10 lần kiểm tra mỗi 5 phút.

Bắt đầu nhanh

Ba dòng để có lệnh gọi hoạt động

<?php
require __DIR__ . '/vendor/autoload.php';

use RegistrarAPI\RegistrarAPI;

$api = RegistrarAPI::make('namesilo', [
  'api_key' => 'YOUR_NAMESILO_API_KEY'
]);

$result = $api->checkAvailability(['example.com', 'mybrand.io']);
print_r($result);

Thông tin xác thực

Cấu hình theo adapter

Mỗi adapter nhận một mảng cấu hình. Dưới đây là mức tối thiểu bạn thường cần.

NameSilo
RegistrarAPI::make('namesilo', [
  'api_key' => 'YOUR_KEY',
]);
GoDaddy
RegistrarAPI::make('godaddy', [
  'api_key'    => 'KEY',
  'api_secret' => 'SECRET',
  // optional: 'base' => 'https://api.godaddy.com/v1'
]);
Namecheap
RegistrarAPI::make('namecheap', [
  'api_user'  => 'USERNAME',
  'api_key'   => 'KEY',
  'client_ip' => 'SERVER_PUBLIC_IP',
  // optional: 'base' => 'https://api.namecheap.com/xml.response'
]);
Dynadot
RegistrarAPI::make('dynadot', [
  'api_key' => 'KEY',
]);

Phương thức

Các thao tác thường dùng

Mọi adapter đều triển khai cùng chữ ký phương thức. Giá trị trả về là mảng kết hợp đã được chuẩn hóa.

// Availability
$api->checkAvailability(['example.com']);

// Lifecycle
$api->registerDomain('example.com', [
  'years'      => 1,
  'privacy'    => true,
  'auto_renew' => true,
  'registrant' => [ /* contact fields */ ],
]);
$api->renewDomain('example.com', 1);
$api->transferDomain('example.com', ['auth_code' => 'EPP']);
$api->getDomain('example.com');

// DNS records
$api->getDNS('example.com');
$api->setDNS('example.com', [
  ['type'=>'A',    'host'=>'@',   'value'=>'203.0.113.10', 'ttl'=>600],
  ['type'=>'CNAME','host'=>'www', 'value'=>'@',            'ttl'=>600],
]);
$api->addDNS('example.com', ['type'=>'TXT','host'=>'@','value'=>'v=spf1 -all','ttl'=>300]);
$api->delDNS('example.com', ['type'=>'TXT','host'=>'@']);

// Nameservers
$api->setNameServers('example.com', ['ns1.host.com','ns2.host.com']);

// Escape hatch — call any raw endpoint the adapter doesn't wrap
$api->raw('domains/suggestions?query=mybrand&limit=5');

Cấu trúc phản hồi

Những gì bạn nhận được

okbool — kiểm tra thành công nhanh
rawpayload gốc đã phân tích của nhà đăng ký (JSON hoặc XML-thành-mảng)
httpmã trạng thái HTTP khi có
errchuỗi lỗi ở tầng truyền tải (chỉ khi lệnh gọi thất bại)
available / unavailable / invalidcác nhóm được điền bởi checkAvailability()
recordsmảng gồm {type,host,value,ttl,prio?} do getDNS() trả về

Phần thưởng

Adapter Cloudflare

Cùng thư viện, cùng cấu trúc, nhưng dành cho zone, bản ghi DNS, xóa cache và các công tắc miễn phí (Always HTTPS, Auto HTTPS Rewrites, Brotli, Minify, Rocket Loader, Dev Mode).

$cf = RegistrarAPI::make('cloudflare', ['api_token' => 'CF_TOKEN']);
$cf->createZone('example.com');
$cf->setDNS('example.com', [
  ['type'=>'A','host'=>'@','value'=>'198.51.100.10','ttl'=>300,'proxied'=>true],
]);
$cf->purgeEverything('example.com');

Đóng góp

Thêm nhà đăng ký mới trong một tệp

Tạo một lớp trong src/adapters/ kế thừa BaseAdapter và triển khai các phương thức trừu tượng. Composer sẽ tự động nạp nó.

namespace RegistrarAPI\Adapters;

use RegistrarAPI\Core\BaseAdapter;

class MyRegistrar extends BaseAdapter {
  protected string $brand = 'myregistrar';

  public function checkAvailability(array $domains): array { /* ... */ }
  public function registerDomain(string $domain, array $opts): array { /* ... */ }
  public function renewDomain(string $domain, int $years=1, array $opts=[]): array { /* ... */ }
  public function transferDomain(string $domain, array $opts): array { /* ... */ }
  public function getDomain(string $domain): array { /* ... */ }
  public function getDNS(string $domain): array { /* ... */ }
  public function setDNS(string $domain, array $records): array { /* ... */ }
  public function addDNS(string $domain, array $record): array { /* ... */ }
  public function delDNS(string $domain, array $selector): array { /* ... */ }
  public function setNameServers(string $domain, array $nameservers): array { /* ... */ }
  public function raw(string $op, array $params=[]): array { /* ... */ }
}