package com.mob.secverify.pure.a.a.a.d; import a.f; import android.content.Context; import android.net.Network; import android.text.TextUtils; import com.meizu.cloud.pushsdk.constants.PushConstants; import com.mob.MobSDK; import com.mob.secverify.e.j; import com.mob.secverify.pure.a.a.a.a.d; import com.mob.secverify.pure.a.a.c.c.e; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.EOFException; import java.io.InputStreamReader; import java.lang.Thread; import java.net.HttpURLConnection; import java.net.URL; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLHandshakeException; import org.json.JSONException; import org.json.JSONObject; /* compiled from: NetworkUtil */ public class b { /* renamed from: a reason: collision with root package name */ private String f6610a; private String b = ""; /* renamed from: c reason: collision with root package name */ private int f6611c = 1; private Context d; private String e; private com.mob.secverify.b.a f; /* compiled from: NetworkUtil */ public interface a { void a(String str, String str2); void a(String str, String str2, String str3); } public b(Context context, com.mob.secverify.b.a aVar) { this.d = context.getApplicationContext(); this.f = aVar; } private static void a(HttpsURLConnection httpsURLConnection, String str, d dVar) { com.mob.secverify.b.b.a().b("[SecPure] ==>%s", "Switch to HttpsURLConnection"); if (!dVar.d && !str.contains("https://config.cmpassport.com/client/uniConfig")) { httpsURLConnection.setSSLSocketFactory(new a(dVar).a().getSocketFactory()); } } public void a(final String str, final String str2, final boolean z, final a aVar, final String str3, final d dVar) { this.f6610a = dVar.D; com.mob.secverify.b.b a5 = com.mob.secverify.b.b.a(); StringBuilder h12 = f.h("traceId: "); h12.append(this.f6610a); a5.b("[SecPure] ==>%s", h12.toString()); AnonymousClass1 r92 = new Thread() { /* class com.mob.secverify.pure.a.a.a.d.b.AnonymousClass1 */ public void run() { com.mob.secverify.b.b a5 = com.mob.secverify.b.b.a(); StringBuilder h12 = f.h("forceWap: "); h12.append(z); a5.b("[SecPure] ==>%s", h12.toString()); if (!z) { b.this.a((b) str, str2, (String) aVar, (a) null, (Network) str3, (String) dVar); } else if ("WIFI".equals(e.b(MobSDK.getContext()))) { b.this.a(str, str2, aVar, str3, dVar); } else { b.this.a((b) str, str2, (String) aVar, (a) null, (Network) str3, (String) dVar); } } }; r92.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { /* class com.mob.secverify.pure.a.a.a.d.b.AnonymousClass2 */ public void uncaughtException(Thread thread, Throwable th2) { b.this.b = com.mob.secverify.pure.a.a.a.e.d.a(); com.mob.secverify.b.b.a().a(th2); aVar.a(String.valueOf(102003), j.a("network_exception", "network exception"), b.this.b); } }); int i = p4.f.b; r92.setName(p4.f.a(r92.getName(), "com.mob.secverify.pure.a.a.a.d.b")); r92.start(); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ /* JADX WARNING: Removed duplicated region for block: B:69:0x01b3 A[Catch:{ all -> 0x022c, all -> 0x0234 }] */ /* JADX WARNING: Removed duplicated region for block: B:70:0x01d4 A[Catch:{ all -> 0x022c, all -> 0x0234 }] */ /* JADX WARNING: Removed duplicated region for block: B:75:0x020f */ /* JADX WARNING: Removed duplicated region for block: B:78:0x0217 */ /* JADX WARNING: Removed duplicated region for block: B:93:? A[RETURN, SYNTHETIC] */ private void a(String str, String str2, a aVar, Network network, String str3, d dVar) { DataOutputStream dataOutputStream; BufferedReader bufferedReader; d dVar2; String str4; Throwable th2; HttpURLConnection httpURLConnection; com.mob.secverify.b.a aVar2; try { com.mob.secverify.b.b a5 = com.mob.secverify.b.b.a(); a5.b("[SecPure] ==>%s", "http request, url: " + str + " values: " + str2); URL url = new URL(str); if (network != null) { httpURLConnection = (HttpURLConnection) network.openConnection(url); } else { httpURLConnection = (HttpURLConnection) url.openConnection(); } if (str.startsWith("https")) { a((HttpsURLConnection) httpURLConnection, str, dVar); } httpURLConnection.setConnectTimeout(15000); httpURLConnection.setReadTimeout(19000); httpURLConnection.addRequestProperty("traceId", this.f6610a); httpURLConnection.addRequestProperty("appid", dVar.H); httpURLConnection.addRequestProperty("interfaceVersion", "7.0"); httpURLConnection.addRequestProperty("sdkVersion", "quick_login_android_5.7.2"); httpURLConnection.setUseCaches(false); httpURLConnection.setRequestProperty("Content-Type", "application/json"); if (str.contains("preGetMobile")) { httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } if (str.contains("getPrePhonescrip")) { httpURLConnection.setRequestProperty("defendEOF", "1"); } httpURLConnection.setRequestProperty("Charset", "UTF-8"); httpURLConnection.setDoInput(true); httpURLConnection.setInstanceFollowRedirects(false); if (str3.equals("POST")) { httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); DataOutputStream dataOutputStream2 = new DataOutputStream(httpURLConnection.getOutputStream()); try { byte[] bytes = str2.getBytes("UTF-8"); dataOutputStream2.write(bytes, 0, bytes.length); dataOutputStream2.flush(); dataOutputStream2.close(); dataOutputStream = dataOutputStream2; } catch (Throwable th3) { th2 = th3; dataOutputStream = dataOutputStream2; str4 = "[SecPure] ==>%s"; dVar2 = dVar; bufferedReader = null; try { com.mob.secverify.pure.a.a.a.c.a.b.add(th2); if (th2 instanceof SSLHandshakeException) { } if (dataOutputStream != null) { } if (bufferedReader != null) { } } catch (Throwable th4) { com.mob.secverify.pure.a.a.a.c.a.b.add(th4); com.mob.secverify.b.b.a().a(th4, str4, th4.getMessage()); throw th; } } } else { if (str3.equals("GET")) { httpURLConnection.setRequestMethod("GET"); } dataOutputStream = null; } try { int responseCode = httpURLConnection.getResponseCode(); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream())); try { StringBuffer stringBuffer = new StringBuffer(""); while (true) { String readLine = bufferedReader2.readLine(); if (readLine == null) { break; } stringBuffer.append(new String(readLine.getBytes(), "utf-8")); } String stringBuffer2 = stringBuffer.toString(); if (dataOutputStream != null) { try { dataOutputStream.close(); } catch (Throwable th5) { com.mob.secverify.pure.a.a.a.c.a.b.add(th5); com.mob.secverify.b.b.a().a(th5, "[SecPure] ==>%s", th5.getMessage()); } } bufferedReader2.close(); com.mob.secverify.b.b a12 = com.mob.secverify.b.b.a(); a12.b("[SecPure] ==>%s", "http response: " + stringBuffer2 + ",responseCode: " + responseCode); if (str.contains("getPrePhonescrip")) { com.mob.secverify.b.a aVar3 = this.f; if (aVar3 != null) { aVar3.a("cm_preRequest"); } } else if (str.contains("getAuthToken") && (aVar2 = this.f) != null) { aVar2.a("cm_tokenRequest"); } bufferedReader = bufferedReader2; str4 = "[SecPure] ==>%s"; dVar2 = dVar; try { a(stringBuffer2, responseCode, aVar, httpURLConnection, network, str2, str, str3, dVar); if (dataOutputStream != null) { try { dataOutputStream.close(); } catch (Throwable th6) { com.mob.secverify.pure.a.a.a.c.a.b.add(th6); com.mob.secverify.b.b.a().a(th6, str4, th6.getMessage()); return; } } bufferedReader.close(); } catch (Throwable th7) { th2 = th7; com.mob.secverify.pure.a.a.a.c.a.b.add(th2); if (th2 instanceof SSLHandshakeException) { } if (dataOutputStream != null) { } if (bufferedReader != null) { } } } catch (Throwable th8) { th2 = th8; bufferedReader = bufferedReader2; str4 = "[SecPure] ==>%s"; dVar2 = dVar; com.mob.secverify.pure.a.a.a.c.a.b.add(th2); if (th2 instanceof SSLHandshakeException) { } if (dataOutputStream != null) { } if (bufferedReader != null) { } } } catch (Throwable th9) { th2 = th9; str4 = "[SecPure] ==>%s"; dVar2 = dVar; bufferedReader = null; com.mob.secverify.pure.a.a.a.c.a.b.add(th2); if (th2 instanceof SSLHandshakeException) { } if (dataOutputStream != null) { } if (bufferedReader != null) { } } } catch (Throwable th10) { th2 = th10; str4 = "[SecPure] ==>%s"; dVar2 = dVar; bufferedReader = null; dataOutputStream = null; com.mob.secverify.pure.a.a.a.c.a.b.add(th2); if (th2 instanceof SSLHandshakeException) { dVar2.w = true; a(null, Integer.valueOf("200072").intValue(), aVar, null, network, str2, str, str3, dVar); } else if (th2 instanceof EOFException) { a(null, Integer.valueOf("200050").intValue(), aVar, null, network, str2, str, str3, dVar); } else { a(j.a(th2), -1, aVar, null, network, str2, str, str3, dVar); } if (dataOutputStream != null) { dataOutputStream.close(); } if (bufferedReader != null) { bufferedReader.close(); } } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(String str, String str2, a aVar, String str3, d dVar) { try { com.mob.secverify.b.a aVar2 = this.f; if (aVar2 != null) { aVar2.a("cm_switch_s"); } Network a5 = com.mob.secverify.pure.c.e.a(this.d).a(str); com.mob.secverify.b.a aVar3 = this.f; if (aVar3 != null) { aVar3.a("cm_switch_e"); } this.b = com.mob.secverify.pure.a.a.a.e.d.a(); a(str, str2, aVar, a5, str3, dVar); } catch (Throwable th2) { aVar.a(String.valueOf(102004), j.a(th2), this.b); } } /* JADX WARNING: Code restructure failed: missing block: B:52:0x0208, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:53:0x0209, code lost: r17 = "200028"; */ /* JADX WARNING: Code restructure failed: missing block: B:67:0x02ad, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:68:0x02ae, code lost: com.mob.secverify.b.b.a().a(r0, "[SecPure] ==>%s", "Network error"); com.mob.secverify.pure.a.a.a.c.a.b.add(r0); r21.a(r17, com.mob.secverify.e.j.a(r0), r18.b); */ /* JADX WARNING: Code restructure failed: missing block: B:69:?, code lost: return; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [B:6:0x0031, B:49:0x01ef] */ private void a(String str, int i, a aVar, HttpURLConnection httpURLConnection, Network network, String str2, String str3, String str4, d dVar) { String str5; String str6; JSONException e6; String str7 = str; if (i == 302 || i == 301) { dVar.f6567a = dVar.f6567a + i + ";"; String headerField = httpURLConnection.getHeaderField("Location"); com.mob.secverify.b.b.a().b("[SecPure] ==>%s", "Location head =" + headerField); if (this.e == null) { this.e = httpURLConnection.getHeaderField("pplocation"); } if (TextUtils.isEmpty(headerField) || this.e == null) { aVar.a("200021", j.a("data_parser_exception", "data parser exception"), this.b); return; } String str8 = dVar.b; if (PushConstants.PUSH_TYPE_UPLOAD_LOG.equals(dVar.f6568c)) { dVar.b = str8 + "getUnicomMobile;"; } else { dVar.b = str8 + "getTelecomMobile;"; } a(headerField, "", aVar, network, "POST", dVar); } else if (i != 200) { com.mob.secverify.b.b.a().b("[SecPure] ==>%s", "http response code is not 200 ---" + i); int i3 = this.f6611c + 1; this.f6611c = i3; if (i3 <= 3 && str3.contains("logReport")) { a(str3, str2, aVar, network, str4, dVar); } else if (i == 0) { aVar.a(i + "", j.a("request_error", "request error"), this.b); } else if (i == 200050) { aVar.a("200050", "EOF exception", this.b); } else if (i == 200072) { aVar.a("200072", j.a("verify_ca_root_certificate_failed", "verify ca root certificate failed"), this.b); } else if (i == 102507) { aVar.a(i + "", str7, this.b); } else { if (TextUtils.isEmpty(str)) { str7 = "network exception "; } aVar.a("200028", str7, this.b); } } else if (!TextUtils.isEmpty(this.e)) { try { com.mob.secverify.b.b.a().b("[SecPure] ==>%s", "other operator login result = " + str7); JSONObject jSONObject = new JSONObject(str7); String optString = jSONObject.optString("result", "0"); str5 = "200028"; try { dVar.f6567a = dVar.f6567a + optString + ";"; if (TextUtils.isEmpty(jSONObject.getString("result")) || !"0".equals(jSONObject.getString("result"))) { str6 = "200039"; try { aVar.a(str6, j.a("verify_login_failed", "verify login failed"), this.b); } catch (JSONException e12) { e6 = e12; } } else { com.mob.secverify.b.b.a().b("[SecPure] ==>%s", "pplocation=" + this.e); String str9 = this.e; String substring = str9.substring(str9.indexOf("?") + 1); JSONObject jSONObject2 = new JSONObject(); jSONObject2.put(substring.split("=")[0], substring.split("=")[1]); jSONObject2.put("data", str7); String str10 = this.e; this.e = str10.substring(1, str10.lastIndexOf("?")); String str11 = "http://onekey.cmpassport.com/unisdk/" + this.e; dVar.b = dVar.b + "getNewTelecomPhoneNumberNotify;"; this.e = null; com.mob.secverify.b.b.a().b("[SecPure] ==>%s", "location" + str11); a(str11, jSONObject2.toString(), aVar, network, "POST", dVar); } } catch (JSONException e13) { e6 = e13; str6 = "200039"; com.mob.secverify.pure.a.a.a.c.a.b.add(e6); aVar.a(str6, j.a("verify_login_failed", "verify login failed"), this.b); } } catch (JSONException e14) { e6 = e14; str5 = "200028"; str6 = "200039"; com.mob.secverify.pure.a.a.a.c.a.b.add(e6); aVar.a(str6, j.a("verify_login_failed", "verify login failed"), this.b); } } else { aVar.a(str7, this.b); } } }