正在查看: 微商客 v2.1.2 应用的 HttpUtil.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 微商客 v2.1.2 应用的 HttpUtil.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.jianzhen.wsk.v1.http;
import android.text.TextUtils;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class HttpUtil {
public static final String URL = "https://www.usfriend.cn";
private static Retrofit mRetrofit;
public static <T> T create(Class<T> cls) {
return (T) create(cls, null);
}
public static <T> T create(Class<T> cls, String str) {
OkHttpClient build;
Retrofit retrofit = mRetrofit;
if (retrofit != null) {
return (T) retrofit.create(cls);
}
if (TextUtils.isEmpty(str)) {
build = new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).readTimeout(30L, TimeUnit.SECONDS).writeTimeout(30L, TimeUnit.SECONDS).connectTimeout(30L, TimeUnit.SECONDS).build();
} else {
build = new OkHttpClient.Builder().addInterceptor(new TokenInterceptor(str)).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).readTimeout(30L, TimeUnit.SECONDS).writeTimeout(30L, TimeUnit.SECONDS).connectTimeout(30L, TimeUnit.SECONDS).build();
}
Retrofit build2 = new Retrofit.Builder().baseUrl("https://www.usfriend.cn").client(build).addCallAdapterFactory(new HttpCallFactory()).addConverterFactory(GsonConverterFactory.create()).build();
mRetrofit = build2;
return (T) build2.create(cls);
}
}