package base.net; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import base.utils.log.DLog; import com.jd.sentry.performance.network.instrumentation.okhttp3.ShooterOkhttp3Instrumentation; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class DaojiaNetUtils { public static final String NET_DESCRYT_FAIL_URL = "https://log-o2o.jddj.com/v1/logging"; private static OkHttpClient client; public static boolean isTest; private static DaojiaNetUtils netClient; private Handler mDelivery; public interface MyCallBack { void onFailure(int i); void onResponse(String str); } private DaojiaNetUtils() { client = initOkHttpClient(); } private OkHttpClient initOkHttpClient() { if (client == null) { client = ShooterOkhttp3Instrumentation.builderInit(new OkHttpClient.Builder()).readTimeout(10000, TimeUnit.MILLISECONDS).connectTimeout(10000, TimeUnit.MILLISECONDS).retryOnConnectionFailure(true).hostnameVerifier(new HostnameVerifier() { /* class base.net.DaojiaNetUtils.AnonymousClass1 */ public boolean verify(String str, SSLSession sSLSession) { return true; } }).build(); } return client; } public static DaojiaNetUtils getNetClient() { if (netClient == null) { netClient = new DaojiaNetUtils(); } return netClient; } private void init() { if (this.mDelivery == null) { this.mDelivery = new Handler(Looper.getMainLooper()); } } public void callNetPost(String str, HashMap<String, String> hashMap, final MyCallBack myCallBack) { FormBody.Builder builder = new FormBody.Builder(); for (Map.Entry<String, String> entry : hashMap.entrySet()) { try { if (!TextUtils.isEmpty(entry.getKey()) && !TextUtils.isEmpty(entry.getValue())) { builder.add(entry.getKey(), entry.getValue()); } } catch (Exception e) { e.printStackTrace(); } } Request build = new Request.Builder().url(str).post(builder.build()).build(); getNetClient(); Call newCall = ShooterOkhttp3Instrumentation.newCall(client, build); init(); newCall.enqueue(new Callback() { /* class base.net.DaojiaNetUtils.AnonymousClass2 */ @Override // okhttp3.Callback public void onFailure(Call call, IOException iOException) { DLog.e("DaojiaNetUtils", " onFailure " + iOException.toString()); DaojiaNetUtils.this.mDelivery.post(new Runnable() { /* class base.net.DaojiaNetUtils.AnonymousClass2.AnonymousClass1 */ public void run() { myCallBack.onFailure(-1); } }); } @Override // okhttp3.Callback public void onResponse(Call call, final Response response) { final String str; DLog.e("DaojiaNetUtils", " onResponse " + response.code()); try { str = response.body().string(); } catch (IOException e) { DLog.e("DaojiaNetUtils", " IOException222222 " + response.code()); e.printStackTrace(); str = null; } DaojiaNetUtils.this.mDelivery.post(new Runnable() { /* class base.net.DaojiaNetUtils.AnonymousClass2.AnonymousClass2 */ public void run() { if (response.code() == 200) { try { myCallBack.onResponse(str); } catch (Exception e) { DLog.e("DaojiaNetUtils", " IOException " + response.code()); myCallBack.onFailure(response.code()); e.printStackTrace(); } } else { myCallBack.onFailure(response.code()); } } }); } }); } public void callNetGet(String str, final MyCallBack myCallBack) { Request build = new Request.Builder().url(str).build(); getNetClient(); Call newCall = ShooterOkhttp3Instrumentation.newCall(client, build); init(); newCall.enqueue(new Callback() { /* class base.net.DaojiaNetUtils.AnonymousClass3 */ @Override // okhttp3.Callback public void onFailure(Call call, IOException iOException) { DLog.e("DaojiaNetUtils", " callNetGet onFailure " + iOException.toString()); DaojiaNetUtils.this.mDelivery.post(new Runnable() { /* class base.net.DaojiaNetUtils.AnonymousClass3.AnonymousClass1 */ public void run() { myCallBack.onFailure(-1); } }); } @Override // okhttp3.Callback public void onResponse(Call call, final Response response) { final String str; DLog.e("DaojiaNetUtils", " callNetGet onResponse " + response.code()); try { str = response.body().string(); } catch (IOException e) { e.printStackTrace(); DLog.e("DaojiaNetUtils", " IOException111111 " + response.code()); str = null; } DaojiaNetUtils.this.mDelivery.post(new Runnable() { /* class base.net.DaojiaNetUtils.AnonymousClass3.AnonymousClass2 */ public void run() { if (response.code() == 200) { try { myCallBack.onResponse(str); } catch (Exception unused) { DLog.e("DaojiaNetUtils", " IOException " + response.code()); myCallBack.onFailure(response.code()); } } else { myCallBack.onFailure(response.code()); } } }); } }); } }