承接 e164-com/e164-php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

e164-com/e164-php-sdk

最新稳定版本:2.1

Composer 安装命令:

composer require e164-com/e164-php-sdk

包简介

A PHP SDK for interacting with the e164.com API.

README 文档

README

Tests Latest Version PHPStan PHP License

The official PHP SDK for the E164 API — phone number validation and network lookup.

Requirements

  • PHP 8.1+
  • ext-json

Installation

composer require e164-com/e164-php-sdk

Quick Start

use Vendor\E164\E164;

$e164 = new E164();
$result = $e164->lookup('441133910781');

echo $result->getType();            // "GEOGRAPHIC"
echo $result->getCallingCode();     // "44"
echo $result->getIso3();            // "GBR"
echo $result->getOperatorBrand();   // "BT"

Authentication (Optional)

The E164 API works without authentication, but if you have an API key you can pass it as the second parameter:

$e164 = new E164(null, 'your-api-key');
$result = $e164->lookup('441133910781');

This sends the key as an X-API-Key header with every request.

Working with Results

$result = $e164->lookup('441133910781');

// Number identification
$result->getPrefix();          // "44113391"
$result->getCallingCode();     // "44"
$result->getIso3();            // "GBR"
$result->getType();            // "GEOGRAPHIC"
$result->getLocation();        // Location if available

// Network details
$result->getTadig();           // TADIG code
$result->getMccmnc();          // "234"
$result->getOperatorBrand();   // "BT"
$result->getOperatorCompany(); // "BT"

// Number length constraints
$result->getTotalLengthMin();  // "12"
$result->getTotalLengthMax();  // "12"

// Metadata
$result->getWeight();          // "11"
$result->getSource();          // "e164.com"

Input Format

The SDK accepts phone numbers in various formats. Non-numeric characters (except +) are stripped automatically:

$e164->lookup('441133910781');      // digits only
$e164->lookup('+441133910781');     // with + prefix
$e164->lookup('+44-113-391-0781'); // formatted

Custom HTTP Client

You can inject your own Guzzle client for custom configuration (proxies, timeouts, etc.):

use GuzzleHttp\Client;
use Vendor\E164\E164;

$client = new Client([
    'timeout' => 10,
    'headers' => [
        'User-Agent' => 'MyApp/1.0',
    ],
]);

$e164 = new E164($client);

Error Handling

use Vendor\E164\E164;
use Vendor\E164\Exception\InvalidPhoneNumberException;
use Vendor\E164\Exception\ApiException;

try {
    $result = $e164->lookup('441133910781');
} catch (InvalidPhoneNumberException $e) {
    // Phone number is empty, non-numeric, or not found
} catch (ApiException $e) {
    // HTTP request failed (network error, timeout, server error)
}

Both exceptions extend RuntimeException, so you can catch them individually or together.

Running Tests

# Install dependencies
composer install

# Run tests
vendor/bin/phpunit

# Run static analysis
vendor/bin/phpstan analyse

Contributing

Fork the repository and submit a pull request. Please include tests for any new features or bug fixes.

License

MIT

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固