手机号码归属地解析

使用 https://github.com/xluohome/phonedata 提供的数据库

环境需求

php >= 7.0 Composer

安装

composer require chendujin/mobile

配置

Laravel环境无需配置

Lumen

将下面代码放入 bootstrap/app.php

$app->register(ChendujinMobileServiceProvider::class);

验证器使用

<?php public function store(Request $request) { $validator = Validator::make($request->all(), [ 'phone' => 'required|is_cmcc|is_cucc|is_ctcc|is_ctccv|is_cuccv|is_cmccv|is_cbcc|is_cbccv' ]); if ($validator->fails()) { return new JsonResponse([ 'state' => 'error', 'message' => $validator->errors()->first(), ]); } }

其他使用

$mobile = new ChendujinMobileMobile(); // 查询 $mobile->search('15240881243'); // 是否是移动运营商 $mobile->isCMCC('18807397135'); // true // 是否是联通运营商 $mobile->isCUCC('15507645084'); // true // 是否是电信运营商 $mobile->isCTCC('18923516448'); // true // 是否是广电运营商 $mobile->isCBCC('19212071413'); // true // 是否为手机号码 $mobile->isMobilePhone('18923516448'); // true // 判断是否为座机号码 $mobile->isTelPhone('5957126'); // true

命令行工具

php bin/searchMobile 15240881243

返回:

Array ( [mobile] => 15240881243 [province] => 云南 [city] => 昭通 [zip_code] => 657000 [area_code] => 0870 [operator_type] => 移动 ) time: 0.0093469620 s memory:664 B

单元测试

./vendor/bin/phpunit

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。