update:
1. 修改用户实名逻辑
This commit is contained in:
@@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.http.util.HttpUtil;
|
||||
import org.springblade.core.tool.sensitive.SensitiveUtil;
|
||||
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.Map;
|
||||
@@ -13,38 +13,41 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
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";
|
||||
|
||||
public static RemoteVerifyResponse verifyRealName(String realName, String idCard, String mobile) {
|
||||
public static RemoteVerifyIDCardResponse verifyRealName(String realName, String idCard) {
|
||||
try {
|
||||
if (StringUtil.isAnyBlank(realName, idCard, mobile)) {
|
||||
if (StringUtil.isAnyBlank(realName, idCard)) {
|
||||
return buildErrorResponse("请求参数缺失");
|
||||
}
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("name", realName);
|
||||
body.put("mobile", mobile);
|
||||
body.put("idcard", idCard);
|
||||
String strJson = HttpUtil.post(URL, getHeaders(), body);
|
||||
String strJson = HttpUtil.get(IDCARD_URL, getHeaders(), body);
|
||||
if (StringUtil.isBlank(strJson)) {
|
||||
return buildErrorResponse("远程服务返回空响应");
|
||||
}
|
||||
RemoteVerifyResponse response = JSON.parseObject(strJson, RemoteVerifyResponse.class);
|
||||
RemoteVerifyIDCardResponse response = JSON.parseObject(strJson, RemoteVerifyIDCardResponse.class);
|
||||
if (response == null) {
|
||||
return buildErrorResponse("远程服务返回无效数据格式");
|
||||
}
|
||||
return response;
|
||||
} 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("服务调用失败,请稍后重试");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static RemoteVerifyResponse buildErrorResponse(String msg) {
|
||||
RemoteVerifyResponse resp = new RemoteVerifyResponse();
|
||||
resp.setCode("CLIENT_ERROR"); // 与业务 SUCCESS code 区分
|
||||
private static RemoteVerifyIDCardResponse buildErrorResponse(String msg) {
|
||||
RemoteVerifyIDCardResponse resp = new RemoteVerifyIDCardResponse();
|
||||
resp.setCode(500); // 与业务 SUCCESS code 区分
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public class MarketUserController {
|
||||
@ApiOperationSupport(order = 15)
|
||||
@Operation(summary = "提交实名认证")
|
||||
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")
|
||||
|
||||
@@ -11,9 +11,6 @@ public class VerifyRealNameRequest implements Serializable {
|
||||
@NotEmpty(message = "无效参数")
|
||||
private String name;
|
||||
|
||||
@NotEmpty(message = "无效参数")
|
||||
private String mobile;
|
||||
|
||||
@NotEmpty(message = "无效参数")
|
||||
private String idCard;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -93,11 +93,6 @@ public class MarketInfoEntity extends BaseEntity {
|
||||
*/
|
||||
@Schema(description = "实名身份证")
|
||||
private String idCard;
|
||||
/**
|
||||
* 实名手机
|
||||
*/
|
||||
@Schema(description = "实名手机")
|
||||
private String verifiedMobile;
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
|
||||
@@ -55,7 +55,7 @@ public interface IMarketInfoService extends BaseService<MarketInfoEntity> {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -34,15 +34,13 @@ import org.springblade.common.utils.CommonUtil;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
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.DigestUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
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.common.eums.RemoteVerifyCodeStatus;
|
||||
import org.springblade.modules.common.eums.RemoteVerifyResponseStatus;
|
||||
import org.springblade.modules.common.eums.IDCardVerifyStatus;
|
||||
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
|
||||
import org.springblade.modules.common.service.ICommonUserPointService;
|
||||
import org.springblade.modules.market.pojo.entity.*;
|
||||
@@ -137,7 +135,7 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
|
||||
|
||||
@Override
|
||||
@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) {
|
||||
throw new ServiceException("无效参数");
|
||||
}
|
||||
@@ -148,19 +146,18 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
|
||||
if (marketInfo.getVerified() == 1) {
|
||||
return true;
|
||||
}
|
||||
if (!CommonUtil.isValidChineseName(name) || !CommonUtil.isValidIdCard(idCard) || !CommonUtil.isValidMobile(mobile)) {
|
||||
if (!CommonUtil.isValidChineseName(name) || !CommonUtil.isValidIdCard(idCard)) {
|
||||
throw new ServiceException("无效姓名、身份证号、手机号");
|
||||
}
|
||||
RemoteVerifyResponse response = RemoteVerifyClient.verifyRealName(name, idCard, mobile);
|
||||
if (RemoteVerifyCodeStatus.SUCCESS.getCode().equals(response.getCode())) {
|
||||
RemoteVerifyResponse.VerifyInfo result = response.getResult();
|
||||
if (!Objects.isNull(result) && result.getRes().equals(RemoteVerifyResponseStatus.CONSISTENT.getCode())) {
|
||||
RemoteVerifyIDCardResponse response = RemoteVerifyClient.verifyRealName(name, idCard);
|
||||
if (response.getSuccess() && 200 == response.getCode()) {
|
||||
RemoteVerifyIDCardResponse.VerifyIDCardInfo data = response.getData();
|
||||
if (!Objects.isNull(data) && data.getResult().equals(IDCardVerifyStatus.CONSISTENT.getCode())) {
|
||||
marketInfo.setRealName(name);
|
||||
marketInfo.setIdCard(idCard);
|
||||
marketInfo.setVerifiedMobile(mobile);
|
||||
marketInfo.setGender(result.getSex());
|
||||
marketInfo.setBirthday(result.getBirthday());
|
||||
marketInfo.setAddress(result.getAddress());
|
||||
marketInfo.setGender(data.getSex());
|
||||
marketInfo.setBirthday(data.getBirthday());
|
||||
marketInfo.setAddress(data.getAddress());
|
||||
marketInfo.setVerifiedDate(DateUtil.now());
|
||||
marketInfo.setVerified(1);
|
||||
if (updateById(marketInfo)) {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.springblade.modules.resource.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum SmsCodeEnum {
|
||||
|
||||
|
||||
@@ -18,14 +21,6 @@ public enum SmsCodeEnum {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static SmsCodeEnum getByCode(String code) {
|
||||
for (SmsCodeEnum item : SmsCodeEnum.values()) {
|
||||
if (item.getCode().equals(code)) {
|
||||
|
||||
Reference in New Issue
Block a user