用户实名认证

This commit is contained in:
yanglei 2026-01-09 10:26:53 +08:00
parent 4c2d731d51
commit 833689270d

View File

@ -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("加密失败");