You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Administrator
|
|
* Date: 2019/7/18 0018
|
|
* Time: 上午 2:30
|
|
*/
|
|
|
|
namespace app\extend;
|
|
|
|
|
|
class IdCardCheck
|
|
{
|
|
public function IdCheck($value)
|
|
{
|
|
if (strlen($value) != 18) {
|
|
return false;
|
|
}
|
|
$idcard_base = substr($value, 0, 17);
|
|
if ($this->idcard_verify_number($idcard_base) != strtoupper(substr($value, 17, 1))) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private function idcard_verify_number($value)
|
|
{
|
|
if (strlen($value) != 17) {
|
|
return false;
|
|
}
|
|
//加权因子
|
|
$factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
|
|
//校验码对应值
|
|
$verify_number_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
|
|
$checksum = 0;
|
|
for ($i = 0; $i < strlen($value); $i++) {
|
|
$checksum += substr($value, $i, 1) * $factor[$i];
|
|
}
|
|
$mod = $checksum % 11;
|
|
$verify_number = $verify_number_list[$mod];
|
|
return $verify_number;
|
|
}
|
|
|
|
} |