package cn.pluss.platform.interceptor;

import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.util.Emoji;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;

/**
 * @author lyf
 */
public class EmojiInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        StringBuilder sb = new StringBuilder();
        String line;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        String body = sb.toString();
        boolean emoji = Emoji.containsEmoji(body);
        if (emoji) {
            throw new MsgException("请正确输入");//这里是我自己封装了一个异常,根据自己需要写自己的异常
        }
        return super.preHandle(request, response, handler);
    }


}
