//需要的自提
public class RetrofitManager {
private static RetrofitManager mRetrofitManager;
private final Retrofit mRetrofit;
private static String BASE_URL = "https://www.zhaoapi.cn/";
public RetrofitManager(String baseUrl) {
mRetrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(bulidOkHttpClient())
.build();
}
public static RetrofitManager getDefault() {
return mRetrofitManager = new RetrofitManager(BASE_URL);
}
private OkHttpClient bulidOkHttpClient() {
//缓存路径
File cacheFile = new File(App.getContext().getCacheDir().getAbsolutePath(), "HttpCache");
Cache cache = new Cache(cacheFile, 1024 * 1024 * 10);//缓存文件为10MB
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
HashMap<String, String> map = new HashMap<>();
map.put("source", "android");
map.put("appVersion", "101");
PublicParamInterceptor paramInterceptor = new PublicParamInterceptor(map);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(5000, TimeUnit.MILLISECON