package com.tencent.open.utils; import a.f; import a40.j; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.os.SystemClock; import android.text.TextUtils; import com.tencent.connect.auth.QQToken; import com.tencent.open.a.g; import com.tencent.open.b.h; import com.tencent.open.log.SLog; import com.tencent.open.log.d; import com.tencent.tauth.IRequestListener; import gg0.n; import java.io.CharConversionException; import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InvalidClassException; import java.io.InvalidObjectException; import java.io.NotActiveException; import java.io.NotSerializableException; import java.io.OptionalDataException; import java.io.StreamCorruptedException; import java.io.SyncFailedException; import java.io.UTFDataFormatException; import java.io.UnsupportedEncodingException; import java.io.WriteAbortedException; import java.net.BindException; import java.net.ConnectException; import java.net.HttpRetryException; import java.net.MalformedURLException; import java.net.NoRouteToHostException; import java.net.PortUnreachableException; import java.net.ProtocolException; import java.net.SocketTimeoutException; import java.net.URLEncoder; import java.net.UnknownHostException; import java.net.UnknownServiceException; import java.nio.channels.ClosedChannelException; import java.nio.channels.FileLockInterruptionException; import java.nio.charset.MalformedInputException; import java.nio.charset.UnmappableCharacterException; import java.util.HashMap; import java.util.InvalidPropertiesFormatException; import java.util.Map; import java.util.zip.ZipException; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLKeyException; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLProtocolException; import org.json.JSONException; import org.json.JSONObject; /* compiled from: ProGuard */ public class HttpUtils { /* compiled from: ProGuard */ public static class NetworkUnavailableException extends Exception { public NetworkUnavailableException(String str) { super(str); } } /* compiled from: ProGuard */ public static class a { /* renamed from: a reason: collision with root package name */ public final String f29416a; public final int b; private a(String str, int i) { this.f29416a = str; this.b = i; } } private HttpUtils() { } private static void a(Context context, QQToken qQToken, String str) { if (str.indexOf("add_share") > -1 || str.indexOf("upload_pic") > -1 || str.indexOf("add_topic") > -1 || str.indexOf("set_user_face") > -1 || str.indexOf("add_t") > -1 || str.indexOf("add_pic_t") > -1 || str.indexOf("add_pic_url") > -1 || str.indexOf("add_video") > -1) { com.tencent.connect.a.a.a(context, qQToken, "requireApi", str); } } private static Map<String, byte[]> b(Bundle bundle) { HashMap hashMap = new HashMap(0); if (!(bundle == null || bundle.size() == 0)) { for (String str : bundle.keySet()) { Object obj = bundle.get(str); if (obj instanceof byte[]) { hashMap.put(str, (byte[]) obj); } } } return hashMap; } public static String encodeUrl(Bundle bundle) { return encodeUrl(a(bundle)); } public static int getErrorCodeFromException(IOException iOException) { if (iOException instanceof CharConversionException) { return -20; } if (iOException instanceof MalformedInputException) { return -21; } if (iOException instanceof UnmappableCharacterException) { return -22; } if (iOException instanceof ClosedChannelException) { return -24; } if (iOException instanceof EOFException) { return -26; } if (iOException instanceof FileLockInterruptionException) { return -27; } if (iOException instanceof FileNotFoundException) { return -28; } if (iOException instanceof HttpRetryException) { return -29; } if (iOException instanceof SocketTimeoutException) { return -8; } if (iOException instanceof InvalidPropertiesFormatException) { return -30; } if (iOException instanceof MalformedURLException) { return -3; } if (iOException instanceof InvalidClassException) { return -33; } if (iOException instanceof InvalidObjectException) { return -34; } if (iOException instanceof NotActiveException) { return -35; } if (iOException instanceof NotSerializableException) { return -36; } if (iOException instanceof OptionalDataException) { return -37; } if (iOException instanceof StreamCorruptedException) { return -38; } if (iOException instanceof WriteAbortedException) { return -39; } if (iOException instanceof ProtocolException) { return -40; } if (iOException instanceof SSLHandshakeException) { return -41; } if (iOException instanceof SSLKeyException) { return -42; } if (iOException instanceof SSLPeerUnverifiedException) { return -43; } if (iOException instanceof SSLProtocolException) { return -44; } if (iOException instanceof BindException) { return -45; } if (iOException instanceof ConnectException) { return -46; } if (iOException instanceof NoRouteToHostException) { return -47; } if (iOException instanceof PortUnreachableException) { return -48; } if (iOException instanceof SyncFailedException) { return -49; } if (iOException instanceof UTFDataFormatException) { return -50; } if (iOException instanceof UnknownHostException) { return -51; } if (iOException instanceof UnknownServiceException) { return -52; } if (iOException instanceof UnsupportedEncodingException) { return -53; } return iOException instanceof ZipException ? -54 : -2; } public static a getProxy(Context context) { ConnectivityManager connectivityManager; NetworkInfo networkInfo; if (context == null || (connectivityManager = (ConnectivityManager) context.getSystemService("connectivity")) == null) { return null; } try { networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (Exception unused) { networkInfo = null; } if (networkInfo != null && networkInfo.getType() == 0) { String b = b(context); int a5 = a(context); if (!TextUtils.isEmpty(b) && a5 >= 0) { return new a(b, a5); } } return null; } /* JADX WARNING: Code restructure failed: missing block: B:24:0x00f2, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x00f3, code lost: r4 = r1; r1 = r12; */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0113, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x0115, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:32:0x0116, code lost: r0.printStackTrace(); com.tencent.open.b.h.a().a(r13, r15, 0, 0, -4); */ /* JADX WARNING: Code restructure failed: missing block: B:33:0x0127, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:34:0x0128, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:35:0x0129, code lost: r0.printStackTrace(); com.tencent.open.b.h.a().a(r13, r15, 0, 0, getErrorCodeFromException(r0)); */ /* JADX WARNING: Code restructure failed: missing block: B:36:0x013d, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:37:0x013e, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:38:0x013f, code lost: r0.printStackTrace(); com.tencent.open.b.h.a().a(r13, r15, 0, 0, -3); */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x0150, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:40:0x0151, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:41:0x0152, code lost: r21 = r1; r1 = r12; */ /* JADX WARNING: Code restructure failed: missing block: B:42:0x0155, code lost: r4 = r21; */ /* JADX WARNING: Code restructure failed: missing block: B:43:0x0157, code lost: r0.printStackTrace(); r12 = -8; r8 = 0; r10 = 0; */ /* JADX WARNING: Code restructure failed: missing block: B:44:0x015f, code lost: if (r1 < r14) goto L_0x0161; */ /* JADX WARNING: Code restructure failed: missing block: B:45:0x0161, code lost: r15 = android.os.SystemClock.elapsedRealtime(); */ /* JADX WARNING: Code restructure failed: missing block: B:46:0x0165, code lost: if (r1 >= r14) goto L_0x0167; */ /* JADX WARNING: Code restructure failed: missing block: B:47:0x0167, code lost: r1 = r4; */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x0176, code lost: com.tencent.open.b.h.a().a(r13, r15, 0, 0, -8); */ /* JADX WARNING: Code restructure failed: missing block: B:52:0x017f, code lost: throw r0; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:24:0x00f2 A[ExcHandler: SocketTimeoutException (e java.net.SocketTimeoutException), Splitter:B:16:0x00d3] */ /* JADX WARNING: Removed duplicated region for block: B:31:0x0115 A[ExcHandler: JSONException (r0v12 'e' org.json.JSONException A[CUSTOM_DECLARE]), Splitter:B:12:0x00b3] */ /* JADX WARNING: Removed duplicated region for block: B:34:0x0128 A[ExcHandler: IOException (r0v11 'e' java.io.IOException A[CUSTOM_DECLARE]), Splitter:B:12:0x00b3] */ /* JADX WARNING: Removed duplicated region for block: B:37:0x013e A[ExcHandler: MalformedURLException (r0v10 'e' java.net.MalformedURLException A[CUSTOM_DECLARE]), Splitter:B:12:0x00b3] */ /* JADX WARNING: Removed duplicated region for block: B:45:0x0161 */ /* JADX WARNING: Removed duplicated region for block: B:57:0x0176 A[SYNTHETIC] */ public static JSONObject request(QQToken qQToken, Context context, String str, Bundle bundle, String str2) throws IOException, JSONException, NetworkUnavailableException, HttpStatusException { String str3; QQToken qQToken2; String str4; JSONObject jSONObject; JSONObject jSONObject2; int i; g a5; int i3; SLog.i("openSDK_LOG.HttpUtils", "OpenApi request"); if (m.b(context)) { if (!str.toLowerCase().startsWith("http")) { str4 = j.a().a(context, "https://openmobile.qq.com/") + str; str3 = j.a().a(context, "https://openmobile.qq.com/") + str; qQToken2 = qQToken; } else { qQToken2 = qQToken; str4 = str; str3 = str4; } a(context, qQToken2, str); JSONObject jSONObject3 = null; long elapsedRealtime = SystemClock.elapsedRealtime(); int i12 = 0; int a12 = i.a(context, qQToken.getAppId()).a("Common_HttpRetryCount"); StringBuilder m = n.m("config 1:Common_HttpRetryCount config_value:", a12, " appid:"); m.append(qQToken.getAppId()); m.append(" url:"); m.append(str3); SLog.v("OpenConfig_test", m.toString()); int i13 = a12 == 0 ? 3 : a12; StringBuilder m12 = n.m("config 1:Common_HttpRetryCount result_value:", i13, " appid:"); m12.append(qQToken.getAppId()); m12.append(" url:"); m12.append(str3); SLog.v("OpenConfig_test", m12.toString()); long j = elapsedRealtime; while (true) { int i14 = i12 + 1; try { a5 = a(str4, str2, bundle); int d = a5.d(); SLog.i("openSDK_LOG.HttpUtils", "request statusCode " + d); if (d == 200) { jSONObject = m.d(a5.a()); i3 = jSONObject.getInt("ret"); break; } JSONObject jSONObject4 = jSONObject3; i = i14; h.a().a(str3, j, 0, 0, d); throw new HttpStatusException(d); } catch (JSONException unused) { i3 = -4; } catch (SocketTimeoutException e) { } catch (MalformedURLException e6) { } catch (IOException e12) { } i12 = i; jSONObject3 = jSONObject2; } h.a().a(str3, j, r8, r10, r12); return jSONObject; } throw new NetworkUnavailableException("network unavailable"); long j12 = (long) a5.b(); int i15 = i3; long j13 = (long) a5.c(); h.a().a(str3, j, j13, j12, i15); return jSONObject; } public static void requestAsync(final QQToken qQToken, final Context context, final String str, final Bundle bundle, final String str2, final IRequestListener iRequestListener) { SLog.i("openSDK_LOG.HttpUtils", "OpenApi requestAsync"); l.a(new Runnable() { /* class com.tencent.open.utils.HttpUtils.AnonymousClass1 */ public void run() { try { JSONObject request = HttpUtils.request(qQToken, context, str, bundle, str2); IRequestListener iRequestListener = iRequestListener; if (iRequestListener != null) { iRequestListener.onComplete(request); SLog.i("openSDK_LOG.HttpUtils", "OpenApi onComplete"); } } catch (MalformedURLException e6) { IRequestListener iRequestListener2 = iRequestListener; if (iRequestListener2 != null) { iRequestListener2.onMalformedURLException(e6); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync MalformedURLException" + e6.toString()); } } catch (SocketTimeoutException e12) { IRequestListener iRequestListener3 = iRequestListener; if (iRequestListener3 != null) { iRequestListener3.onSocketTimeoutException(e12); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync onSocketTimeoutException" + e12.toString()); } } catch (NetworkUnavailableException e13) { IRequestListener iRequestListener4 = iRequestListener; if (iRequestListener4 != null) { iRequestListener4.onNetworkUnavailableException(e13); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync onNetworkUnavailableException" + e13.toString()); } } catch (HttpStatusException e14) { IRequestListener iRequestListener5 = iRequestListener; if (iRequestListener5 != null) { iRequestListener5.onHttpStatusException(e14); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync onHttpStatusException" + e14.toString()); } } catch (IOException e15) { IRequestListener iRequestListener6 = iRequestListener; if (iRequestListener6 != null) { iRequestListener6.onIOException(e15); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync IOException" + e15.toString()); } } catch (JSONException e16) { IRequestListener iRequestListener7 = iRequestListener; if (iRequestListener7 != null) { iRequestListener7.onJSONException(e16); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync JSONException" + e16.toString()); } } catch (Exception e17) { IRequestListener iRequestListener8 = iRequestListener; if (iRequestListener8 != null) { iRequestListener8.onUnknowException(e17); SLog.e("openSDK_LOG.HttpUtils", "OpenApi requestAsync onUnknowException" + e17.toString()); } } } }); } /* compiled from: ProGuard */ public static class HttpStatusException extends Exception { public final int statusCode; public HttpStatusException(String str) { super(str); this.statusCode = -1; } public HttpStatusException(int i) { super(j.h("http status code error:", i)); this.statusCode = i; } } public static String encodeUrl(Map<String, String> map) { if (map == null || map.size() == 0) { return ""; } StringBuilder sb2 = new StringBuilder(); boolean z = true; for (String str : map.keySet()) { if (z) { z = false; } else { sb2.append("&"); } sb2.append(URLEncoder.encode(str)); sb2.append("="); sb2.append(URLEncoder.encode(map.get(str))); } return sb2.toString(); } private static String b(Context context) { return System.getProperty("http.proxyHost"); } private static g a(String str, String str2, Bundle bundle) throws IOException { Bundle bundle2; if (bundle != null) { bundle2 = new Bundle(bundle); } else { bundle2 = new Bundle(); } if (str2.equalsIgnoreCase("GET")) { Map<String, String> a5 = a(bundle2); Bundle b = d.b(bundle2); if (b != bundle2) { StringBuilder h12 = f.h("-->openUrl encodedParam ="); h12.append(b.toString()); h12.append(" -- url = "); h12.append(str); SLog.i("openSDK_LOG.HttpUtils", h12.toString()); } else { StringBuilder h13 = f.h("-->openUrl encodedParam ="); h13.append(a5.toString()); h13.append(" -- url = "); h13.append(str); SLog.i("openSDK_LOG.HttpUtils", h13.toString()); } return com.tencent.open.a.f.a().a(str, a5); } else if (str2.equalsIgnoreCase("POST")) { Map<String, String> a12 = a(bundle2); Map<String, byte[]> b2 = b(bundle2); if (b2 == null || b2.size() == 0) { return com.tencent.open.a.f.a().b(str, a12); } StringBuilder h14 = f.h("openUrl: has binary "); h14.append(b2.size()); SLog.w("openSDK_LOG.HttpUtils", h14.toString()); return com.tencent.open.a.f.a().a(str, a12, b2); } else { SLog.e("openSDK_LOG.HttpUtils", "openUrl: http method " + str2 + " is not supported."); throw new IOException("http method is not supported."); } } private static Map<String, String> a(Bundle bundle) { HashMap hashMap = new HashMap(); if (!(bundle == null || bundle.size() == 0)) { for (String str : bundle.keySet()) { Object obj = bundle.get(str); if (!(obj instanceof String) && !(obj instanceof String[])) { StringBuilder h12 = f.h("parseBundleToMap: the type "); h12.append(obj.getClass()); h12.append(" is unsupported"); SLog.w("openSDK_LOG.HttpUtils", h12.toString()); } else if (obj instanceof String[]) { String[] strArr = (String[]) obj; StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < strArr.length; i++) { if (i != 0) { sb2.append(","); } sb2.append(strArr[i]); } hashMap.put(str, sb2.toString()); } else { hashMap.put(str, (String) obj); } } } return hashMap; } private static int a(Context context) { String property = System.getProperty("http.proxyPort"); if (!TextUtils.isEmpty(property)) { try { return Integer.parseInt(property); } catch (NumberFormatException unused) { } } return -1; } }