Commit 79a6914f by lujunyi

身份证验证

parent 11c26861
......@@ -8,6 +8,7 @@
use App\Models\PharmacyModel;
use App\Models\User;
use Illuminate\Http\Request;
use Jxlwqq\IdValidator\IdValidator;
// 问诊人控制器
class PatientController extends BaseApiController
......@@ -57,7 +58,8 @@ public function add(Request $request)
$patient->pharmacy_id = $pharmacy->id;
}
// 验证身份证格式
if (! validateIdCard($data['id_card'])) {
$idValidator = new IdValidator();
if (! $idValidator->isValid($data['id_card'])) {
return $this->failed('身份证格式错误');
}
$mobile = $data['mobile'];
......@@ -87,10 +89,10 @@ public function update(Request $request)
$id = $request->input('id');
$id_card = $request->input('id_card');
// 验证身份证格式
if (! validateIdCard($id_card)) {
$idValidator = new IdValidator();
if (! $idValidator->isValid($id_card)) {
return $this->failed('身份证格式错误');
}
$idCardInfo = Util::getIdCardInfo($id_card);
$data = PatientModel::find($id);
if (! $data) {
......
......@@ -165,39 +165,7 @@ function data_masking(string $str, string $strType)
}
}
if (! function_exists('validateIdCard')) {
/**
* 身份证号码校验
*/
function validateIdCard($value)
{
$len = strlen($value);
if ($len != 15 && $len != 18) {
return false;
}
if ($len === 18) {
$birthday = substr($value, 6, 8); // 6-14 出生日期
if (! validateBirthday($birthday)) {
return false;
}
$sex = substr($value, -2, 1);
if (! validateISO7064($value)) {
return false;
}
return true;
} else {
$birthday = substr($value, 6, 6);
$birthday = '19'.$birthday;
if (! validateBirthday($birthday)) {
return false;
}
$sex = substr($value, -1);
return true;
}
}
if (! function_exists('validateBirthday')) {
function validateBirthday($birthday)
{
$year = substr($birthday, 0, 4);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment