package com.mob.secverify.pure.a.a.d; import android.net.Network; import android.text.TextUtils; import androidx.core.view.accessibility.AccessibilityEventCompat; import com.meizu.cloud.pushsdk.constants.PushConstants; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.security.SecureRandom; import java.util.HashMap; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import org.json.JSONObject; /* compiled from: XWHttpImpl */ public class f { /* compiled from: XWHttpImpl */ public static class a implements HostnameVerifier { public boolean verify(String str, SSLSession sSLSession) { if (TextUtils.isEmpty(str)) { return false; } if (str.equals("opencloud.wostore.cn") || str.contains("10010.com")) { return true; } return false; } } /* compiled from: XWHttpImpl */ public static class b implements HostnameVerifier { public boolean verify(String str, SSLSession sSLSession) { if (TextUtils.isEmpty(str)) { return false; } if (str.equals("opencloud.wostore.cn") || str.contains("10010.com")) { return true; } return false; } } private String c(String str, HashMap<String, String> hashMap, Network network) { String str2; String str3; HttpsURLConnection httpsURLConnection; try { str2 = new URL(str).getHost(); } catch (MalformedURLException unused) { str2 = ""; } if (str2.contains("10010.com")) { StringBuilder h12 = a.f.h(str2); h12.append(g.b()); str3 = h12.toString(); } else { str3 = str; } try { SSLContext instance = SSLContext.getInstance("TLS"); instance.init(null, null, new SecureRandom()); j jVar = new j(instance.getSocketFactory()); URL url = new URL(str3); if (network != null) { httpsURLConnection = (HttpsURLConnection) network.openConnection(url); } else { httpsURLConnection = (HttpsURLConnection) url.openConnection(); } httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(false); httpsURLConnection.setUseCaches(false); httpsURLConnection.setInstanceFollowRedirects(false); httpsURLConnection.setReadTimeout(30000); httpsURLConnection.setConnectTimeout(30000); httpsURLConnection.setRequestMethod("GET"); httpsURLConnection.setSSLSocketFactory(jVar); httpsURLConnection.setHostnameVerifier(new b()); if (hashMap != null) { for (String str4 : hashMap.keySet()) { httpsURLConnection.setRequestProperty(str4, hashMap.get(str4)); } } if (str.startsWith("https://opencloud.wostore.cn/openapi/netauth/precheck/wp?")) { httpsURLConnection.addRequestProperty("Connection", "Keep-Alive"); } else { httpsURLConnection.addRequestProperty("Connection", "close"); } httpsURLConnection.connect(); if (httpsURLConnection.getResponseCode() == 200) { String a5 = a(httpsURLConnection.getInputStream()); if (!TextUtils.isEmpty(a5)) { return a5; } JSONObject jSONObject = new JSONObject(); jSONObject.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10012); jSONObject.put("msg", "10012"); jSONObject.put("data", str3); return jSONObject.toString(); } else if (httpsURLConnection.getResponseCode() == 302) { String headerField = httpsURLConnection.getHeaderField("Location"); if (TextUtils.isEmpty(headerField)) { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10013); jSONObject2.put("msg", "无跳转地址"); jSONObject2.put("data", str2); return jSONObject2.toString(); } else if (headerField.startsWith("https")) { return a(headerField, null, network); } else { return b(headerField, null, network); } } else { JSONObject jSONObject3 = new JSONObject(); jSONObject3.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10010); jSONObject3.put("msg", "https状态码" + httpsURLConnection.getResponseCode()); jSONObject3.put("data", str2); return jSONObject3.toString(); } } catch (Throwable unused2) { return null; } } /* JADX WARNING: Removed duplicated region for block: B:56:0x0174 */ public String a(String str, HashMap<String, String> hashMap, Network network) { String str2; String str3; Throwable th2; HttpsURLConnection httpsURLConnection; try { str2 = new URL(str).getHost(); } catch (MalformedURLException unused) { str2 = ""; } if (str2.contains("10010.com")) { StringBuilder h12 = a.f.h(str); h12.append(g.b()); str3 = h12.toString(); } else { str3 = str; } try { URL url = new URL(str3); if (network != null) { httpsURLConnection = (HttpsURLConnection) network.openConnection(url); } else { httpsURLConnection = (HttpsURLConnection) url.openConnection(); } try { httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(false); httpsURLConnection.setUseCaches(false); httpsURLConnection.setInstanceFollowRedirects(false); httpsURLConnection.setReadTimeout(30000); httpsURLConnection.setConnectTimeout(30000); httpsURLConnection.setRequestMethod("GET"); httpsURLConnection.setHostnameVerifier(new a()); if (hashMap != null) { for (String str4 : hashMap.keySet()) { httpsURLConnection.setRequestProperty(str4, hashMap.get(str4)); } } if (str.startsWith("https://opencloud.wostore.cn/openapi/netauth/precheck/wp?")) { httpsURLConnection.addRequestProperty("Connection", "Keep-Alive"); } else { httpsURLConnection.addRequestProperty("Connection", "close"); } httpsURLConnection.connect(); if (httpsURLConnection.getResponseCode() == 200) { String a5 = a(httpsURLConnection.getInputStream()); if (TextUtils.isEmpty(a5)) { JSONObject jSONObject = new JSONObject(); jSONObject.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10012); jSONObject.put("msg", "10012"); jSONObject.put("data", str2); String jSONObject2 = jSONObject.toString(); httpsURLConnection.disconnect(); return jSONObject2; } httpsURLConnection.disconnect(); return a5; } else if (httpsURLConnection.getResponseCode() == 302) { String headerField = httpsURLConnection.getHeaderField("Location"); if (TextUtils.isEmpty(headerField)) { JSONObject jSONObject3 = new JSONObject(); jSONObject3.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10013); jSONObject3.put("msg", "无跳转地址"); jSONObject3.put("data", str2); String jSONObject4 = jSONObject3.toString(); httpsURLConnection.disconnect(); return jSONObject4; } else if (headerField.startsWith("https")) { String a12 = a(headerField, null, network); httpsURLConnection.disconnect(); return a12; } else { String b2 = b(headerField, null, network); httpsURLConnection.disconnect(); return b2; } } else { JSONObject jSONObject5 = new JSONObject(); jSONObject5.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10010); jSONObject5.put("msg", "https状态码" + httpsURLConnection.getResponseCode()); jSONObject5.put("data", str2); String jSONObject6 = jSONObject5.toString(); httpsURLConnection.disconnect(); return jSONObject6; } } catch (Throwable th3) { th2 = th3; try { com.mob.secverify.pure.c.f.a(th2); JSONObject jSONObject7 = new JSONObject(); jSONObject7.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10011); jSONObject7.put("msg", "https异常" + th2.getMessage()); jSONObject7.put("data", str2); String jSONObject8 = jSONObject7.toString(); if (httpsURLConnection != null) { httpsURLConnection.disconnect(); } return jSONObject8; } catch (Exception unused2) { if (httpsURLConnection != null) { httpsURLConnection.disconnect(); } return null; } catch (Throwable th4) { if (httpsURLConnection != null) { httpsURLConnection.disconnect(); } throw th4; } } } catch (Throwable th5) { th2 = th5; httpsURLConnection = null; com.mob.secverify.pure.c.f.a(th2); JSONObject jSONObject72 = new JSONObject(); jSONObject72.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10011); jSONObject72.put("msg", "https异常" + th2.getMessage()); jSONObject72.put("data", str2); String jSONObject82 = jSONObject72.toString(); if (httpsURLConnection != null) { } return jSONObject82; } } /* JADX WARNING: Removed duplicated region for block: B:47:0x0150 */ public String b(String str, HashMap<String, String> hashMap, Network network) { Throwable th2; HttpURLConnection httpURLConnection; try { URL url = new URL(str); str = "http://" + url.getHost(); } catch (MalformedURLException unused) { } try { URL url2 = new URL(str); if (network != null) { httpURLConnection = (HttpURLConnection) network.openConnection(url2); } else { httpURLConnection = (HttpURLConnection) url2.openConnection(); } try { httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(false); httpURLConnection.setUseCaches(false); httpURLConnection.setInstanceFollowRedirects(false); httpURLConnection.setReadTimeout(30000); httpURLConnection.setConnectTimeout(30000); httpURLConnection.setRequestMethod("GET"); if (hashMap != null) { for (String str2 : hashMap.keySet()) { httpURLConnection.setRequestProperty(str2, hashMap.get(str2)); } } httpURLConnection.addRequestProperty("Connection", "close"); httpURLConnection.connect(); if (httpURLConnection.getResponseCode() == 200) { String a5 = a(httpURLConnection.getInputStream()); if (TextUtils.isEmpty(a5)) { JSONObject jSONObject = new JSONObject(); jSONObject.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10012); jSONObject.put("msg", "10012"); jSONObject.put("data", str); String jSONObject2 = jSONObject.toString(); httpURLConnection.disconnect(); return jSONObject2; } httpURLConnection.disconnect(); return a5; } else if (httpURLConnection.getResponseCode() == 302) { String headerField = httpURLConnection.getHeaderField("Location"); if (TextUtils.isEmpty(headerField)) { JSONObject jSONObject3 = new JSONObject(); jSONObject3.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10013); jSONObject3.put("msg", "无跳转地址"); jSONObject3.put("data", str); String jSONObject4 = jSONObject3.toString(); httpURLConnection.disconnect(); return jSONObject4; } else if (headerField.startsWith("https")) { String a12 = a(headerField, null, network); httpURLConnection.disconnect(); return a12; } else { String b2 = b(headerField, null, network); httpURLConnection.disconnect(); return b2; } } else { JSONObject jSONObject5 = new JSONObject(); jSONObject5.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10010); jSONObject5.put("msg", "http状态码" + httpURLConnection.getResponseCode()); jSONObject5.put("data", str); String jSONObject6 = jSONObject5.toString(); httpURLConnection.disconnect(); return jSONObject6; } } catch (Throwable th3) { th2 = th3; try { JSONObject jSONObject7 = new JSONObject(); jSONObject7.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10024); jSONObject7.put("msg", "http异常" + th2.getMessage()); jSONObject7.put("data", str); String jSONObject8 = jSONObject7.toString(); if (httpURLConnection != null) { httpURLConnection.disconnect(); } return jSONObject8; } catch (Exception unused2) { if (httpURLConnection != null) { httpURLConnection.disconnect(); } return null; } catch (Throwable th4) { if (httpURLConnection != null) { httpURLConnection.disconnect(); } throw th4; } } } catch (Throwable th5) { th2 = th5; httpURLConnection = null; JSONObject jSONObject72 = new JSONObject(); jSONObject72.put(PushConstants.BASIC_PUSH_STATUS_CODE, 10024); jSONObject72.put("msg", "http异常" + th2.getMessage()); jSONObject72.put("data", str); String jSONObject82 = jSONObject72.toString(); if (httpURLConnection != null) { } return jSONObject82; } } /* JADX WARNING: Removed duplicated region for block: B:18:0x0029 A[SYNTHETIC, Splitter:B:18:0x0029] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x002e A[Catch:{ Exception -> 0x0031 }] */ /* JADX WARNING: Removed duplicated region for block: B:28:0x0035 A[SYNTHETIC, Splitter:B:28:0x0035] */ /* JADX WARNING: Removed duplicated region for block: B:31:0x003a A[Catch:{ Exception -> 0x003d }] */ private String a(InputStream inputStream) { ByteArrayOutputStream byteArrayOutputStream; Throwable th2; try { byteArrayOutputStream = new ByteArrayOutputStream(); try { byte[] bArr = new byte[AccessibilityEventCompat.TYPE_TOUCH_EXPLORATION_GESTURE_END]; while (true) { int read = inputStream.read(bArr); if (read == -1) { break; } byteArrayOutputStream.write(bArr, 0, read); } String byteArrayOutputStream2 = byteArrayOutputStream.toString(); try { byteArrayOutputStream.close(); inputStream.close(); } catch (Exception unused) { } return byteArrayOutputStream2; } catch (Exception unused2) { if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (Exception unused3) { return null; } } if (inputStream != null) { inputStream.close(); } return null; } catch (Throwable th3) { th2 = th3; if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (Exception unused4) { throw th2; } } if (inputStream != null) { inputStream.close(); } throw th2; } } catch (Exception unused5) { byteArrayOutputStream = null; if (byteArrayOutputStream != null) { } if (inputStream != null) { } return null; } catch (Throwable th4) { byteArrayOutputStream = null; th2 = th4; if (byteArrayOutputStream != null) { } if (inputStream != null) { } throw th2; } } }