edsi-tech / gandi-bundle
此软件包最新版本(v1.2)没有提供许可证信息。
EDSI-Tech 为 Gandi V3 API 开发的 Gandi Bundle
v1.2
2018-01-24 16:48 UTC
Requires
- php: ^5.4 || ^7.0
- ocramius/proxy-manager: ^2.0
- symfony/symfony: ^2.8 || ^3.4 || ^4.0
- zendframework/zend-xmlrpc: ^2.6
- zendframework/zendxml: ^1.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-14 18:25:55 UTC
README
Gandi API v3
安装
- 使用 composer 安装软件包
composer require edsi-tech/gandi-bundle
- 注册 Bundle
在您的 AppKernel.php 中添加 new EdsiTech\GandiBundle\EdsiTechGandiBundle(),
- 添加必需的配置选项
在您的 app/config/config.yml 中
edsitech_gandi: server_url: "https://rpc.ote.gandi.net/xmlrpc/" api_key: default_nameservers: - dns1.edsi-tech.com - dns2.edsi-tech.com - dns3.edsi-tech.com default_handles: bill: XYZ-GANDI tech: XYZ-GANDI admin: XYZ-GANDI owner: XYZ-GANDI
注意测试服务器是 https://rpc.ote.gandi.net/xmlrpc/
,而生产服务器是 https://rpc.gandi.net/xmlrpc/
使用示例
获取所有域名及其过期日期
$currentHandle = "MYHANDLE-GANDI"; $domainRepository = $this->get('edsitech_gandi.domain_repository'); $domains_api = $domainRepository->findBy(['handle' => $currentHandle]); foreach($domains_api as $domain) { $fqdn = $domain->getFqdn(); echo $fqdn.": ".$domain->getExpire()->format('Y-m-d')."\n"; }
获取一个域名
use EdsiTech\GandiBundle\Model\Domain; $fqdn = "example.com"; $domainRepository = $this->get('edsitech_gandi.domain_repository'); $domain = $domainRepository->find($fqdn); if($domain instanceof Domain) { print_r($domain); }
获取可用扩展
$gandi = $this->get('edsitech_gandi.domain_availibility'); print_r($gandi->getExtensions());
检查域名可用性
$domain = "example.com"; $domainAPI = $this->get('edsitech_gandi.domain_availibility'); $domain = idn_to_ascii($domain); //needed for special chars domains $result = $domainAPI->isAvailable([$domain]); //this is an array, you can pass multiple domains print_r($result); //the result is also an array, the key is the domain name and the value is the result.
注册域名
use EdsiTech\GandiBundle\Model\Domain; use EdsiTech\GandiBundle\Model\Contact; use EdsiTech\GandiBundle\Model\Operation; use EdsiTech\GandiBundle\Exception\APIException; $fqdn = "example.com"; $myHandle = "XYZ-GANDI"; $domain = new Domain($fqdn); $domain->setDuration(1) //years ->setAutorenew(true) ->setOwnerContact(new Contact($myHandle)) ; //others contact informations are taken from the default_handles config keys. $domainRepository = $this->get('edsitech_gandi.domain_repository'); try { $result = $domainRepository->register($domain); if($result instanceof Operation) { echo "Operation in progress"; } } catch (APIException $e) { $message = $e->getMessage(); echo "Error: ".$message; }
转移域名
use EdsiTech\GandiBundle\Model\Operation; $domain = "example.com"; $authcode = "test"; $domainRepository = $this->get('edsitech_gandi.domain_repository'); $result = $domainRepository->transfert($domain, $authcode); if($result instanceof Operation) { echo "Operation in progress"; }
启用自动续费
use EdsiTech\GandiBundle\Exception\APIException; $fqdn = "example.com"; $domainRepository = $this->get('edsitech_gandi.domain_repository'); $domain = $domainRepository->find($fqdn); try { $domainRepository->enableAutorenew($domain); } catch (APIException $e) { echo "That's an error"; }
禁用域名锁定
use EdsiTech\GandiBundle\Exception\APIException; $fqdn = "example.com"; $domainRepository = $this->get('edsitech_gandi.domain_repository'); $domain = $domainRepository->find($fqdn); try { $domain->setLock(false); $domainRepository->update($domain); } catch (APIException $e) { echo "That's an error"; }
为联系人创建一个 Symfony2 表单
use EdsiTech\GandiBundle\Form\ContactType; use EdsiTech\GandiBundle\Model\Contact; use EdsiTech\GandiBundle\Exception\APIException; $contactRepository = $this->get('edsitech_gandi.contact_repository'); $contact = $contactRepository->find($currentHandle); $form = $this->createForm(new ContactType(), $contact); //.... if ($form->isValid()) { try { $result = $contactRepository->persist($contact); } catch (APIException $e) { //... } }
免责声明
- API 需要一些额外的信息,这些信息针对特定顶级域(tld)未在本软件包中实现。
- DNSSEC 支持正在开发中,尚未完全实现。
- 您可能需要向域名和扩展列表中添加缓存层(例如 redis),因为获取结果需要 10-15 秒。
测试
运行 bin/phpunit Tests/