| 12345678910111213141516171819202122232425 |
- package com.jyc.threegames.net;
- import android.text.TextUtils;
- import com.jyc.threegames.controller.LoginController;
- import java.io.IOException;
- import okhttp3.Interceptor;
- import okhttp3.Request;
- import okhttp3.Response;
- public class TokenInterceptor implements Interceptor {
- @Override
- public Response intercept(Chain chain) throws IOException {
- String token = LoginController.getInstance().getToken();
- if (TextUtils.isEmpty(token))
- return chain.proceed(chain.request());
- Request request = chain.request()
- .newBuilder()
- .addHeader("Authorization", "Bearer " + token)
- .build();
- return chain.proceed(request);
- }
- }
|