From e94411c6d8dc7be8702112fac1c2e14b6446e3a8 Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 25 Jan 2024 14:54:55 +0800 Subject: [PATCH] 1.add base64 image check code --- .../luoo/user/controller/LoginController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index d080ad0..5f9e3c3 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -1,7 +1,9 @@ package com.luoo.user.controller; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; +import java.util.Base64; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; @@ -165,6 +167,28 @@ public class LoginController extends BaseController { redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES); vCode.write(response.getOutputStream()); } + /** + * 4.1获取图行验证码Base64 + * @return + */ + @ApiOperation(value = "4.1获取图行验证码Base64", notes = "4.三次短信验证失败后,获取图形验证码Base64,有效期10分钟") + @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true) }) + @GetMapping("/imageCheckCodeBase64/{deviceId}") + @GlobalInterceptor + public Result imageCheckCodeBase64(HttpServletResponse response, + @VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException { + CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10); + response.setHeader("Pragma", "no-cache"); + response.setHeader("Cache-Control", "no-cache"); + response.setDateHeader("Expires", 0); + response.setContentType("image/jpeg"); + String code = vCode.getCode(); + String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId; + redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + vCode.write(bos); + return Result.success(Base64.getEncoder().encodeToString(bos.toByteArray())); + } /** * 获取支持的手机号国家码