use of com.chao.cloud.common.extra.emoji.annotation.EmojiFilter in project chao-cloud by chaojunzi.
the class EmojiFilterProxy method around.
// 环绕拦截
@Around(value = "@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object around(ProceedingJoinPoint pdj) throws Throwable {
Method method = this.getMethod(pdj);
// 获取method 中的注解
EmojiFilter emojiFilter = method.getAnnotation(EmojiFilter.class);
// 获取参数
List<Object> args = Stream.of(pdj.getArgs()).filter(o -> !isInclude(o)).collect(Collectors.toList());
// 开始过滤
if ((emojiFilter == null || emojiFilter.value()) && !CollUtil.isEmpty(args)) {
// 参数json化
String jsonStr = JSONUtil.toJsonStr(args);
// 提取emoji
List<String> list = EmojiUtil.extractEmojis(jsonStr);
if (!CollUtil.isEmpty(list)) {
String emoji = list.stream().collect(Collectors.joining());
// 抛出异常
throw new BusinessException(StrUtil.format("[非法字符:emoji:->{}]", emoji));
}
}
return pdj.proceed();
}
Aggregations