package hls.bwie.com.yuekaoer.http; import com.google.gson.Gson; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; /** * retrofit网络请求工具类 */ public class RetrofitUtils { //单例模式 private static RetrofitUtils retrofitUtils; private final Retrofit retrofit; public static RetrofitUtils getRetrofitUtils(){ if(retrofitUtils==null){ retrofitUtils = new RetrofitUtils(); } return retrofitUtils; } //初始化retrofit public RetrofitUtils(){ retrofit = new Retrofit.Builder() .baseUrl(HttpConfig.baseurl) .addConverterFactory(GsonConverterFactory.create(new Gson())) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); } public<T> T createService(Class<T>clz){ T t = retrofit.create(clz); return t; } }