From 5ca36383823e57e625403886784f50916b8dffbc Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Aug 2026 22:18:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BA=AB=E4=BB=BD=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E8=AF=81=E5=8F=B7=E7=A0=81=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- .../user-center-renderers/profile-auth.php | 2 +- src/AKSRT/Identity/ApplicationService.php | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/inc/helpers/user-center-renderers/profile-auth.php b/inc/helpers/user-center-renderers/profile-auth.php index 6bc7cdf7..2e99edb4 100644 --- a/inc/helpers/user-center-renderers/profile-auth.php +++ b/inc/helpers/user-center-renderers/profile-auth.php @@ -84,7 +84,7 @@ $config = [ - + diff --git a/src/AKSRT/Identity/ApplicationService.php b/src/AKSRT/Identity/ApplicationService.php index 6b42e775..4cca62a3 100644 --- a/src/AKSRT/Identity/ApplicationService.php +++ b/src/AKSRT/Identity/ApplicationService.php @@ -54,10 +54,10 @@ final class ApplicationService { } $person_name = sanitize_text_field((string) ($input['person_name'] ?? '')); - $id_number = preg_replace('/\s+/', '', sanitize_text_field((string) ($input['id_number'] ?? ''))) ?: ''; + $id_number = strtoupper(preg_replace('/\s+/', '', sanitize_text_field((string) ($input['id_number'] ?? ''))) ?: ''); $company_name = $type === 'enterprise' ? sanitize_text_field((string) ($input['company_name'] ?? '')) : ''; $company_code = $type === 'enterprise' ? (preg_replace('/\s+/', '', sanitize_text_field((string) ($input['company_code'] ?? ''))) ?: '') : ''; - if ($person_name === '' || $this->length($person_name) > 50 || $id_number === '' || $this->length($id_number) > 20) { + if ($person_name === '' || $this->length($person_name) > 50 || !$this->is_china_id_number($id_number)) { return new \WP_Error('aksrt_identity_person_fields', __('请填写有效的姓名和身份证号码', 'aksrt')); } if ($type === 'enterprise' && ($company_name === '' || $this->length($company_name) > 191 || $company_code === '' || $this->length($company_code) > 32)) { @@ -298,4 +298,20 @@ final class ApplicationService { private function truncate(string $value, int $length): string { return function_exists('mb_substr') ? mb_substr($value, 0, $length) : substr($value, 0, $length); } + + private function is_china_id_number(string $value): bool { + if (!preg_match('/^(\d{17}[0-9X]|\d{15})$/', $value)) { + return false; + } + if (strlen($value) === 15) { + return true; + } + $weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; + $codes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; + $sum = 0; + for ($i = 0; $i < 17; $i++) { + $sum += (int) $value[$i] * $weights[$i]; + } + return $codes[$sum % 11] === $value[17]; + } }