puzhibing
2026-04-30 1ee6637e101e539b7e327c779087d81de9d8b129
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
package com.xiaopeng.map.config;
 
import com.xiaopeng.map.config.interceptor.SafeCheckForClientInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
import javax.annotation.Resource;
 
@Slf4j
@Configuration
public class MiniprogramConfigurer extends WebMvcConfigurerAdapter {
 
    @Resource
    @Lazy
    private SafeCheckForClientInterceptor safeCheckForClientInterceptor;
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        try {
            log.info("正在注册小程序拦截器...");
            // 使用安全的统一验证服务拦截器,避免 ClassCastException
            registry.addInterceptor(safeCheckForClientInterceptor)
                    .addPathPatterns("/base/v1/mini-program/**", "/api/v1/mini-program/**")
                    .excludePathPatterns("/base/v1/mini-program/fence/check"
                            , "/base/v1/mini-program/cities/list"
                            , "/base/v1/mini-program/point/getPointByIp");
            log.info("小程序拦截器注册成功");
        } catch (Exception e) {
            log.warn("小程序拦截器注册失败: {}", e.getMessage());
        }
    }
 
}