From b0c62bb2268824c26398a4e33baf95f5d08d8dd9 Mon Sep 17 00:00:00 2001 From: 18631081161 <2088094923@qq.com> Date: Thu, 29 Jan 2026 17:50:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniapp/pages/realname/index.vue | 18 ++++++++++--- .../RealName/AliyunRealNameProvider.cs | 27 +++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/miniapp/pages/realname/index.vue b/miniapp/pages/realname/index.vue index 32224ea..b145a04 100644 --- a/miniapp/pages/realname/index.vue +++ b/miniapp/pages/realname/index.vue @@ -463,11 +463,21 @@ const handleSubmitVerification = async () => { if (!canSubmit.value || submitting.value) return - // 简单校验身份证号格式 - const idCardRegex = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/ - if (!idCardRegex.test(idCardNumber.value)) { + // 检查身份证号长度 + const idCard = idCardNumber.value.trim() + if (idCard.length !== 18) { uni.showToast({ - title: '请输入正确的身份证号', + title: '身份证号必须是18位', + icon: 'none' + }) + return + } + + // 校验身份证号格式 + const idCardRegex = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/ + if (!idCardRegex.test(idCard)) { + uni.showToast({ + title: '身份证号格式不正确,请检查', icon: 'none' }) return diff --git a/server/src/XiangYi.Infrastructure/RealName/AliyunRealNameProvider.cs b/server/src/XiangYi.Infrastructure/RealName/AliyunRealNameProvider.cs index d0b0d58..68d3082 100644 --- a/server/src/XiangYi.Infrastructure/RealName/AliyunRealNameProvider.cs +++ b/server/src/XiangYi.Infrastructure/RealName/AliyunRealNameProvider.cs @@ -173,15 +173,32 @@ public class AliyunRealNameProvider : IRealNameProvider /// private static string GetErrorMessage(string? bizCode, string? message) { - return bizCode switch + // 先检查 bizCode + var bizCodeMsg = bizCode switch { "1" => "验证通过", - "2" => "姓名与身份证号不一致", - "3" => "身份证号不存在", - "4" => "身份证号格式错误", + "2" => "姓名与身份证号不一致,请核对后重新输入", + "3" => "身份证号不存在,请检查是否输入正确", + "4" => "身份证号格式错误,请输入18位有效身份证号", "5" => "服务异常,请稍后重试", - _ => message ?? "验证失败,请检查身份信息是否正确" + _ => null }; + + if (bizCodeMsg != null) + return bizCodeMsg; + + // 检查 message 中的特定错误 + if (!string.IsNullOrEmpty(message)) + { + if (message.Contains("identifyNum") || message.Contains("IdentifyNum")) + return "身份证号格式错误,请输入正确的18位身份证号"; + if (message.Contains("userName") || message.Contains("UserName")) + return "姓名格式错误,请输入正确的中文姓名"; + if (message.Contains("参数非法")) + return "输入信息格式错误,请检查姓名和身份证号是否正确"; + } + + return message ?? "验证失败,请检查身份信息是否正确"; } private static string MaskIdCard(string idCard)