david 2 роки тому
батько
коміт
50a083c582

+ 26 - 5
src/main/java/com/roma/romaapi/controller/ApiController.java

@@ -2,8 +2,12 @@ package com.roma.romaapi.controller;
 
 
 import com.roma.romaapi.service.CaptchaService;
-import jakarta.servlet.http.HttpServletResponse;
+import com.roma.romaapi.utils.CustomResponse;
+import com.roma.romaapi.utils.UUIDUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -11,13 +15,20 @@ import org.springframework.web.bind.annotation.RestController;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 @RestController
 @CrossOrigin
 public class ApiController {
 
+    @Value("${server.servlet.session.timeout}")
+    private Integer timeout;
     @Autowired
     CaptchaService captchaService;
+    @Autowired
+    private UUIDUtil uuidUtil;
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
     // 获取验证码
     @RequestMapping("/login/verifyCode")
     public Map<String, Object> loginVerifyCode() throws IOException {
@@ -27,9 +38,19 @@ public class ApiController {
     // 登录系统
     @RequestMapping("/api/login")
     public Map login(){
-        System.out.print("aaa");
-        Map a = new HashMap();
-        a.put("aa", "dsadsa");
-        return  a;
+
+        Map ret = new HashMap();
+        String key = uuidUtil.getUUID32();
+        ret.put("token", key);
+        return CustomResponse.formatResponse(ret);
+//        //生成验证码对应的token  以token为key  验证码为value存在redis中
+//        ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
+//        valueOperations.set(key, key);
+//        //设置验证码过期时间
+//        redisTemplate.expire(key, timeout, TimeUnit.MINUTES);
+//        Map<String, Object> map = new HashMap<>();
+//        map.put("token", key);
+//        map.put("expire", timeout);
+
     }
 }

+ 1 - 1
src/main/resources/application.properties

@@ -1 +1 @@
-#服务
server.port=8081
server.servlet.session.timeout=600

#数据库
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://172.22.255.174:3306/lowcode?serverTimezone=UTC&tinyInt1isBit=false&transformedBitIsBoolean=false
spring.datasource.username = root
spring.datasource.password = mypass

#redis
spring.redis.database=0
spring.redis.password=
#spring.redis.password=name:password
spring.redis.port=6379
spring.redis.host=172.22.255.174
spring.redis.timeout=5000
spring.redis.lettuce.pool.max-active=3
spring.redis.lettuce.pool.min-idle=2
spring.redis.lettuce.pool.max-idle=3
spring.redis.lettuce.pool.max-wait=-1
#spring.redis.lettuce.shutdown-timeout=100
#spring.cache.redis.cache-null-values=false


+#服务
server.port=8081
server.servlet.session.timeout=600

#数据库
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://172.21.85.42:3306/lowcode?serverTimezone=UTC&tinyInt1isBit=false&transformedBitIsBoolean=false
spring.datasource.username = root
spring.datasource.password = mypass

#redis
spring.redis.database=0
spring.redis.password=
#spring.redis.password=name:password
spring.redis.port=6379
spring.redis.host=172.21.85.42
spring.redis.timeout=5000
spring.redis.lettuce.pool.max-active=3
spring.redis.lettuce.pool.min-idle=2
spring.redis.lettuce.pool.max-idle=3
spring.redis.lettuce.pool.max-wait=-1
#spring.redis.lettuce.shutdown-timeout=100
#spring.cache.redis.cache-null-values=false