package com.bohuikeji.delivery.backstage.config;

import com.bohuikeji.delivery.backstage.lnterceptor.ApiLnterceptor;
import com.bohuikeji.delivery.backstage.lnterceptor.OpenApiLnterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.websocket.OnOpen;

/**
 * API接口拦截器
 * @author Admin
 */
@Configuration
public class ApiAdapterConfig implements WebMvcConfigurer {
    /**
     * 不拦截以下接口
     */
    public static String[] exclude = {
            "/api/courier/login/app",//派送员登陆接口
            "/api/courier/getVerCode",//获取验证码接口
            "/api/courier/login/register",//派送员注册接口
            "/api/sysconfig/get/key",//获取配置接口
            /*"/api/sys/courier/update",//获取更新接口*/
            "/api/sys/token",//获取token接口
            "/api/admin/user/login",//管理端登陆接口
            "/api/customer/getVerCode",//客户获取验证码
            "/api/customer/wxLogin",//客户微信登录接口
            "/api/aliPay/notify",//支付宝回调接口
            "/api/wxPay/newRefund",//微信退款回调接口
            "/api/v2/wxPay/wxnoty",//微信小程序支付回调接口
            "/api/sys/customer/update",//客户端App安卓热更新
            "/api/sys/customer/force/update",//客户端App 安卓强制更新
            "/api/sys/customer/ios/update",//客户端App IOS热更新
            "/api/sys/customer/force/ios/update",//客户端App IOS强制更新
            "/api/sys/update/courier",//客户端App热更新
            "/api/sys/force/update/courier",//客户端App强制更新
            "/api/v2/join/get/list",//招商轮播图
            "/api/v2/join/get/douyin/list",//招商轮播图抖音转有
            "/api/v2/join/add/info",//客户端App强制更新
            "/api/admin/upload/files",//不拦截图片上传接口
            "/api/v2/config/service/voucher/get",//不拦首页图片显示接口
            /*"/api/v2/customer/get/describe",//招商轮播图*/
            "/api/test/**",
            "/api/open/**",//不拦截开放平台接口
            "/api/courier/save/notice/**",//保险回调通知接口
            "/api/v2/share/**",//分享相关接口
            "/api/ad/**",//广告接口不拦截,
            "/api/callback/**",//第三方回调通知接口不拦截
            "/api/baidu/getSessionKey",//百度小程序code解析
            "/api/baidu/pay/notify",//百度小程序订单支付回调地址
            "/api/baidu/refund/notify",//百度小程序订单退款回调地址
            "/api/v2/customer/get/list",//获取满减卷
            "/api/v2/customer/login/receive",//客户注册领取优惠卷
            "/api/v2/byte/get/byte/sessionKey/login",//抖音小程序code解析
            "/api/v2/byte/pay/notify",//抖音小程序支付回调
            "/api/v2/byte/get/pay/settle",//订单分账记录查询
            "/api/v2/rental/save/car/info",
            "/api/v2/kuaishou/pay/notify",//快手小程序支付、退款回调
            "/api/v2/kuaishou/get/pay/settle",//快手小程序订单结算
            "/api/sys/app/update",//更新接口不拦截,
            "/api/jd/**",
            "/api/h5/**"
    };


    /**
     * 接口拦截器
     *
     * @return
     */
    @Bean
    ApiLnterceptor apiLnterceptor() {
        return new ApiLnterceptor();
    }

    /**
     * 开放平台接口拦截器
     * @return
     */
    @Bean
    OpenApiLnterceptor openApiLnterceptor(){return new OpenApiLnterceptor();}

    /**
     * 注册所以拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 拦截接口请求
         */
        InterceptorRegistration apiRegistry = registry.addInterceptor(apiLnterceptor()).addPathPatterns("/api/**");
        //不拦截设置
        apiRegistry.excludePathPatterns(exclude);
        /**
         * 开放平台接口拦截
         */
        InterceptorRegistration openApiRegistry = registry.addInterceptor(openApiLnterceptor()).addPathPatterns("/api/open/**");
        //不拦截获取token接口,不拦截海底捞的客如云接口
        openApiRegistry.excludePathPatterns("/api/open/auth/get/token","/api/open/kry/**");
    }
}
