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];
+ }
}