hejunjie/mobile-locator
Composer 安装命令:
composer require hejunjie/mobile-locator
包简介
基于国内号段规则的手机号码归属地查询库,支持运营商识别与地区定位,适用于注册验证、用户画像、数据归档等场景 | A mobile number lookup library based on Chinese carrier rules. Identifies carriers and regions, suitable for registration checks, user profiling, and data archiving.
README 文档
README
English | 简体中文
A mobile phone number location lookup library based on Chinese number segment rules. Supports carrier and region identification, suitable for registration validation, user profiling, and data archiving.
Number segments included: 483,709
This project has been parsed by Zread. Click here for a quick overview: Understand this project
Features
- Offline lookup: No third-party API dependencies or network requests — all data is bundled locally
- On-demand loading: Data is split across multiple files by number prefix, loading only what's needed per query to minimize memory usage
- Carrier identification: Automatically identifies China Mobile, China Unicom, China Telecom, and other carriers
- Region resolution: Pinpoints location down to province and city
- Regular updates: Number segment data is updated periodically to stay current
Requirements
- PHP >= 8.1
Installation
composer require hejunjie/mobile-locator
Quick Start
<?php use Hejunjie\MobileLocator\MobileLocator; // Look up a phone number's carrier and location $info = MobileLocator::getCarrierInfo('16601750925'); print_r($info); // Array // ( // [province] => 上海 // [city] => 上海 // [isp] => 联通 // )
API
getCarrierInfo(string $phoneNumber, string $returnUnknown = '未知'): array
Queries carrier and location information for a given phone number.
| Parameter | Type | Description |
|---|---|---|
$phoneNumber |
string |
Phone number, must be numeric with at least 7 digits |
$returnUnknown |
string |
Default value returned when no match is found, defaults to '未知' |
Return value:
[
'province' => '上海', // Province
'city' => '上海', // City
'isp' => '联通', // Carrier / ISP
]
When no match is found, all three fields return the value of $returnUnknown.
Exceptions:
InvalidArgumentException: thrown when the phone number format is invalidException: thrown when a data file is corrupted or missing
Implementation: Uses the singleton pattern internally, with query results cached in memory. Repeated queries for the same number within a single process will not trigger redundant file reads.
getData(): array
Returns the full dataset of all number segments.
Warning
The data file is approximately 49MB, and decoding can consume 200–500MB of memory. The method sets memory_limit to 1024M internally. For production use, consider importing the data into an external cache such as Redis via this method.
Data Files
The project includes two types of data files:
| File | Description |
|---|---|
src/data.json |
Full dataset (~49MB), containing all number segments |
src/carrier_data_{prefix}.json |
Sharded files split by the first 3 digits, 56 files in total |
Data format:
{
"1660000": {
"province": "北京",
"city": "北京",
"isp": "联通"
}
}
Each segment (first 7 digits of a phone number) maps to a record containing province, city, and carrier information.
Performance Tips
The getCarrierInfo() method provides basic on-demand loading and in-memory caching, sufficient for low-frequency lookup scenarios. For higher performance requirements (high concurrency, batch queries), we recommend:
- Cache the full dataset in Redis: Use
getData()to retrieve all data and import it into Redis, then query directly from Redis - Implement your own batch lookup: For bulk phone number queries, preload the relevant segment files and perform batch matching to avoid repeated I/O overhead
Updates & Contributing
Number segment data is updated periodically. If you find missing or inaccurate data, feel free to open an Issue or PR.
hejunjie/mobile-locator 适用场景与选型建议
hejunjie/mobile-locator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.99k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2025 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hejunjie/mobile-locator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hejunjie/mobile-locator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 40
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-12