用户实名认证
This commit is contained in:
parent
4c2d731d51
commit
833689270d
@ -23,7 +23,11 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -35,7 +39,11 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.time.LocalDateTime;
|
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
|
@Transactional
|
||||||
public void verifyRealName(UserValidateDto userValidateDto) {
|
public void verifyRealName(UserValidateDto userValidateDto) {
|
||||||
EbikeUserVo userInfo = ebikeUserService.getUserInfoByUserId(userValidateDto.getUserId());
|
EbikeUserVo userInfo = ebikeUserService.getUserInfoByUserId(userValidateDto.getUserId());
|
||||||
if (userInfo == null) {
|
if (Objects.isNull(userInfo)) {
|
||||||
throw new EbikeException("用户不存在");
|
throw new EbikeException("用户不存在");
|
||||||
}
|
}
|
||||||
Integer realNameStatus = userInfo.getUserRealNameStatus();
|
Integer realNameStatus = userInfo.getUserRealNameStatus();
|
||||||
@ -184,7 +192,7 @@ public class VerifyUtil {
|
|||||||
if (!"10000".equals(code)) {
|
if (!"10000".equals(code)) {
|
||||||
String message = result.has("message") ? result.get("message").asText() : "未知错误";
|
String message = result.has("message") ? result.get("message").asText() : "未知错误";
|
||||||
log.error("验证用户实名失败, code: {}, message: {}", code, message);
|
log.error("验证用户实名失败, code: {}, message: {}", code, message);
|
||||||
throw new EbikeException("验证用户实名失败");
|
throw new EbikeException(message);
|
||||||
}
|
}
|
||||||
// 3. 解密并解析结果
|
// 3. 解密并解析结果
|
||||||
String data = securityContext.decrypt(result.get("data").asText(), realNameVerifyConfig.getClientPrivateKey());
|
String data = securityContext.decrypt(result.get("data").asText(), realNameVerifyConfig.getClientPrivateKey());
|
||||||
@ -195,15 +203,12 @@ public class VerifyUtil {
|
|||||||
updateRealNameInfo(userValidateDto, true);
|
updateRealNameInfo(userValidateDto, true);
|
||||||
log.info("验证用户实名成功");
|
log.info("验证用户实名成功");
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
// 验证失败
|
|
||||||
String failReason = jsonData.has("msg") ? jsonData.get("msg").asText() : "实名验证未通过";
|
|
||||||
log.warn("实名验证未通过,原因: {}", failReason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 验证失败:更新为未认证
|
// 4. 验证失败:更新为未认证
|
||||||
|
String failReason = jsonData.has("msg") ? jsonData.get("msg").asText() : "实名验证未通过";
|
||||||
|
log.warn("实名验证未通过,原因: {}", failReason);
|
||||||
updateRealNameInfo(userValidateDto, false);
|
updateRealNameInfo(userValidateDto, false);
|
||||||
throw new EbikeException("验证用户实名失败");
|
throw new EbikeException(failReason);
|
||||||
|
|
||||||
} catch (EncryptFailureException e) {
|
} catch (EncryptFailureException e) {
|
||||||
throw new EbikeException("加密失败");
|
throw new EbikeException("加密失败");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user