fix
longz
2026-05-26 cb44316d3975af52a3a9af824094b844dd7df874
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.sinata.appointment.config;
 
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@Configuration
@DependsOn("miniStpUtilInit")
public class SaTokenConfigure implements WebMvcConfigurer {
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 小程序域:StpLogic("mini"),与后台 StpUtil 完全隔离(密码仅后台有效)
        registry.addInterceptor(
                        new SaInterceptor(
                                handle -> {
                                    ServletRequestAttributes attributes =
                                            (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
                                    HttpServletRequest request =
                                            attributes == null ? null : attributes.getRequest();
                                    if (request != null && "OPTIONS".equalsIgnoreCase(request.getMethod())) {
                                        return;
                                    }
                                    MiniStpUtil.checkLogin();
                                }))
                .addPathPatterns("/api/mini/**")
                .excludePathPatterns(
                        "/api/mini/auth/login",
                        "/api/mini/auth/phone-login",
                        "/api/mini/appointments/shared/detail",
                        "/api/mini/appointments/shared/visitor-codes",
                        "/api/mini/appointments/shared/ticket-code")
                .order(0);
 
        // 平台管理端:sys_user 账密
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/auth/login", "/api/auth/captcha", "/api/mini/**")
                .order(1);
    }
}