From 833689270d5d9831b6c91e4b117e76a7a588b3fcf15f38c2716ee841cdfe4f40 Mon Sep 17 00:00:00 2001 From: yanglei Date: Fri, 9 Jan 2026 10:26:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=AE=9E=E5=90=8D=E8=AE=A4?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cdzy/user/utils/VerifyUtil.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ebike-user/src/main/java/com/cdzy/user/utils/VerifyUtil.java b/ebike-user/src/main/java/com/cdzy/user/utils/VerifyUtil.java index 10aa2fd..144f69a 100644 --- a/ebike-user/src/main/java/com/cdzy/user/utils/VerifyUtil.java +++ b/ebike-user/src/main/java/com/cdzy/user/utils/VerifyUtil.java @@ -23,7 +23,11 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; -import okhttp3.*; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,7 +39,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.Security; import java.time.LocalDateTime; -import java.util.*; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.StringJoiner; /** * 验证工具类 @@ -152,7 +160,7 @@ public class VerifyUtil { @Transactional public void verifyRealName(UserValidateDto userValidateDto) { EbikeUserVo userInfo = ebikeUserService.getUserInfoByUserId(userValidateDto.getUserId()); - if (userInfo == null) { + if (Objects.isNull(userInfo)) { throw new EbikeException("用户不存在"); } Integer realNameStatus = userInfo.getUserRealNameStatus(); @@ -184,7 +192,7 @@ public class VerifyUtil { if (!"10000".equals(code)) { String message = result.has("message") ? result.get("message").asText() : "未知错误"; log.error("验证用户实名失败, code: {}, message: {}", code, message); - throw new EbikeException("验证用户实名失败"); + throw new EbikeException(message); } // 3. 解密并解析结果 String data = securityContext.decrypt(result.get("data").asText(), realNameVerifyConfig.getClientPrivateKey()); @@ -195,15 +203,12 @@ public class VerifyUtil { updateRealNameInfo(userValidateDto, true); log.info("验证用户实名成功"); return; - } else { - // 验证失败 - String failReason = jsonData.has("msg") ? jsonData.get("msg").asText() : "实名验证未通过"; - log.warn("实名验证未通过,原因: {}", failReason); } - // 4. 验证失败:更新为未认证 + String failReason = jsonData.has("msg") ? jsonData.get("msg").asText() : "实名验证未通过"; + log.warn("实名验证未通过,原因: {}", failReason); updateRealNameInfo(userValidateDto, false); - throw new EbikeException("验证用户实名失败"); + throw new EbikeException(failReason); } catch (EncryptFailureException e) { throw new EbikeException("加密失败");