hlrlookup/php-sdk 问题修复 & 功能扩展

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

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

hlrlookup/php-sdk

Composer 安装命令:

composer require hlrlookup/php-sdk

包简介

PHP SDK for the HLR Lookup API - HLR, MNP, and Number Validation lookups

README 文档

README

Tests Latest Version PHPStan PHP License

The official PHP SDK for the HLR Lookup API — HLR, MNP, and Number Validation lookups.

Requirements

  • PHP 8.1+
  • ext-json

Installation

composer require hlrlookup/php-sdk

Quick Start

use HlrLookup\HlrLookup;
use HlrLookup\Config;

$hlr = new HlrLookup(new Config('your-api-key', 'your-api-secret'));

// Single number lookup
$results = $hlr->hlr('+447540822872');

$result = $results[0];
echo $result->liveStatus->value;          // "LIVE"
echo $result->telephoneNumberType->value; // "MOBILE"
echo $result->isLive();                   // true
echo $result->isPorted();                 // true/false

Lookup Types

// HLR Lookup (full live status check) - 1 credit
$results = $hlr->lookups()->hlr('447540822872');

// MNP Lookup (number portability only) - 0.5 credits
$results = $hlr->lookups()->mnp('447540822872');

// Number Validation
$results = $hlr->lookups()->validate('447540822872');

Multiple Numbers

Up to 80 numbers per request:

$results = $hlr->hlr('447540822872', '441133910781', '17148307000');

foreach ($results as $result) {
    echo $result->detectedTelephoneNumber . ': ' . $result->liveStatus->value . "\n";
}

Per-Request Options

use HlrLookup\DTO\LookupRequest;
use HlrLookup\Enum\SaveToCache;

$request = new LookupRequest(
    telephoneNumber: '447540822872',
    cacheDaysPrivate: 30,
    cacheDaysGlobal: 15,
    saveToCache: SaveToCache::YES,
    outputFormat: 'E164',
    inputFormat: 'GBR',         // ISO3 country code for local numbers
    getPortedDate: true,        // +1 credit
    getLandlineStatus: true,    // +1 credit (UK/Ireland only)
    usaStatus: true,            // +1 credit (USA mobile only)
);

$results = $hlr->hlr($request);

Working with Results

$result = $results[0];

// Status
$result->liveStatus;              // LiveStatus enum: LIVE, DEAD, ABSENT_SUBSCRIBER, etc.
$result->telephoneNumberType;     // TelephoneNumberType enum: MOBILE, LANDLINE, VOIP, etc.
$result->isPorted;                // PortedStatus enum: YES, NO, UNKNOWN
$result->disposableNumber;        // DisposableStatus enum: YES, UNKNOWN

// Convenience methods
$result->isLive();                // bool
$result->isDead();                // bool
$result->isPorted();              // bool
$result->isDisposable();          // bool
$result->hasError();              // bool

// Network details
$result->originalNetworkDetails->name;       // "O2 (UK)"
$result->originalNetworkDetails->mccmnc;     // "23410"
$result->originalNetworkDetails->countryIso3; // "GBR"
$result->currentNetworkDetails->name;        // "EE"

// Other fields
$result->creditsSpent;            // float
$result->detectedTelephoneNumber; // "447540822872"
$result->formattedTelephoneNumber;// "+447540822872" (when output_format set)
$result->uuid;                    // unique identifier
$result->timestamp;               // "2022-10-07T13:06:15Z"
$result->portedDate;              // ISO 8601 date or "NOT_AVAILABLE"

Balance Check

$balance = $hlr->lookups()->balance();
echo $balance->credits; // 150.5

Bulk Operations

use HlrLookup\DTO\BatchArguments;

$bulk = $hlr->bulk();

// Create a batch
$batch = $bulk->create('my-numbers.csv');

// Upload numbers
$bulk->uploadNumbers($batch->id, ['447540822872', '441133910781']);

// Or upload a file
$bulk->uploadFile($batch->id, '/path/to/numbers.csv');

// Start processing
$bulk->start($batch->id);

// Check status
$batch = $bulk->get($batch->id);
echo $batch->status->value; // "PROCESSING", "COMPLETE", etc.

// Download results
$csv = $bulk->resultsCsv($batch->id);
$results = $bulk->resultsJson($batch->id); // LookupResult[]

// Schedule for later
$bulk->schedule($batch->id, new \DateTimeImmutable('2024-01-15T10:00:00Z'));

// Pause / delete
$bulk->pause($batch->id);
$bulk->delete($batch->id); // irreversible

Error Handling

use HlrLookup\Exception\AuthenticationException;
use HlrLookup\Exception\BadRequestException;
use HlrLookup\Exception\RateLimitException;
use HlrLookup\Exception\ServerException;
use HlrLookup\Exception\ValidationException;

try {
    $results = $hlr->hlr('447540822872');
} catch (AuthenticationException $e) {
    // 401 - Invalid credentials
} catch (BadRequestException $e) {
    // 400 - Invalid parameters
} catch (RateLimitException $e) {
    // 429 - Too many requests, retry later
} catch (ServerException $e) {
    // 500 - Server error
} catch (ValidationException $e) {
    // Client-side validation (e.g., >80 numbers)
}

Optional Headers

$config = new Config(
    apiKey: 'your-key',
    apiSecret: 'your-secret',
    referenceId: 'my-ref-123',
    accountId: 'my-account',
);

Testing Suite

We provide a free testing suite at testing.hlrlookup.com so you can develop and test your integration without incurring any charges. The testing suite is pre-populated with example responses and is not connected to real telephone networks — no credits are spent.

$hlr = new HlrLookup(Config::testing());
$results = $hlr->hlr('441133910781');

Config::testing() is preconfigured with the testing suite URL and credentials, so you can start integrating immediately without needing an account.

Test Numbers

The following numbers are available in the testing suite and return realistic responses:

Number Type
447540822872 MOBILE
441133910781 LANDLINE
818000804085 TOLL_FREE
448719429222 PREMIUM
6531522665 VOIP
447640123456 PAGER
7540 BAD_FORMAT

For a complete list of test numbers, see the testing documentation.

Running SDK Tests

# Unit tests (mocked HTTP, no network access)
vendor/bin/phpunit --testsuite unit

# Integration tests (hits the free testing suite at testing.hlrlookup.com)
vendor/bin/phpunit --group integration

License

MIT

hlrlookup/php-sdk 适用场景与选型建议

hlrlookup/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sms」 「phone-number」 「hlr」 「Telecoms」 「mnp」 「hlr-lookup」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 hlrlookup/php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-16