| | |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.sandu.common.security.annotation.AnonymousAccess; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | public class VerifyCodeController { |
| | | |
| | | private final Snowflake snowflake; |
| | | // private final RedisUtils redisUtils; |
| | | |
| | | |
| | | @AnonymousAccess |
| | | @RequestMapping("/getImg") |
| | | @ResponseBody |
| | | public Map getVerifiCode(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | |
| | | long key = snowflake.nextId(); |
| | | ImageVerificationCode ivc = new ImageVerificationCode(); //用我们的验证码类,生成验证码类对象 |
| | | BufferedImage image = ivc.getImage(); //获取验证码 |
| | | |
| | | // ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流 |
| | | // ImageIO.write(image, "JPEG", baos);//写入流中 |
| | | // byte[] bytes = baos.toByteArray();//转换成字节 |
| | | // BASE64Encoder encoder = new BASE64Encoder(); |
| | | // String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串 |
| | | // png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n |
| | | |
| | | // ImageIO.write(bufferedImage, "png", new File("D:/qrcode1.png")); |
| | | // System.out.println("值为:"+"data:image/jpg;base64,"+png_base64); |
| | | request.getSession().setAttribute(key+"", ivc.getText()); //将验证码的文本存在session中 |
| | | System.out.println(ivc.getText()+"----加密前的验证码"); |
| | | // System.out.println(MD5Util.md5(ivc.getText().toUpperCase())+"----加密后的验证码"); |
| | | RedisUtils.getBean().set(key+"",MD5Util.md5(ivc.getText().toUpperCase()),60); |
| | | // request.getSession().setAttribute(key+"", MD5Util.md5(ivc.getText().toUpperCase())); //将验证码的文本存在session中 |
| | | // ImageVerificationCode.output(image, response.getOutputStream());//将验证码图片响应给客户端 |
| | | String img = getBufferedImageToBase64(image, "JPEG"); |
| | | String session_vcode = (String) request.getSession().getAttribute(key+""); |
| | | // String session_vcode = (String) request.getSession().getAttribute(key+""); |
| | | |
| | | |
| | | Map map = new HashMap(); |
| | | // map.put("img", "data:image/jpg;base64,"+png_base64); |
| | | map.put("img", img); |
| | | map.put("vlue", session_vcode); |
| | | // map.put("vlue", session_vcode); |
| | | map.put("key", key); |
| | | return map; |
| | | } |
| | | |
| | | @AnonymousAccess |
| | | @RequestMapping("/Login_authentication/{key}") |
| | | @ResponseBody |
| | | public String Login_authentication(HttpServletRequest request, HttpServletResponse response,@PathVariable String key) throws IOException, ServletException { |
| | | request.setCharacterEncoding("utf-8"); |
| | | // String vcode = (String)map.get("session_vcode"); |
| | | // String vcode = (String)map.get("session_vcode"); r6mt |
| | | // if(vcode.isEmpty()||vcode==null){ |
| | | // return "验证码不能为空"; |
| | | // } |