|
@@ -109,6 +109,8 @@ function topcard_format($card_list)
|
|
|
return $ret;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
function card_type($cardno)
|
|
|
{
|
|
|
if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
|
|
@@ -117,14 +119,43 @@ function card_type($cardno)
|
|
|
elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
|
|
|
return PetroChinaCard;
|
|
|
}
|
|
|
- elseif(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;
|
|
|
+ elseif(preg_match('/^1\d{10}$/',$cardno,$matches))
|
|
|
+ {
|
|
|
+ $checker = function ($phone) {
|
|
|
+ if (empty($phone)) return false; //手机号不能为空
|
|
|
+ $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel={$phone}";
|
|
|
+ $resp = file_get_contents($url); //获取API返回 的数据
|
|
|
+ $resp = mb_convert_encoding($resp, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); //解决中文乱码
|
|
|
+
|
|
|
+ $datas = explode('=', $resp);
|
|
|
+ if(count($datas) == 2)
|
|
|
+ {
|
|
|
+ $body = trim($datas[1]);
|
|
|
+ if(preg_match_all("/(\w+):'([^']+)/", $body, $m)) {
|
|
|
+ $res = array_combine($m[1], $m[2]);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+
|
|
|
+ $ret = $checker($cardno);
|
|
|
+ if(empty($ret)) {
|
|
|
+ return UnknownCard;
|
|
|
+ }
|
|
|
+ elseif($ret['catName'] == '中国联通') {
|
|
|
+ return ChinaUnicomCard;
|
|
|
+ }
|
|
|
+ elseif($ret['catName'] == '中国电信') {
|
|
|
+ return ChinaTelecomCard;
|
|
|
+ }
|
|
|
+ elseif($ret['catName'] == '中国移动') {
|
|
|
+ return ChinaMobileCard;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return UnknownCard;
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
return UnknownCard;
|