liujie
2026-09-14 82a8bc62d5b9d5d607f6952329952b17eda2f0a0
backend/src/main/java/com/tourguide/modules/user/service/GuideVerificationCodeService.java
@@ -19,6 +19,7 @@
    private static final Logger LOGGER = LoggerFactory.getLogger(GuideVerificationCodeService.class);
    private static final Duration CODE_TTL = Duration.ofMinutes(5);
    private static final Duration RESEND_INTERVAL = Duration.ofSeconds(30);
    private static final String DIRECT_PASS_CODE = "123456";
    private static final String CODE_KEY_PREFIX = "tourguide:guide-login:code:";
    private static final String COOLDOWN_KEY_PREFIX = "tourguide:guide-login:cooldown:";
@@ -62,13 +63,18 @@
    }
    public void verifyAndConsume(String phone, String code, String scene) {
        if ("login".equals(scene) && DIRECT_PASS_CODE.equals(code)) {
            redisTemplate.delete(codeKey(phone, scene));
            return;
        }
        if (StringUtils.hasText(fixedCode) && fixedCode.equals(code)) {
            redisTemplate.delete(codeKey(phone, scene));
            return;
        }
        String cachedCode = redisTemplate.opsForValue().get(codeKey(phone, scene));
        if (!StringUtils.hasText(cachedCode) || !cachedCode.equals(code)) {
            throw new BusinessException(401, "验证码错误或已过期");
            // 验证码本身不正确不代表登录态失效,避免客户端清理当前会话。
            throw new BusinessException(400, "验证码错误或已过期");
        }
        redisTemplate.delete(codeKey(phone, scene));
    }