修改实名认证校验
This commit is contained in:
@@ -34,8 +34,9 @@ public class ApiAccessLimitUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认 当月5次
|
* 默认 当月5次
|
||||||
* @param id 唯一值
|
*
|
||||||
* @param key 接口名称 sys:limit:接口名称
|
* @param id 唯一值
|
||||||
|
* @param key 接口名称 sys:limit:接口名称
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String id, String key) {
|
public static boolean isAccessAllowed(String id, String key) {
|
||||||
@@ -58,9 +59,10 @@ public class ApiAccessLimitUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认月 month/月/自然月
|
* 默认月 month/月/自然月
|
||||||
* @param id 唯一值
|
*
|
||||||
* @param key 接口名称 sys:limit:接口名称
|
* @param id 唯一值
|
||||||
* @param count 次数限制
|
* @param key 接口名称 sys:limit:接口名称
|
||||||
|
* @param count 次数限制
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String id, String key, Integer count) {
|
public static boolean isAccessAllowed(String id, String key, Integer count) {
|
||||||
@@ -82,9 +84,10 @@ public class ApiAccessLimitUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认 5次
|
* 默认 5次
|
||||||
|
*
|
||||||
* @param id 唯一值
|
* @param id 唯一值
|
||||||
* @param key 接口名称 sys:limit:接口名称
|
* @param key 接口名称 sys:limit:接口名称
|
||||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String id, String key, String timeFormat) {
|
public static boolean isAccessAllowed(String id, String key, String timeFormat) {
|
||||||
@@ -108,7 +111,7 @@ public class ApiAccessLimitUtil {
|
|||||||
* @param id 唯一值
|
* @param id 唯一值
|
||||||
* @param key 接口名称 sys:limit:接口名称
|
* @param key 接口名称 sys:limit:接口名称
|
||||||
* @param count 次数限制
|
* @param count 次数限制
|
||||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String id, String key, Integer count, String timeFormat) {
|
public static boolean isAccessAllowed(String id, String key, Integer count, String timeFormat) {
|
||||||
@@ -118,7 +121,7 @@ public class ApiAccessLimitUtil {
|
|||||||
long expireAt;
|
long expireAt;
|
||||||
if (StrUtil.isBlank(timeFormat)) {
|
if (StrUtil.isBlank(timeFormat)) {
|
||||||
expireAt = count;
|
expireAt = count;
|
||||||
}else {
|
} else {
|
||||||
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
||||||
expireAt = calculateExpireAt(timeFormat);
|
expireAt = calculateExpireAt(timeFormat);
|
||||||
}
|
}
|
||||||
@@ -133,14 +136,40 @@ public class ApiAccessLimitUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getCertAuthIsAccessAllowed(String id, String key, Integer count) {
|
||||||
|
String redisKey = generateRedisKey(key, id);
|
||||||
|
Object countObj = redisUtils.get(redisKey);
|
||||||
|
if (countObj == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return Integer.parseInt(countObj.toString()) < count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCertAuthIsAccessAllowed(String id, String key, Integer count, String timeFormat) {
|
||||||
|
String redisKey = generateRedisKey(key, id);
|
||||||
|
Object countObj = redisUtils.get(redisKey);
|
||||||
|
if (countObj == null) {
|
||||||
|
long expireAt;
|
||||||
|
if (StrUtil.isBlank(timeFormat)) {
|
||||||
|
expireAt = count;
|
||||||
|
} else {
|
||||||
|
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
||||||
|
expireAt = calculateExpireAt(timeFormat);
|
||||||
|
}
|
||||||
|
redisUtils.set(redisKey, 1, expireAt);
|
||||||
|
} else {
|
||||||
|
redisUtils.incr(redisKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void removeKey(String id, String key) {
|
public static void removeKey(String id, String key) {
|
||||||
String redisKey = generateRedisKey(key, id);
|
String redisKey = generateRedisKey(key, id);
|
||||||
redisUtils.delete(redisKey);
|
redisUtils.delete(redisKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static<T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey, Integer seconds) {
|
public static <T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey, Integer seconds) {
|
||||||
try{
|
try {
|
||||||
// 创建线程id, 用作判断
|
// 创建线程id, 用作判断
|
||||||
String clientId = UUID.randomUUID().toString();
|
String clientId = UUID.randomUUID().toString();
|
||||||
// 设置分布式锁
|
// 设置分布式锁
|
||||||
@@ -154,12 +183,12 @@ public class ApiAccessLimitUtil {
|
|||||||
lock = Boolean.TRUE.equals(redisUtils.setIfAbsent(lockKey, clientId, seconds));
|
lock = Boolean.TRUE.equals(redisUtils.setIfAbsent(lockKey, clientId, seconds));
|
||||||
}
|
}
|
||||||
return supplier.get();
|
return supplier.get();
|
||||||
} catch (RuntimeException e){
|
} catch (RuntimeException e) {
|
||||||
log.error("执行出错", e);
|
log.error("执行出错", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally{
|
} finally {
|
||||||
redisUtils.delete(lockKey);
|
redisUtils.delete(lockKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,7 +218,7 @@ public class ApiAccessLimitUtil {
|
|||||||
Date now = DateUtil.beginOfDay(DateUtil.date());
|
Date now = DateUtil.beginOfDay(DateUtil.date());
|
||||||
Date expireDate = null;
|
Date expireDate = null;
|
||||||
if ("day".equals(timePeriod)) {
|
if ("day".equals(timePeriod)) {
|
||||||
expireDate = DateUtil.endOfDay(now);
|
expireDate = DateUtil.endOfDay(now);
|
||||||
} else if ("week".equals(timePeriod)) {
|
} else if ("week".equals(timePeriod)) {
|
||||||
expireDate = DateUtil.endOfWeek(now);
|
expireDate = DateUtil.endOfWeek(now);
|
||||||
} else if ("month".equals(timePeriod)) {
|
} else if ("month".equals(timePeriod)) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.sqx.common.annotation.Debounce;
|
import com.sqx.common.annotation.Debounce;
|
||||||
import com.sqx.common.exception.SqxException;
|
|
||||||
import com.sqx.common.utils.ApiAccessLimitUtil;
|
import com.sqx.common.utils.ApiAccessLimitUtil;
|
||||||
import com.sqx.common.utils.DataLimitUtil;
|
import com.sqx.common.utils.DataLimitUtil;
|
||||||
import com.sqx.common.utils.Result;
|
import com.sqx.common.utils.Result;
|
||||||
@@ -33,6 +32,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* APP登录授权
|
* APP登录授权
|
||||||
|
* @author mac
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/app/user")
|
@RequestMapping("/app/user")
|
||||||
@@ -104,87 +104,75 @@ public class AppController {
|
|||||||
UserInfo userInfo = userInfoService.getByUserId(userId);
|
UserInfo userInfo = userInfoService.getByUserId(userId);
|
||||||
UserEntity userEntity = userService.getById(userId);
|
UserEntity userEntity = userService.getById(userId);
|
||||||
|
|
||||||
String errMsg = null;
|
|
||||||
if (StrUtil.isNotBlank(zhiFuBao) && (!zhiFuBao.equals(userEntity.getZhiFuBao())) || !certName.equals(userEntity.getZhiFuBaoName())) {
|
if (StrUtil.isNotBlank(zhiFuBao) && (!zhiFuBao.equals(userEntity.getZhiFuBao())) || !certName.equals(userEntity.getZhiFuBaoName())) {
|
||||||
int count = userService.count(new QueryWrapper<UserEntity>()
|
int count = userService.count(new QueryWrapper<UserEntity>()
|
||||||
.ne("user_id", userId)
|
.ne("user_id", userId)
|
||||||
.eq("zhi_fu_bao_name", certName)
|
.eq("zhi_fu_bao_name", certName)
|
||||||
.eq("zhi_fu_bao", zhiFuBao));
|
.eq("zhi_fu_bao", zhiFuBao));
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
errMsg = "支付宝信息修改失败: 一个支付宝账号仅可绑定一个用户";
|
return Result.error("支付宝信息修改失败: 此支付宝账号已被绑定");
|
||||||
}
|
}
|
||||||
if (errMsg == null && StrUtil.isNotBlank(userInfo.getCertName()) && !certName.equals(userInfo.getCertName())) {
|
if (StrUtil.isNotBlank(userInfo.getCertName()) && !certName.equals(userInfo.getCertName())) {
|
||||||
errMsg = "支付宝信息修改失败: 姓名与实名认证信息不相符";
|
return Result.error("支付宝信息修改失败: 姓名与实名认证信息不相符");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMsg == null && !DataLimitUtil.isAccessAllowed(zhiFuBao+certName, Integer.parseInt(commonRepository.findOne(924).getValue()), "month")) {
|
if (!DataLimitUtil.isAccessAllowed(zhiFuBao + certName, Integer.parseInt(commonRepository.findOne(924).getValue()), "month")) {
|
||||||
errMsg = "支付宝信息修改失败: 相同支付宝账号每月可绑定次数已用完";
|
return Result.error("支付宝信息修改失败: 相同支付宝账号每月可绑定次数已用完");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMsg == null && !ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", Integer.parseInt(commonRepository.findOne(925).getValue()), "month")) {
|
if (!ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", Integer.parseInt(commonRepository.findOne(925).getValue()), "month")) {
|
||||||
errMsg = "支付宝信息修改失败: 每月可修改次数已用完,请联系管理员";
|
return Result.error("支付宝信息修改失败: 每月可修改次数已用完,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMsg == null) {
|
userEntity.setZhiFuBao(zhiFuBao);
|
||||||
userEntity.setZhiFuBao(zhiFuBao);
|
userEntity.setZhiFuBaoName(certName);
|
||||||
userEntity.setZhiFuBaoName(certName);
|
userService.update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
|
||||||
userService.update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
|
}
|
||||||
}
|
|
||||||
|
if (StrUtil.isBlank(certNum)) {
|
||||||
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String authErrMsg = null;
|
if (!certNum.equals(userInfo.getCertNo()) || !certName.equals(userInfo.getCertName())) {
|
||||||
if (StrUtil.isNotBlank(certNum) && (!certNum.equals(userInfo.getCertNo()) || !certName.equals(userInfo.getCertName()))) {
|
|
||||||
if (StrUtil.isNotBlank(userEntity.getZhiFuBaoName()) && !certName.equals(userEntity.getZhiFuBaoName())) {
|
if (StrUtil.isNotBlank(userEntity.getZhiFuBaoName()) && !certName.equals(userEntity.getZhiFuBaoName())) {
|
||||||
authErrMsg = "实名修改失败: 姓名与绑定支付宝信息不相符";
|
return Result.error("实名修改失败: 姓名与绑定支付宝信息不相符");
|
||||||
}
|
}
|
||||||
if (authErrMsg == null && !IdcardUtil.isValidCard(certNum)) {
|
if (!IdcardUtil.isValidCard(certNum)) {
|
||||||
authErrMsg = "实名修改失败: 身份证号码有误";
|
return Result.error("实名修改失败: 身份证号码有误");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authErrMsg == null) {
|
Integer idCount = userInfoService.countCertCount(certName, certNum);
|
||||||
Integer idCount = userInfoService.countCertCount(certName, certNum);
|
if (idCount >= 1) {
|
||||||
if (idCount >= 1) {
|
return Result.error("实名修改失败: 此身份证信息已绑定过");
|
||||||
authErrMsg = "实名修改失败: 此实名信息已存在";
|
}
|
||||||
}
|
|
||||||
}
|
if (!ApiAccessLimitUtil.getCertAuthIsAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1)) {
|
||||||
|
return Result.error("实名修改失败: 每月可修改次数已用完,请联系管理员");
|
||||||
if (authErrMsg == null && !ApiAccessLimitUtil.isAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1, "month")) {
|
}
|
||||||
authErrMsg = "实名修改失败: 账号每月可修改次数已用完,请联系管理员";
|
|
||||||
}
|
if (!ApiAccessLimitUtil.getCertAuthIsAccessAllowed(certNum, "updateAuthCertInfoByIdCard", 1)) {
|
||||||
|
return Result.error("实名修改失败: 每月可修改次数已用完,请联系管理员");
|
||||||
if (authErrMsg == null && !ApiAccessLimitUtil.isAccessAllowed(certNum, "updateAuthCertInfoByIdCard", 1, "month")) {
|
}
|
||||||
authErrMsg = "实名修改失败: 此身份证信息次月已绑定过,请联系管理员";
|
|
||||||
}
|
try {
|
||||||
|
aliService.authCertNo(certName, certNum);
|
||||||
if (authErrMsg == null) {
|
userInfo.setCertName(certName);
|
||||||
try {
|
userInfo.setCertNo(certNum);
|
||||||
aliService.authCertNo(certName, certNum);
|
userInfo.setUpdateTime(DateUtil.date());
|
||||||
userInfo.setCertName(certName);
|
boolean update = userInfoService.update(userInfo, new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserId, userId).eq(UserInfo::getId, userInfo.getId()));
|
||||||
userInfo.setCertNo(certNum);
|
if (!update) {
|
||||||
userInfo.setUpdateTime(DateUtil.date());
|
return Result.error("实名修改失败: 请稍后重试");
|
||||||
boolean update = userInfoService.update(userInfo, new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserId, userId).eq(UserInfo::getId, userInfo.getId()));
|
|
||||||
if (!update) {
|
|
||||||
ApiAccessLimitUtil.removeKey(String.valueOf(userId), "updateAuthCertInfo");
|
|
||||||
ApiAccessLimitUtil.removeKey(certNum, "updateAuthCertInfoByIdCard");
|
|
||||||
}
|
|
||||||
}catch (Exception e) {
|
|
||||||
ApiAccessLimitUtil.removeKey(String.valueOf(userId), "updateAuthCertInfo");
|
|
||||||
ApiAccessLimitUtil.removeKey(certNum, "updateAuthCertInfoByIdCard");
|
|
||||||
authErrMsg = "实名修改失败: 身份证信息不匹配";
|
|
||||||
}
|
}
|
||||||
|
ApiAccessLimitUtil.setCertAuthIsAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1, "month");
|
||||||
|
ApiAccessLimitUtil.setCertAuthIsAccessAllowed(certNum, "updateAuthCertInfoByIdCard", 1, "month");
|
||||||
|
return Result.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("实名修改失败: 身份证信息不匹配");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMsg != null || authErrMsg != null) {
|
|
||||||
authErrMsg = authErrMsg == null ? "" : authErrMsg;
|
|
||||||
return Result.error(errMsg == null ? authErrMsg : errMsg + " " + authErrMsg);
|
|
||||||
}
|
|
||||||
return Result.success();
|
return Result.success();
|
||||||
// 去除首绑支付宝奖励
|
|
||||||
// if (bool && isFirstBind) {
|
|
||||||
// userService.firstBindAwardsMoney(old);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -198,22 +186,6 @@ public class AppController {
|
|||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*@Login
|
|
||||||
@RequestMapping(value = "/updateUsers", method = RequestMethod.POST)
|
|
||||||
@ApiOperation("用户修改个人信息")
|
|
||||||
@ResponseBody
|
|
||||||
public Result updateUsers(@RequestAttribute("userId") Long userId,String userName,String avatar,String phone) {
|
|
||||||
UserEntity userEntity=new UserEntity();
|
|
||||||
userEntity.setUserId(userId);
|
|
||||||
userEntity.setUserName(userName);
|
|
||||||
userEntity.setAvatar(avatar);
|
|
||||||
userEntity.setPhone(phone);
|
|
||||||
userService.updateById(userEntity);
|
|
||||||
return Result.success();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
@Login
|
@Login
|
||||||
@RequestMapping(value = "/updateUserImageUrl", method = RequestMethod.POST)
|
@RequestMapping(value = "/updateUserImageUrl", method = RequestMethod.POST)
|
||||||
@ApiOperation("用户修改头像")
|
@ApiOperation("用户修改头像")
|
||||||
|
|||||||
@@ -167,16 +167,6 @@ public class AppLoginController {
|
|||||||
return userService.sendMsg(phone, state,null);
|
return userService.sendMsg(phone, state,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Login
|
|
||||||
@Debounce(value = "#authCertNoDTO.idNum")
|
|
||||||
@PostMapping("/authCertNo")
|
|
||||||
public Result authCertNo(@RequestBody @Validated AuthCertNoDTO authCertNoDTO, @RequestAttribute("userId") long userId) {
|
|
||||||
if (!ApiAccessLimitUtil.isAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1, "month")) {
|
|
||||||
return Result.error("每月可修改次数已用完,请联系管理员");
|
|
||||||
}
|
|
||||||
return Result.success().put("data", userService.authCertNo(userId, authCertNoDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("解密手机号")
|
@ApiOperation("解密手机号")
|
||||||
@RequestMapping(value = "/selectPhone",method = RequestMethod.POST)
|
@RequestMapping(value = "/selectPhone",method = RequestMethod.POST)
|
||||||
public Result getPhoneNumberBeanS5(@RequestBody WxPhone wxPhone) {
|
public Result getPhoneNumberBeanS5(@RequestBody WxPhone wxPhone) {
|
||||||
|
|||||||
Reference in New Issue
Block a user