zero před 1 rokem
rodič
revize
1843ee6b3d

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/business/redis/RedisService.java

@@ -2,11 +2,11 @@
 package com.example.xiaoshiweixinback.business.redis;
 
 
+import jakarta.annotation.Resource;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.support.atomic.RedisAtomicLong;
 import org.springframework.stereotype.Component;
 
-import javax.annotation.Resource;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;

+ 6 - 3
src/main/java/com/example/xiaoshiweixinback/controller/LoginController.java

@@ -12,6 +12,9 @@ import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * 登录相关接口
  *
@@ -61,13 +64,13 @@ public class LoginController {
     @PostMapping("/verifyCode")
     @Operation(summary = "生成校验码")
     public Response verifyCode(@RequestBody @Valid PersonPhoneDTO vo) throws Exception {
-        boolean b = true;
+        Map<String, String> map = new HashMap<>();
         try {
-            b = loginService.verifyCode(vo);
+            map = loginService.verifyCode(vo);
         } catch (Exception e) {
             return Response.success(e.getMessage());
         }
-        return Response.success(b);
+        return Response.success(map);
     }
 
     @PostMapping("/editPerson")

+ 7 - 2
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -4,6 +4,7 @@ package com.example.xiaoshiweixinback.service;
 import cn.hutool.captcha.CaptchaUtil;
 import cn.hutool.captcha.CircleCaptcha;
 import cn.hutool.core.img.ImgUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.crypto.SecureUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -94,6 +95,8 @@ public class LoginService {
         if (ToolUtil.isEmpty(person)) {
             person = new Person();
             person.setPhoneNum(dto.getPhoneNum());
+            String uid = IdUtil.simpleUUID();
+            person.setUuid(uid);
             personMapper.insert(person);
 
             loginVO.setId(person.getId());
@@ -170,6 +173,8 @@ public class LoginService {
                     person.setFileGuid(fileGuid);
                     person.setPhoneNum(phoneNumber);
                     person.setOpenId(jscode2SessionWo.getOpenid());
+                    String uid = IdUtil.simpleUUID();
+                    person.setUuid(uid);
                     person.insert();
 
                     wxVO.setIfFirst(true);
@@ -210,7 +215,7 @@ public class LoginService {
      * @return 1.生成验证码的base64转码 2.生成的UUID 与Redis里面的验证码KEY值一致
      * @date: 20240401
      */
-    public boolean verifyCode(PersonPhoneDTO vo) {
+    public Map<String, String> verifyCode(PersonPhoneDTO vo) {
         if (!RegexUtil.isPhoneLegal(vo.getPhoneNum())) {
             throw new BusinessException(ExceptionEnum.PHONE_FORMAT_ERROR);
         }
@@ -224,7 +229,7 @@ public class LoginService {
         result.put("uuid", uuid);
         //4.将验证码存放到Redis里面并设置过期时间为 60 单位:秒 KEY值格式为: 验证码:UUID  VALUE值为:验证码生成工具所生成的验证码
         redisUtil.setEx(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()), captcha.getCode(), 60, TimeUnit.SECONDS);
-        return true;
+        return result;
     }
 
     @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)

+ 16 - 0
src/test/java/com/example/xiaoshiweixinback/XiaoshiWeixinbackApplicationTests.java

@@ -1,13 +1,29 @@
 package com.example.xiaoshiweixinback;
 
+import com.example.xiaoshiweixinback.entity.dto.person.PersonPhoneDTO;
+import com.example.xiaoshiweixinback.service.LoginService;
 import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.util.Map;
+
 @SpringBootTest
 class XiaoshiWeixinbackApplicationTests {
 
+    @Autowired
+    private LoginService loginService;
+
     @Test
     void contextLoads() {
     }
 
+    @Test
+    public void test() {
+        PersonPhoneDTO dto = new PersonPhoneDTO();
+        dto.setPhoneNum("123456789");
+        Map<String, String> map = loginService.verifyCode(dto);
+        System.out.println(map);
+
+    }
 }