验证码模块提交

This commit is contained in:
Chopper 2021-06-21 16:38:29 +08:00
parent 2db8eb7324
commit cdbaed22d9
4 changed files with 18 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package cn.lili.controller.common; package cn.lili.controller.common;
import cn.lili.common.aop.limiter.annotation.LimitPoint; import cn.lili.common.aop.limiter.annotation.LimitPoint;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException; import cn.lili.common.exception.ServiceException;
import cn.lili.common.enums.ResultUtil; import cn.lili.common.enums.ResultUtil;
import cn.lili.common.verification.enums.VerificationEnums; import cn.lili.common.verification.enums.VerificationEnums;
@ -37,8 +38,8 @@ public class SliderImageController {
} catch (ServiceException e) { } catch (ServiceException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
log.error("获取校验接口错误",e); log.error("获取校验接口错误", e);
return null; throw new ServiceException(ResultCode.VERIFICATION_EXIST);
} }
} }

View File

@ -5,10 +5,8 @@ import cn.lili.common.exception.ServiceException;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -18,7 +16,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method;
/** /**
* 流量拦截 * 流量拦截
@ -43,40 +40,34 @@ public class LimitInterceptor {
this.limitScript = limitScript; this.limitScript = limitScript;
} }
@Around("execution(public * *(..)) && @annotation(cn.lili.common.aop.limiter.annotation.LimitPoint)") @Before("@annotation(limitPointAnnotation)")
public Object interceptor(ProceedingJoinPoint pjp) throws Throwable { public void interceptor(LimitPoint limitPointAnnotation) {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Method method = signature.getMethod();
LimitPoint limitPointAnnotation = method.getAnnotation(LimitPoint.class);
LimitType limitType = limitPointAnnotation.limitType(); LimitType limitType = limitPointAnnotation.limitType();
String name = limitPointAnnotation.name(); String name = limitPointAnnotation.name();
String key; String key;
int limitPeriod = limitPointAnnotation.period(); int limitPeriod = limitPointAnnotation.period();
int limitCount = limitPointAnnotation.limit(); int limitCount = limitPointAnnotation.limit();
switch (limitType) { switch (limitType) {
case IP:
key = limitPointAnnotation.key() + getIpAddress();
break;
case CUSTOMER: case CUSTOMER:
key = limitPointAnnotation.key(); key = limitPointAnnotation.key();
break; break;
default: default:
key = StringUtils.upperCase(method.getName()); key = limitPointAnnotation.key() + getIpAddress();
} }
ImmutableList<String> keys = ImmutableList.of(StringUtils.join(limitPointAnnotation.prefix(), key)); ImmutableList<String> keys = ImmutableList.of(StringUtils.join(limitPointAnnotation.prefix(), key));
try { try {
Number count = redisTemplate.execute(limitScript, keys, limitCount, limitPeriod); Number count = redisTemplate.execute(limitScript, keys, limitCount, limitPeriod);
log.info("Access try count is {} for name={} and key = {}", count, name, key); log.info("限制请求{}, 当前请求{},缓存key{}", limitCount, count.intValue(), key);
//如果缓存里没有值或者他的值小于限制频率 //如果缓存里没有值或者他的值小于限制频率
if (count.intValue() <= limitCount) { if (count.intValue() >= limitCount) {
return pjp.proceed();
} else {
throw new ServiceException("访问过于频繁,请稍后再试"); throw new ServiceException("访问过于频繁,请稍后再试");
} }
} }
//如果从redis中执行都值判定为空则这里跳过 //如果从redis中执行都值判定为空则这里跳过
catch (NullPointerException e) { catch (NullPointerException e) {
return pjp.proceed(); return;
} catch (ServiceException e) {
throw e;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("服务器异常,请稍后再试"); throw new RuntimeException("服务器异常,请稍后再试");
} }

View File

@ -34,6 +34,7 @@ public enum ResultCode {
*/ */
WECHAT_CONNECT_NOT_EXIST(1001, "微信联合登录未配置"), WECHAT_CONNECT_NOT_EXIST(1001, "微信联合登录未配置"),
VERIFICATION_EXIST(1002, "验证码服务异常"),
/** /**
* 分类 * 分类
*/ */
@ -56,6 +57,7 @@ public enum ResultCode {
GOODS_UPPER_ERROR(11004, "商品上架失败"), GOODS_UPPER_ERROR(11004, "商品上架失败"),
GOODS_AUTH_ERROR(11005, "商品审核失败"), GOODS_AUTH_ERROR(11005, "商品审核失败"),
POINT_GOODS_ERROR(11006, "积分商品业务异常,请稍后重试"), POINT_GOODS_ERROR(11006, "积分商品业务异常,请稍后重试"),
GOODS_SKU_ERROR(11007, "SKU信息均为必填项不能为空"),
/** /**
* 参数 * 参数

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.lili.common.cache.Cache; import cn.lili.common.cache.Cache;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException; import cn.lili.common.exception.ServiceException;
import cn.lili.common.rocketmq.RocketmqSendCallbackBuilder; import cn.lili.common.rocketmq.RocketmqSendCallbackBuilder;
import cn.lili.common.rocketmq.tags.GoodsTagsEnum; import cn.lili.common.rocketmq.tags.GoodsTagsEnum;
@ -603,6 +604,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
for (Map.Entry<String, Object> m : map.entrySet()) { for (Map.Entry<String, Object> m : map.entrySet()) {
//保存规格信息 //保存规格信息
if (m.getKey().equals("id") || m.getKey().equals("sn") || m.getKey().equals("cost") || m.getKey().equals("price") || m.getKey().equals("quantity") || m.getKey().equals("weight")) { if (m.getKey().equals("id") || m.getKey().equals("sn") || m.getKey().equals("cost") || m.getKey().equals("price") || m.getKey().equals("quantity") || m.getKey().equals("weight")) {
if (null == m.getValue()) {
throw new ServiceException(ResultCode.GOODS_SKU_ERROR);
}
continue; continue;
} else { } else {
specMap.put(m.getKey(), m.getValue()); specMap.put(m.getKey(), m.getValue());