lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.fuban.user.network;
 
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import cn.sinata.xldutils.utils.SPUtils;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class InterUtil {
    public static Interceptor get(){
        Interceptor interceptor = new Interceptor() {
            @NotNull
            @Override
            public Response intercept(@NotNull Chain chain) throws IOException {
                String token = SPUtils.Companion.instance().getString("token","");
                Request request = token.isEmpty()? chain.request():chain.request().newBuilder().addHeader("Authorization", "Bearer "+token).build();
                return chain.proceed(request);
            }
        };
        return interceptor;
    }
 
}