sugangqiang 2 år sedan
förälder
incheckning
ccd651f812
2 ändrade filer med 7 tillägg och 8 borttagningar
  1. 6 7
      app/common/api/IdCardApi.php
  2. 1 1
      app/enterprise/validate/TalentInfo.php

+ 6 - 7
app/common/api/IdCardApi.php

@@ -108,16 +108,15 @@ class IdCardApi {
         if (strlen($num) == 18) {
             $factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
             $tokens = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
-
             $checkSum = 0;
             for ($i = 0; $i < 17; $i++) {
-                $checkSum += intval($num{$i}) * $factor[$i];
+                $checkSum += intval($num[$i]) * $factor[$i];
             }
 
             $mod = $checkSum % 11;
             $token = $tokens[$mod];
 
-            $lastChar = strtoupper($num{17});
+            $lastChar = strtoupper($num[17]);
 
             if ($lastChar != $token) {
                 return false;
@@ -139,7 +138,7 @@ class IdCardApi {
             $sum = (ord($hongkong[1]) - 64) * 8;
             $index = 7;
             for ($j = 0; $j < 6; $j++) {
-                $sum += $hongkong[2]{$j} * $index;
+                $sum += $hongkong[2][$j] * $index;
                 $index--;
             }
             $get_num = $sum % 11;
@@ -158,15 +157,15 @@ class IdCardApi {
         if ($taiwan && count($taiwan) === 3) {//首位数字代表性别,男性为1、女性为2
             $area_code = array('A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 34, 'J' => 18, 'K' => 19, 'L' => 20, 'M' => 21, 'N' => 22, 'O' => 35, 'P' => 23, 'Q' => 24, 'R' => 25, 'S' => 26, 'T' => 27, 'U' => 28, 'V' => 29, 'W' => 32, 'X' => 30, 'Y' => 31, 'Z' => 33);
             $code = $area_code[$taiwan[1]];
-            $sum = $code{0} + $code{1} * 9;
+            $sum = $code[0] + $code[1] * 9;
             $index = 8;
             for ($k = 1; $k < 8; $k++) {
-                $sum += $taiwan[2]{$k} * $index;
+                $sum += $taiwan[2][$k] * $index;
                 $index--;
             }
 
             $get_num = $sum % 10;
-            if ($get_num === $taiwan[2]{8}) {
+            if ($get_num === $taiwan[2][8]) {
                 return true;
             }
             return false;

+ 1 - 1
app/enterprise/validate/TalentInfo.php

@@ -112,7 +112,7 @@ class TalentInfo extends Validate {
                     break;
             }
         }
-        return true;
+        return "身份证号码不合法";
     }
 
     protected function checkRangeDate($value, $rule, $data = []) {