release- 生成uuid时存入缓存,生成二维码时也校验是否有缓存

release-2024-08-08
pikaqiudeshujia 5 months ago
parent 4f6ec1b1eb
commit 877f8651b8

@ -400,6 +400,7 @@ public class LoginController extends BaseController {
@GetMapping(value = "/uuid") @GetMapping(value = "/uuid")
public Result<String> getUuid() { public Result<String> getUuid() {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
return Result.success(uuid); return Result.success(uuid);
} }
@ -419,11 +420,20 @@ public class LoginController extends BaseController {
response.setContentType("image/jpeg"); response.setContentType("image/jpeg");
try { try {
Object o = redisTemplate.opsForValue().get(uuid);
if (o == null) {
throw new BizException("二维码失效!");
}
if(!String.valueOf(o).equals("0")) {
throw new BizException("登录认证已完成");
}
response.setHeader("uuid", uuid); response.setHeader("uuid", uuid);
// 这里是开源工具类 hutool里的QrCodeUtil // 这里是开源工具类 hutool里的QrCodeUtil
// 网址http://hutool.mydoc.io/ // 网址http://hutool.mydoc.io/
QrCodeUtil.generate(uuid, 300, 300, "jpg",response.getOutputStream()); QrCodeUtil.generate(uuid, 300, 300, "jpg",response.getOutputStream());
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -715,7 +715,7 @@ public class UserInfoService {
if (o == null) { if (o == null) {
throw new BizException("二维码失效!"); throw new BizException("二维码失效!");
} }
if(!String.valueOf(0).equals("0")) { if(!String.valueOf(o).equals("0")) {
throw new BizException("登录认证已完成"); throw new BizException("登录认证已完成");
} }

Loading…
Cancel
Save