reashetyr/namecheap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

reashetyr/namecheap

Composer 安装命令:

composer require reashetyr/namecheap

包简介

Easy access to the Namecheap xml api using PHP

README 文档

README

THIS IS STILL IN VERY BETA DO NOT USE YET!

namecheap-php is a Namecheap API client in PHP. API itself is documented at https://www.namecheap.com/support/api/intro/

This client supports:

  • Registering a domain
  • Checking domain name availability
  • Listing domains you have registered
  • Getting contact information for a domain
  • Setting DNS info to default values
  • Set DNS host records

Installation

Installation is as simple as:

composer require reashetyr/namecheap

How to sign up to start using the API

The API has two environments, production and sandbox. Since this API will spend real money when registering domains, start with the sandbox by going to http://www.sandbox.namecheap.com/ and creating an account. Accounts between production and sandbox are different, so even if you already have a Namecheap account you will need a new one.

After you have an account, go to "Profile".

Profile

From there, select the "Profile" menu again, then "Tools". Scroll to the bottom of the page to the "Business & Dev Tools" and select "Manage" on the "Namecheap API Access" section.

API menu

You'll get to your credentials page. From here you need to take note of your api key, username and add your IP to the whitelist of IP addresses that are allowed to access the account. You can check your public IP by searching "what is my ip" on Google and add it here. It might take some time before it actually starts working, so don't panic if API access doesn't work at first.

Credentials

How to access the API from PHP

Install the package using composer. You can access the API as follows:

use reashetyr\NameCheap\NameCheap;
$api = new NameCheap(username, api_key, username, ip_address, true);

The fields are the ones which appear in the credentials screen above. The username appears twice, because you might be acting on behalf of someone else.

Registering a domain name using the API

Unfortunately you need a bunch of contact details to register a domain, so it is not as easy as just providing the domain name. In the sandbox, the following contact details are acceptable. Trickiest field is the phone number, which has to be formatted as shown.

NameCheap.domains_create([
    'DomainName' => 'registeringadomainthroughtheapiwow.com',
    'FirstName' => 'Jack',
    'LastName' => 'Trotter',
    'Address1' => 'Ridiculously Big Mansion, Yellow Brick Road',
    'City' => 'Tokushima',
    'StateProvince' => 'Tokushima',
    'PostalCode' => '771-0144',
    'Country' => 'Japan',
    'Phone' => '+81.123123123',
    'EmailAddress' => 'jack.trotter@example.com'
]);

This call should succeed in the sandbox, but if you use the API to check whether this domain is available after registering it, the availability will not change. This is normal.

How to check if a domain name is available

The domains_check method returns True if the domain is available.

NameCheap.domains_check(domain_name);

You can also pass a list of domain names, in which case it does a batch check for all and returns an array of the answers. You should probably not be writing a mass domain checking tool using this, it is intended to be used before registering a domain.

Basic host records management code

Here's the example of simple DNS records management script:

<?php

use reashetyr\NameCheap\NameCheap;

$api = new NameCheap($username, $api_key, $username, $ip_address, false);

$domain = "example.org";

# list domain records
$api->domains_dns_getHosts(domain);

$record = [
    # required
    "Type" => "A",
    "Name" => "test1",
    "Address" => "127.0.0.1",

    # optional
    "TTL" => "1800",
    "MXPref" => "10"
];

# add A "test1" record pointing to 127.0.0.1
$api->domains_dns_addHost($domain, $record);

# delete record we just created,
# selecting it by Name, Type and Address values
$api.domains_dns_delHost($domain, $record);

Retry mechanism

Sometimes you could face wrong API responses, which are related to server-side errors.

We implemented retry mechanism, one could enable it by adding 2 parameters to NameCheap instance:

$api = new NameCheap($username, $api_key, $username, $ip_address, false, 3, 0.1);

Values of 2 or 3 should do the thing.

More

This is a reimplementation from the python source: https://github.com/Bemmu/PyNamecheap

reashetyr/namecheap 适用场景与选型建议

reashetyr/namecheap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 reashetyr/namecheap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 reashetyr/namecheap 我们能提供哪些服务?
定制开发 / 二次开发

基于 reashetyr/namecheap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-05