- 使用 https://github.com/xluohome/phonedata 提供的数据库
- php >= 7.0
- Composer
composer require chendujin/mobile
将下面代码放入 bootstrap/app.php
$app->register(Chendujin\Mobile\ServiceProvider::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 \Chendujin\Mobile\Mobile();
// 查询
$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