|
@@ -191,7 +191,7 @@ function simple_card_type($cardno)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function card_type($cardno,&$regin_no,$fCoroutine = false)
|
|
|
+function card_type($cardno,&$regin_no)
|
|
|
{
|
|
|
$regin_no = -1;
|
|
|
if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
|
|
@@ -202,66 +202,14 @@ function card_type($cardno,&$regin_no,$fCoroutine = false)
|
|
|
}
|
|
|
elseif(preg_match('/^1\d{10}$/',$cardno,$matches))
|
|
|
{
|
|
|
- $checker = function ($phone,&$region)
|
|
|
- {
|
|
|
-// if (empty($phone)) return false; //手机号不能为空
|
|
|
-// $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel={$phone}";
|
|
|
-// $resp = http_request($url); //获取API返回 的数据
|
|
|
-// if(empty($resp)) return false;
|
|
|
-//
|
|
|
-// $resp = mb_convert_encoding($resp, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); //解决中文乱码
|
|
|
-// $datas = explode('__GetZoneResult_', $resp);
|
|
|
-// if(count($datas) == 2)
|
|
|
-// {
|
|
|
-// $body = trim($datas[0]);
|
|
|
-// $res = json_decode($body,true);
|
|
|
-// if(empty($res)) return false;
|
|
|
-//
|
|
|
-// $province = formatProvince($res['province']);
|
|
|
-// $region = array_search($province, ProvinceList);
|
|
|
-// return $res;
|
|
|
-// }
|
|
|
-
|
|
|
- return false;
|
|
|
- };
|
|
|
-
|
|
|
- $i = 0;
|
|
|
- do {
|
|
|
- $ret = $checker($cardno, $region);
|
|
|
-// if($ret === false && $fCoroutine) {
|
|
|
-// Log::record("query card_type sleep one second.",Log::DEBUG);
|
|
|
-// Swoole\Coroutine::sleep(1);
|
|
|
-// }
|
|
|
- $i++;
|
|
|
- } while (empty($ret) && $i < 3);
|
|
|
-
|
|
|
- if (empty($ret))
|
|
|
- {
|
|
|
- $regin_no = -1;
|
|
|
- Log::record("淘宝接口没法使用了,用传统办法识别卡类型",Log::ERR);
|
|
|
- if (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) {
|
|
|
- return ChinaMobileCard;
|
|
|
- } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
|
|
|
- return ChinaUnicomCard;
|
|
|
- } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
|
|
|
- return ChinaTelecomCard;
|
|
|
- } else {
|
|
|
- return UnknownCard;
|
|
|
- }
|
|
|
- }
|
|
|
- elseif($ret['catName'] == '中国联通') {
|
|
|
- $regin_no = $region;
|
|
|
+ $regin_no = -1;
|
|
|
+ if (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) {
|
|
|
+ return ChinaMobileCard;
|
|
|
+ } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
|
|
|
return ChinaUnicomCard;
|
|
|
- }
|
|
|
- elseif($ret['catName'] == '中国电信') {
|
|
|
- $regin_no = $region;
|
|
|
+ } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
|
|
|
return ChinaTelecomCard;
|
|
|
- }
|
|
|
- elseif($ret['catName'] == '中国移动') {
|
|
|
- $regin_no = $region;
|
|
|
- return ChinaMobileCard;
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
return UnknownCard;
|
|
|
}
|
|
|
}
|
|
@@ -283,37 +231,86 @@ function oil_type($cardno)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function valid_phone($phone) : bool
|
|
|
+function valid_phone($card_no)
|
|
|
{
|
|
|
- $ali = function ($phone,&$net_err) : bool
|
|
|
+ $type_checker = function ($channel)
|
|
|
+ {
|
|
|
+ if($channel == '中国联通') {
|
|
|
+ return ChinaUnicomCard;
|
|
|
+ }
|
|
|
+ elseif($channel == '中国电信') {
|
|
|
+ return ChinaTelecomCard;
|
|
|
+ }
|
|
|
+ elseif($channel == '中国移动') {
|
|
|
+ return ChinaMobileCard;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return UnknownCard;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $validate_checker = function ($status)
|
|
|
+ {
|
|
|
+ // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号
|
|
|
+ if (in_array($status, [0,5])) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $regin_checker = function ($area)
|
|
|
+ {
|
|
|
+ $areas = explode('-',$area);
|
|
|
+ if(count($areas) > 0)
|
|
|
+ {
|
|
|
+ $province = $areas[0];
|
|
|
+ $endtxts= ["省","市","自治区","特别行政区"];
|
|
|
+
|
|
|
+ foreach ($endtxts as $endtxt)
|
|
|
+ {
|
|
|
+ if(strpos($province, $endtxt) === false) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ $province = mb_strcut($province, 0, strrpos($province, $endtxt));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $region = array_search($province, ProvinceList);
|
|
|
+ return $region;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $ali = function ($card_no, &$validate, &$card_type, &$region_no) use ($validate_checker, $type_checker, $regin_checker): bool
|
|
|
{
|
|
|
$url = 'https://mobileempty.shumaidata.com/mobileempty';
|
|
|
- $params['mobile'] = $phone;
|
|
|
+ $params['mobile'] = $card_no;
|
|
|
$headers = ["Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537'];
|
|
|
|
|
|
+ $net_err = 0;
|
|
|
$resp = http_request($url, $params, 'GET', false, $headers,$net_err);
|
|
|
- if ($resp == false) return true;
|
|
|
+ if ($resp == false) return false;
|
|
|
|
|
|
$resp = json_decode($resp, true);
|
|
|
- if ($resp == false) return true;
|
|
|
+ if ($resp == false) return false;
|
|
|
|
|
|
- if ($resp['success'] == true && $resp['code'] == 200)
|
|
|
+ if ($resp['code'] == 200)
|
|
|
{
|
|
|
- // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号
|
|
|
- $status = intval($resp['data']['status']);
|
|
|
- if (in_array($status, [0,5])) {
|
|
|
- Log::record("valid_phone phone:{$phone}, status : {$status}", Log::DEBUG);
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- Log::record("valid_phone phone:{$phone} return msg:{$resp['msg']}", Log::DEBUG);
|
|
|
+ $data = $resp['data'];
|
|
|
+ $validate = $validate_checker(intval($data['status']));
|
|
|
+ $card_type = $type_checker($data['channel']);
|
|
|
+ $region_no = $regin_checker($data['area']);
|
|
|
return true;
|
|
|
+ } else {
|
|
|
+ Log::record("ali_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
|
|
|
+ return false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- $tian_yan = function ($phone,&$net_err) : bool
|
|
|
+ $tianyan = function ($card_no, &$validate, &$card_type, &$region_no) use ($validate_checker, $type_checker, $regin_checker): bool
|
|
|
{
|
|
|
$url = 'https://api.shumaidata.com/v4/mobile_empty/check';
|
|
|
$appid = '2Xfa6IFIPv0sVUjy';
|
|
@@ -324,54 +321,46 @@ function valid_phone($phone) : bool
|
|
|
$data['timestamp'] = intval($cur * 1000);
|
|
|
$content = "{$appid}&{$data['timestamp']}&{$appSecurity}";
|
|
|
$data['sign'] = md5($content);
|
|
|
- $data['mobile'] = $phone;
|
|
|
+ $data['mobile'] = $card_no;
|
|
|
|
|
|
+ $net_err = 0;
|
|
|
$resp = http_request($url, $data, 'GET',false, [],$net_err);
|
|
|
- if ($resp == false) return true;
|
|
|
+ if ($resp == false) return false;
|
|
|
|
|
|
$resp = json_decode($resp, true);
|
|
|
- if ($resp == false) return true;
|
|
|
+ if ($resp == false) return false;
|
|
|
|
|
|
- if ($resp['success'] == true && $resp['code'] == 200)
|
|
|
+ if ($resp['code'] == 200)
|
|
|
{
|
|
|
- // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号
|
|
|
- $status = intval($resp['data']['status']);
|
|
|
- if (in_array($status, [0,5])) {
|
|
|
- Log::record("tianyan_valid_phone phone:{$phone}, status : {$status}", Log::DEBUG);
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- Log::record("tianyan_valid_phone phone:{$phone} return msg:{$resp['msg']}", Log::DEBUG);
|
|
|
+ $data = $resp['data'];
|
|
|
+ $validate = $validate_checker(intval($data['status']));
|
|
|
+ $card_type = $type_checker($data['channel']);
|
|
|
+ $region_no = $regin_checker($data['area']);
|
|
|
return true;
|
|
|
+ } else {
|
|
|
+ Log::record("tianyan_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
|
|
|
+ return false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- $net_err = 0;
|
|
|
- $ret = $tian_yan($phone,$net_err);
|
|
|
- if(empty($net_err)) return $ret;
|
|
|
+ $validate = true;
|
|
|
+ $card_type = card_type($card_no,$region_no);
|
|
|
+ $region_no = -1;
|
|
|
|
|
|
- $net_err = 0;
|
|
|
- return $ali($phone,$net_err);
|
|
|
-}
|
|
|
-
|
|
|
-function formatProvince(string $province) : string
|
|
|
-{
|
|
|
- if(empty($province)) {
|
|
|
- return '';
|
|
|
+ if($card_type == PetroChinaCard || $card_type == SinopecCard) {
|
|
|
+ return [$validate,$card_type,$region_no];
|
|
|
}
|
|
|
|
|
|
- $checkArr = ["省","市","自治区","特别行政区"];
|
|
|
+ $ret = $tianyan($card_no,$validate,$card_type,$region_no);
|
|
|
+ if($ret) {
|
|
|
+ return [$validate,$card_type,$region_no];
|
|
|
+ }
|
|
|
|
|
|
- for($i = 0; $i < count($checkArr); $i++)
|
|
|
- {
|
|
|
- if(strpos($province, $checkArr[$i]) === false) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- $province = mb_strcut($province, 0, strrpos($province, $checkArr[$i]));
|
|
|
- }
|
|
|
+ $ret = $ali($card_no,$validate,$card_type,$region_no);
|
|
|
+ if($ret) {
|
|
|
+ return [$validate,$card_type,$region_no];
|
|
|
}
|
|
|
|
|
|
- return $province;
|
|
|
+ $card_type = card_type($card_no,$region_no);
|
|
|
+ return [$validate,$card_type,$region_no];
|
|
|
}
|