用户实名认证校验
This commit is contained in:
parent
f5484b5e25
commit
58eaf37bf6
@ -155,7 +155,6 @@ public class VerifyUtil {
|
|||||||
if (userInfo == null) {
|
if (userInfo == null) {
|
||||||
throw new EbikeException("用户不存在");
|
throw new EbikeException("用户不存在");
|
||||||
}
|
}
|
||||||
// 校验是否已进行验证
|
|
||||||
Integer realNameStatus = userInfo.getUserRealNameStatus();
|
Integer realNameStatus = userInfo.getUserRealNameStatus();
|
||||||
if (realNameStatus != null && realNameStatus.equals(RealNameAttestationStatus.CERTIFIED)) {
|
if (realNameStatus != null && realNameStatus.equals(RealNameAttestationStatus.CERTIFIED)) {
|
||||||
throw new EbikeException("用户已实名验证");
|
throw new EbikeException("用户已实名验证");
|
||||||
@ -175,29 +174,37 @@ public class VerifyUtil {
|
|||||||
ebikeRealNameVerifyDto.setTimestamp(encryptedTimestamp);
|
ebikeRealNameVerifyDto.setTimestamp(encryptedTimestamp);
|
||||||
ebikeRealNameVerifyDto.setSign(sign);
|
ebikeRealNameVerifyDto.setSign(sign);
|
||||||
ebikeRealNameVerifyDto.setKey(realNameVerifyConfig.getApiKey());
|
ebikeRealNameVerifyDto.setKey(realNameVerifyConfig.getApiKey());
|
||||||
|
// 2. 调用第三方实名验证
|
||||||
// 2. 验证用户实名
|
|
||||||
JsonNode result = httpPost("验证用户实名", REALNAME_VERIFY_URL, ebikeRealNameVerifyDto, null);
|
JsonNode result = httpPost("验证用户实名", REALNAME_VERIFY_URL, ebikeRealNameVerifyDto, null);
|
||||||
log.info("验证用户实名结果:{}", result);
|
log.info("验证用户实名结果: {}", result);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new EbikeException("验证用户实名失败");
|
throw new EbikeException("验证用户实名失败");
|
||||||
}
|
}
|
||||||
|
String code = result.has("code") ? result.get("code").asText() : "";
|
||||||
if (result.has("code") && "10000".equals(result.get("code").asText())) {
|
if (!"10000".equals(code)) {
|
||||||
// 3. 解密结果
|
String message = result.has("message") ? result.get("message").asText() : "未知错误";
|
||||||
String data = securityContext.decrypt(result.get("data").asText(), realNameVerifyConfig.getClientPrivateKey());
|
log.error("验证用户实名失败, code: {}, message: {}", code, message);
|
||||||
JsonNode jsonData = objectMapper.readTree(data);
|
throw new EbikeException("验证用户实名失败: " + message);
|
||||||
if (jsonData.has("result") && "1".equals(jsonData.get("result").asText())) {
|
|
||||||
// 4. 更新用户实名信息
|
|
||||||
updateRealNameInfo(userValidateDto, true);
|
|
||||||
log.info("验证用户实名成功");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 3. 解密并解析结果
|
||||||
|
String data = securityContext.decrypt(result.get("data").asText(), realNameVerifyConfig.getClientPrivateKey());
|
||||||
|
JsonNode jsonData = objectMapper.readTree(data);
|
||||||
|
|
||||||
|
if (jsonData.has("result") && "1".equals(jsonData.get("result").asText())) {
|
||||||
|
// 验证成功直接返回
|
||||||
|
updateRealNameInfo(userValidateDto, true);
|
||||||
|
log.info("验证用户实名成功");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// 验证失败
|
||||||
|
String failReason = jsonData.has("msg") ? jsonData.get("msg").asText() : "实名验证未通过";
|
||||||
|
log.warn("实名验证未通过,原因: {}", failReason);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 验证失败:更新为未认证
|
||||||
updateRealNameInfo(userValidateDto, false);
|
updateRealNameInfo(userValidateDto, false);
|
||||||
String errorCode = result.has("code") ? result.get("code").asText() : "未知错误";
|
|
||||||
String errorMessage = result.has("message") ? result.get("message").asText() : "验证失败";
|
|
||||||
log.error("验证用户实名失败,{} {}", errorCode, errorMessage);
|
|
||||||
throw new EbikeException("验证用户实名失败");
|
throw new EbikeException("验证用户实名失败");
|
||||||
|
|
||||||
} catch (EncryptFailureException e) {
|
} catch (EncryptFailureException e) {
|
||||||
throw new EbikeException("加密失败");
|
throw new EbikeException("加密失败");
|
||||||
} catch (SignFailureException e) {
|
} catch (SignFailureException e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user