package com.fdkankan.fusion.controller; import cn.hutool.captcha.CaptchaUtil; import cn.hutool.captcha.LineCaptcha; import com.fdkankan.fusion.common.ResultData; import com.fdkankan.fusion.common.util.RedisKeyUtil; import com.fdkankan.fusion.common.util.StringUtils; import com.fdkankan.fusion.response.UserAddRequest; import com.fdkankan.fusion.service.ITmUserService; import com.fdkankan.redis.util.RedisUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; @RestController @RequestMapping("/notAuth") @Slf4j public class NoLoginController { @Autowired RedisUtil redisUtil; @Autowired ITmUserService tmUserService; @GetMapping("/getLoginAuthCode") public void getLoginCode(HttpServletResponse response){ response.setHeader("Cache-Control", "no-store, no-cache"); response.setContentType("image/jpeg"); try { LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60); while (redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,lineCaptcha.getCode()))){ lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60); } redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,lineCaptcha.getCode()),lineCaptcha.getCode(),30); lineCaptcha.write(response.getOutputStream()); response.getOutputStream().close(); } catch (Exception e){ log.info("生成登录验证码错误:",e); } } @PostMapping("/changePassword") public ResultData changePassword(@RequestBody UserAddRequest param){ tmUserService.changePassword(param); return ResultData.ok(); } @GetMapping("/getMsgAuthCode") public ResultData getMsgAuthCode(@RequestParam(name = "phoneNum") String phoneNum) { return ResultData.ok( tmUserService.getMsgAuthCode(phoneNum)); } }