stanley-king 3 лет назад
Родитель
Сommit
439e42c66e
2 измененных файлов с 129 добавлено и 73 удалено
  1. 125 71
      helper/mtopcard/mtopcard.php
  2. 4 2
      test/TestCardNo.php

+ 125 - 71
helper/mtopcard/mtopcard.php

@@ -72,6 +72,40 @@ const ProvinceList = [
     31	=> '新疆'
 ];
 
+const Prov2Noes = [
+    '北京' => 1,
+    '天津' => 2,
+    '河北' => 3,
+    '山西' => 4,
+    '内蒙古' => 5,
+    '辽宁' => 6,
+    '吉林' => 7,
+    '黑龙江' => 8,
+    '上海' => 9,
+    '江苏' => 10,
+    '浙江' => 11,
+    '安徽' => 12,
+    '福建' => 13,
+    '江西' => 14,
+    '山东' => 15,
+    '河南' => 16,
+    '湖北' => 17,
+    '湖南' => 18,
+    '广东' => 19,
+    '广西' => 20,
+    '海南' => 21,
+    '重庆' => 22,
+    '四川' => 23,
+    '贵州' => 24,
+    '云南' => 25,
+    '西藏' => 26,
+    '陕西' => 27,
+    '甘肃' => 28,
+    '青海' => 29,
+    '宁夏' => 30,
+    '新疆' => 31,
+];
+
 #空号拦截状态
 const CardState = [
     0 => '空号',
@@ -243,7 +277,7 @@ function oil_type($cardno)
 }
 
 //[$validate,$card_type,$region_no,$isTransfer,$status,$black]
-function valid_phone($card_no)
+function tianyan_valid_phone($card_no)
 {
     $type_checker = function ($channel)
     {
@@ -290,12 +324,12 @@ function valid_phone($card_no)
                 }
             }
 
-            $region = array_search($province, ProvinceList);
-            return $region;
-        }
-        else {
-            return -1;
+            if(array_key_exists($province,Prov2Noes)) {
+                return Prov2Noes[$province];
+            }
         }
+
+        return -1;
     };
 
     $ali = function ($card_no, &$validate, &$region_no,&$status) use ($validate_checker, $regin_checker): bool
@@ -396,59 +430,6 @@ function valid_phone($card_no)
         }
     };
 
-    $time_checker = function ($update_time)
-    {
-        //90 天以内数据有效
-        $delta = time() - intval($update_time);
-        return $delta < 360 * 86400 && $delta >= 0;
-    };
-
-    $pinfo_getter = function ($card_no) use ($validate_checker,$time_checker)
-    {
-        $mod_card = Model('card_info');
-        $info = $mod_card->getCardInfo($card_no);
-
-        if(empty($info)) {
-            return [false,[]];
-        }
-        elseif($time_checker($info['update_time'])) {
-            $mod_card->where(['card_no' => $card_no])->update(['using_times' => $info['using_times'] + 1]);
-
-            $card_type = intval($info['card_type']);
-            $region_no = intval($info['regin']);
-            $isTransfer = intval($info['transfer']) == 0 ? false : true;
-            $status = intval($info['card_state']);
-            $black = intval($info['black']);
-            $validate = $validate_checker($status);
-
-            $result = [$validate,$card_type,$region_no,$isTransfer,$status,$black];
-            return [true,$result];
-        }
-        else {
-            return [false,[]];
-        }
-    };
-
-    $pinfo_updator = function ($card_no,$card_type,$org_type,$region_no,$isTransfer,$status)
-    {
-        $mod_card = Model('card_info');
-        $transfer = $isTransfer == true ? 1 : 0;
-        $mod_card->replace_card($card_no,$card_type,$org_type,$region_no,$transfer,$status);
-    };
-
-    $validate = true;
-    $black = 0;
-
-    $card_type = card_type($card_no,$region_no);
-    $region_no = -1;
-
-    if($card_type == PetroChinaCard || $card_type == SinopecCard) {
-        return [$validate,$card_type,$region_no,false,1,$black];
-    }
-
-    [$succ,$result] = $pinfo_getter($card_no);
-    if($succ) return $result;
-
     [$succ,$_card_type,$_org_type,$_isTransfer] = $tianyan_cardtyper($card_no);
     if($succ) {
         $card_type = $_card_type;
@@ -463,18 +444,16 @@ function valid_phone($card_no)
     $ret = $tianyan($card_no,$validate,$region_no,$status);
     if($ret)
     {
-        if($succ) $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
-        return [$validate,$card_type,$region_no,$isTransfer,$status,$black];
+        return [$validate,$card_type,$region_no,$isTransfer,$status];
     }
 
     $ret = $ali($card_no,$validate,$region_no,$status);
     if($ret)
     {
-        if($succ) $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
-        return [$validate,$card_type,$region_no,$isTransfer,$status,$black];
+        return [$validate,$card_type,$region_no,$isTransfer,$status];
     }
 
-    return [true,$card_type,-1,false,$status,$black];
+    return [true,$card_type,-1,false,$status];
 }
 
 function is_validate($status)
@@ -486,19 +465,18 @@ function is_validate($status)
     }
 }
 
-
 function tencent_valid_phone($card_no)
 {
     $type_checker = function ($channel)
     {
-        if($channel == 'CUCC') {
-            return ChinaUnicomCard;
+        if($channel == 'CMCC') {
+            return ChinaMobileCard;
         }
         elseif($channel == 'CTCC') {
             return ChinaTelecomCard;
         }
-        elseif($channel == 'CMCC') {
-            return ChinaMobileCard;
+        elseif($channel == 'CUCC') {
+            return ChinaUnicomCard;
         }
         else {
             return UnknownCard;
@@ -509,7 +487,7 @@ function tencent_valid_phone($card_no)
     {
         // 字段code:【1 为实号;2为空号;3为停机;4为流量卡;5为沉默号】
         Log::record("status={$code}",Log::DEBUG);
-        if (in_array($code, [2])) {
+        if (in_array($code, [2, 4])) {
             return false;
         } else {
             return true;
@@ -530,7 +508,11 @@ function tencent_valid_phone($card_no)
             }
         }
 
-        return array_search($province, ProvinceList);
+        if(array_key_exists($province,Prov2Noes)) {
+            return Prov2Noes[$province];
+        } else {
+            return -1;
+        }
     };
 
     $api_function = function ($card_no, &$card_type, &$validate, &$region_no,&$status) use($type_checker, $validate_checker, $regin_checker)
@@ -586,4 +568,76 @@ function tencent_valid_phone($card_no)
         return [$validate,$card_type,$region_no,$status];
     }
     return [$validate,$card_type,-1,$status];
+}
+
+function valid_phone($card_no)
+{
+    $validate_checker = function ($status)
+    {
+        // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号
+        Log::record("status={$status}",Log::DEBUG);
+        if (in_array($status, [0,5])) {
+            return false;
+        } else {
+            return true;
+        }
+    };
+
+    $time_checker = function ($update_time)
+    {
+        //90 天以内数据有效
+        $delta = time() - intval($update_time);
+        return $delta < 360 * 86400 && $delta >= 0;
+    };
+
+    $pinfo_getter = function ($card_no) use ($validate_checker,$time_checker)
+    {
+        $mod_card = Model('card_info');
+        $info = $mod_card->getCardInfo($card_no);
+
+        if(empty($info)) {
+            return [false,[]];
+        }
+        elseif($time_checker($info['update_time'])) {
+            $mod_card->where(['card_no' => $card_no])->update(['using_times' => $info['using_times'] + 1]);
+
+            $card_type = intval($info['card_type']);
+            $region_no = intval($info['regin']);
+            $isTransfer = intval($info['transfer']) == 0 ? false : true;
+            $status = intval($info['card_state']);
+            $black = intval($info['black']);
+            $validate = $validate_checker($status);
+
+            $result = [$validate,$card_type,$region_no,$isTransfer,$status,$black];
+            return [true,$result];
+        }
+        else {
+            return [false,[]];
+        }
+    };
+
+    $pinfo_updator = function ($card_no,$card_type,$org_type,$region_no,$isTransfer,$status)
+    {
+        $mod_card = Model('card_info');
+        $transfer = $isTransfer == true ? 1 : 0;
+        $mod_card->replace_card($card_no,$card_type,$org_type,$region_no,$transfer,$status);
+    };
+
+    $validate = true;
+    $black = 0;
+
+    $card_type = card_type($card_no,$region_no);
+    $region_no = -1;
+
+    if($card_type == PetroChinaCard || $card_type == SinopecCard) {
+        return [$validate,$card_type,$region_no,false,1,$black];
+    }
+
+    [$succ,$result] = $pinfo_getter($card_no);
+    if($succ) return $result;
+
+
+
+//    if($succ) $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
+
 }

+ 4 - 2
test/TestCardNo.php

@@ -66,7 +66,9 @@ class TestCardNo extends TestCase
 
     public function testTencentValidPhone()
     {
-        $card_no = 17801048874;
-        [$validate,$card_type,$region_no,$status] = mtopcard\tencent_valid_phone($card_no);
+        $card_no = 13911129867;
+//        [$validate,$card_type,$region_no,$status] = mtopcard\tencent_valid_phone($card_no);
+        [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
+
     }
 }