1. 修改用户实名逻辑
This commit is contained in:
2026-04-14 17:13:37 +08:00
parent f144f42634
commit 75ae51b873
13 changed files with 83 additions and 116 deletions

View File

@@ -36,8 +36,6 @@ COMMENT ON COLUMN user_hierarchy.is_deleted IS '是否已删除';
-- 修改 user_market_info -- 修改 user_market_info
alter table public.user_market_info add verified_mobile varchar(50);
comment on column public.user_market_info.verified_mobile is '实名手机号码';
alter table public.user_market_info add gender varchar(10); alter table public.user_market_info add gender varchar(10);
comment on column public.user_market_info.gender is '性别'; comment on column public.user_market_info.gender is '性别';
alter table public.user_market_info add birthday varchar(10); alter table public.user_market_info add birthday varchar(10);

View File

@@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.http.util.HttpUtil; import org.springblade.core.http.util.HttpUtil;
import org.springblade.core.tool.sensitive.SensitiveUtil; import org.springblade.core.tool.sensitive.SensitiveUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.api.response.RemoteVerifyResponse; import org.springblade.modules.api.response.RemoteVerifyIDCardResponse;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -13,38 +13,41 @@ import java.util.Map;
@Slf4j @Slf4j
public class RemoteVerifyClient { public class RemoteVerifyClient {
private static final String URL = "https://mobile3elements.shumaidata.com/mobile/verify_real_name"; private static final String IDCARD_URL = "https://idcardv2.shumaidata.com/new-idcard";
private static final String BANKCARD_URL = "https://bankcard234.shumaidata.com/bankcard234";
private static final String BANKCARD_INFO_URL ="https://bankaddress.shumaidata.com/bankaddress";
private static final String APP_CODE = "650c376cec984b06a1289d30531c05a6"; private static final String APP_CODE = "650c376cec984b06a1289d30531c05a6";
public static RemoteVerifyResponse verifyRealName(String realName, String idCard, String mobile) { public static RemoteVerifyIDCardResponse verifyRealName(String realName, String idCard) {
try { try {
if (StringUtil.isAnyBlank(realName, idCard, mobile)) { if (StringUtil.isAnyBlank(realName, idCard)) {
return buildErrorResponse("请求参数缺失"); return buildErrorResponse("请求参数缺失");
} }
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("name", realName); body.put("name", realName);
body.put("mobile", mobile);
body.put("idcard", idCard); body.put("idcard", idCard);
String strJson = HttpUtil.post(URL, getHeaders(), body); String strJson = HttpUtil.get(IDCARD_URL, getHeaders(), body);
if (StringUtil.isBlank(strJson)) { if (StringUtil.isBlank(strJson)) {
return buildErrorResponse("远程服务返回空响应"); return buildErrorResponse("远程服务返回空响应");
} }
RemoteVerifyResponse response = JSON.parseObject(strJson, RemoteVerifyResponse.class); RemoteVerifyIDCardResponse response = JSON.parseObject(strJson, RemoteVerifyIDCardResponse.class);
if (response == null) { if (response == null) {
return buildErrorResponse("远程服务返回无效数据格式"); return buildErrorResponse("远程服务返回无效数据格式");
} }
return response; return response;
} catch (Exception e) { } catch (Exception e) {
log.error("实名认证调用异常 [name={}, mobile={}, idCard={}]", SensitiveUtil.process(realName), SensitiveUtil.process(mobile), SensitiveUtil.process(idCard), e); log.error("实名认证调用异常 [name={}, idCard={}]", SensitiveUtil.process(realName), SensitiveUtil.process(idCard), e);
return buildErrorResponse("服务调用失败,请稍后重试"); return buildErrorResponse("服务调用失败,请稍后重试");
} }
} }
private static RemoteVerifyResponse buildErrorResponse(String msg) { private static RemoteVerifyIDCardResponse buildErrorResponse(String msg) {
RemoteVerifyResponse resp = new RemoteVerifyResponse(); RemoteVerifyIDCardResponse resp = new RemoteVerifyIDCardResponse();
resp.setCode("CLIENT_ERROR"); // 与业务 SUCCESS code 区分 resp.setCode(500); // 与业务 SUCCESS code 区分
return resp; return resp;
} }

View File

@@ -155,7 +155,7 @@ public class MarketUserController {
@ApiOperationSupport(order = 15) @ApiOperationSupport(order = 15)
@Operation(summary = "提交实名认证") @Operation(summary = "提交实名认证")
public R verifyRealName(@RequestBody @Valid VerifyRealNameRequest request) { public R verifyRealName(@RequestBody @Valid VerifyRealNameRequest request) {
return R.status(marketInfoService.verifyRealName(AuthUtil.getUserId(),request.getName(), request.getMobile(), request.getIdCard())); return R.status(marketInfoService.verifyRealName(AuthUtil.getUserId(),request.getName(), request.getIdCard()));
} }
@GetMapping("/real-name-verification") @GetMapping("/real-name-verification")

View File

@@ -11,9 +11,6 @@ public class VerifyRealNameRequest implements Serializable {
@NotEmpty(message = "无效参数") @NotEmpty(message = "无效参数")
private String name; private String name;
@NotEmpty(message = "无效参数")
private String mobile;
@NotEmpty(message = "无效参数") @NotEmpty(message = "无效参数")
private String idCard; private String idCard;

View File

@@ -0,0 +1,36 @@
package org.springblade.modules.api.response;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class RemoteVerifyIDCardResponse implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Integer code;
private String msg;
private Boolean success;
private VerifyIDCardInfo data;
@Data
public static class VerifyIDCardInfo implements Serializable {
private Integer result;
private String desc;
private String sex;
private String birthday;
private String address;
}
}

View File

@@ -1,38 +0,0 @@
package org.springblade.modules.api.response;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class RemoteVerifyResponse implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String code;
private VerifyInfo result;
@Data
public static class VerifyInfo implements Serializable {
private String name;
private String mobile;
private String idcard;
private String res;
private String description;
private String sex;
private String birthday;
private String address;
}
}

View File

@@ -0,0 +1,17 @@
package org.springblade.modules.common.eums;
import lombok.Getter;
@Getter
public enum IDCardVerifyStatus {
//0 一致,1 不一致,2 无记录(预留)
CONSISTENT(0),
INCONSISTENT(1),
NO_RECORD(2);
private final Integer code;
IDCardVerifyStatus(Integer code) {
this.code = code;
}
}

View File

@@ -1,15 +0,0 @@
package org.springblade.modules.common.eums;
import lombok.Getter;
@Getter
public enum RemoteVerifyCodeStatus {
SUCCESS("0");
private final String code;
RemoteVerifyCodeStatus(String code) {
this.code = code;
}
}

View File

@@ -1,18 +0,0 @@
package org.springblade.modules.common.eums;
import lombok.Getter;
@Getter
public enum RemoteVerifyResponseStatus {
//1:一致 2:不一致 3:无记录 -1:异常
CONSISTENT("1"),
INCONSISTENT("2"),
NO_RECORD("3"),
EXCEPTION("-1");
private final String code;
RemoteVerifyResponseStatus(String code) {
this.code = code;
}
}

View File

@@ -93,11 +93,6 @@ public class MarketInfoEntity extends BaseEntity {
*/ */
@Schema(description = "实名身份证") @Schema(description = "实名身份证")
private String idCard; private String idCard;
/**
* 实名手机
*/
@Schema(description = "实名手机")
private String verifiedMobile;
/** /**
* 性别 * 性别
*/ */

View File

@@ -55,7 +55,7 @@ public interface IMarketInfoService extends BaseService<MarketInfoEntity> {
List<Long> selectAncestorIds(Long userId); List<Long> selectAncestorIds(Long userId);
boolean verifyRealName(Long userId, String name, String mobile, String idCard); boolean verifyRealName(Long userId, String name, String idCard);
boolean hasVerifyRealName(Long userId); boolean hasVerifyRealName(Long userId);

View File

@@ -34,15 +34,13 @@ import org.springblade.common.utils.CommonUtil;
import org.springblade.core.cache.utils.CacheUtil; import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.redis.ratelimiter.RateLimiter; import org.springblade.core.redis.ratelimiter.RateLimiter;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.DigestUtil; import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.modules.api.client.RemoteVerifyClient; import org.springblade.modules.api.client.RemoteVerifyClient;
import org.springblade.modules.api.response.RemoteVerifyResponse; import org.springblade.modules.api.response.RemoteVerifyIDCardResponse;
import org.springblade.modules.auth.provider.UserType; import org.springblade.modules.auth.provider.UserType;
import org.springblade.modules.common.eums.RemoteVerifyCodeStatus; import org.springblade.modules.common.eums.IDCardVerifyStatus;
import org.springblade.modules.common.eums.RemoteVerifyResponseStatus;
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity; import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
import org.springblade.modules.common.service.ICommonUserPointService; import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.market.pojo.entity.*; import org.springblade.modules.market.pojo.entity.*;
@@ -137,7 +135,7 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
@Override @Override
@RateLimiter(value = "verify:realName", param = "#userId", max = 3, ttl = 1, timeUnit = TimeUnit.DAYS) @RateLimiter(value = "verify:realName", param = "#userId", max = 3, ttl = 1, timeUnit = TimeUnit.DAYS)
public boolean verifyRealName(Long userId, String name, String mobile, String idCard) { public boolean verifyRealName(Long userId, String name, String idCard) {
if (userId == null) { if (userId == null) {
throw new ServiceException("无效参数"); throw new ServiceException("无效参数");
} }
@@ -148,19 +146,18 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
if (marketInfo.getVerified() == 1) { if (marketInfo.getVerified() == 1) {
return true; return true;
} }
if (!CommonUtil.isValidChineseName(name) || !CommonUtil.isValidIdCard(idCard) || !CommonUtil.isValidMobile(mobile)) { if (!CommonUtil.isValidChineseName(name) || !CommonUtil.isValidIdCard(idCard)) {
throw new ServiceException("无效姓名、身份证号、手机号"); throw new ServiceException("无效姓名、身份证号、手机号");
} }
RemoteVerifyResponse response = RemoteVerifyClient.verifyRealName(name, idCard, mobile); RemoteVerifyIDCardResponse response = RemoteVerifyClient.verifyRealName(name, idCard);
if (RemoteVerifyCodeStatus.SUCCESS.getCode().equals(response.getCode())) { if (response.getSuccess() && 200 == response.getCode()) {
RemoteVerifyResponse.VerifyInfo result = response.getResult(); RemoteVerifyIDCardResponse.VerifyIDCardInfo data = response.getData();
if (!Objects.isNull(result) && result.getRes().equals(RemoteVerifyResponseStatus.CONSISTENT.getCode())) { if (!Objects.isNull(data) && data.getResult().equals(IDCardVerifyStatus.CONSISTENT.getCode())) {
marketInfo.setRealName(name); marketInfo.setRealName(name);
marketInfo.setIdCard(idCard); marketInfo.setIdCard(idCard);
marketInfo.setVerifiedMobile(mobile); marketInfo.setGender(data.getSex());
marketInfo.setGender(result.getSex()); marketInfo.setBirthday(data.getBirthday());
marketInfo.setBirthday(result.getBirthday()); marketInfo.setAddress(data.getAddress());
marketInfo.setAddress(result.getAddress());
marketInfo.setVerifiedDate(DateUtil.now()); marketInfo.setVerifiedDate(DateUtil.now());
marketInfo.setVerified(1); marketInfo.setVerified(1);
if (updateById(marketInfo)) { if (updateById(marketInfo)) {

View File

@@ -1,5 +1,8 @@
package org.springblade.modules.resource.utils; package org.springblade.modules.resource.utils;
import lombok.Getter;
@Getter
public enum SmsCodeEnum { public enum SmsCodeEnum {
@@ -18,14 +21,6 @@ public enum SmsCodeEnum {
this.message = message; this.message = message;
} }
public String getCode() {
return code;
}
public String getMessage() {
return message;
}
public static SmsCodeEnum getByCode(String code) { public static SmsCodeEnum getByCode(String code) {
for (SmsCodeEnum item : SmsCodeEnum.values()) { for (SmsCodeEnum item : SmsCodeEnum.values()) {
if (item.getCode().equals(code)) { if (item.getCode().equals(code)) {