翰林优商.apk(点击下载) / d.java


package com.mobile.auth.d;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;
import android.text.TextUtils;
import com.baidu.mobads.sdk.internal.ae;
import com.mobile.auth.a.a;
import com.mobile.auth.c.b;
import com.mobile.auth.c.e;
import com.mobile.auth.gatewayauth.ExceptionProcessor;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;

public class d {
    private static final String a = "d";

    /* JADX WARNING: Removed duplicated region for block: B:59:0x00fc A[SYNTHETIC, Splitter:B:59:0x00fc] */
    /* JADX WARNING: Removed duplicated region for block: B:64:0x0104 A[Catch:{ Exception -> 0x0100 }] */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x0109 A[Catch:{ Exception -> 0x0100 }] */
    public static String a(Context context, String str, Network network) {
        BufferedReader bufferedReader;
        InputStreamReader inputStreamReader;
        InputStream inputStream;
        Throwable th;
        String str2 = "";
        try {
            int i = 3000;
            int i2 = a.c <= 0 ? 3000 : a.c;
            if (a.d > 0) {
                i = a.d;
            }
            try {
                URL url = new URL(str);
                HttpsURLConnection httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url.openConnection() : network.openConnection(url));
                httpsURLConnection.setRequestProperty("accept", "*/*");
                httpsURLConnection.setRequestProperty("connection", "Keep-Alive");
                httpsURLConnection.setRequestMethod("GET");
                httpsURLConnection.setDoOutput(false);
                httpsURLConnection.setDoInput(true);
                httpsURLConnection.setConnectTimeout(i2);
                httpsURLConnection.setReadTimeout(i);
                httpsURLConnection.setUseCaches(false);
                httpsURLConnection.addRequestProperty("Accept-Charset", "UTF-8");
                httpsURLConnection.connect();
                if (httpsURLConnection.getResponseCode() == 302) {
                    URL url2 = new URL(httpsURLConnection.getHeaderField("Location"));
                    httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2));
                    httpsURLConnection.setRequestProperty("accept", "*/*");
                    httpsURLConnection.setRequestProperty("connection", "Keep-Alive");
                    httpsURLConnection.setRequestMethod("GET");
                    httpsURLConnection.setDoOutput(false);
                    httpsURLConnection.setDoInput(true);
                    httpsURLConnection.setConnectTimeout(i2);
                    httpsURLConnection.setReadTimeout(i);
                    httpsURLConnection.setUseCaches(false);
                    httpsURLConnection.addRequestProperty("Accept-Charset", "UTF-8");
                    httpsURLConnection.connect();
                }
                if (httpsURLConnection.getResponseCode() == 200) {
                    inputStream = httpsURLConnection.getInputStream();
                    try {
                        inputStreamReader = new InputStreamReader(inputStream);
                    } catch (Throwable th2) {
                        th = th2;
                        inputStreamReader = null;
                        bufferedReader = null;
                        try {
                            a.a(a, "doGet error", th);
                            if (bufferedReader != null) {
                            }
                            if (inputStreamReader != null) {
                            }
                            if (inputStream != null) {
                            }
                            return str2;
                        } catch (Throwable th3) {
                            if (bufferedReader != null) {
                                try {
                                    bufferedReader.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    throw th3;
                                }
                            }
                            if (inputStreamReader != null) {
                                inputStreamReader.close();
                            }
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            throw th3;
                        }
                    }
                    try {
                        bufferedReader = new BufferedReader(inputStreamReader);
                        while (true) {
                            try {
                                String readLine = bufferedReader.readLine();
                                if (readLine == null) {
                                    break;
                                }
                                str2 = str2 + readLine;
                            } catch (Throwable th4) {
                                th = th4;
                                a.a(a, "doGet error", th);
                                if (bufferedReader != null) {
                                }
                                if (inputStreamReader != null) {
                                }
                                if (inputStream != null) {
                                }
                                return str2;
                            }
                        }
                    } catch (Throwable th5) {
                        th = th5;
                        bufferedReader = null;
                        a.a(a, "doGet error", th);
                        if (bufferedReader != null) {
                            try {
                                bufferedReader.close();
                            } catch (Exception e2) {
                                e = e2;
                                e.printStackTrace();
                                return str2;
                            }
                        }
                        if (inputStreamReader != null) {
                            inputStreamReader.close();
                        }
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        return str2;
                    }
                } else {
                    inputStream = null;
                    inputStreamReader = null;
                    bufferedReader = null;
                }
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (Exception e3) {
                        e = e3;
                        e.printStackTrace();
                        return str2;
                    }
                }
                if (inputStreamReader != null) {
                    inputStreamReader.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Throwable th6) {
                th = th6;
                inputStream = null;
                inputStreamReader = null;
                bufferedReader = null;
                a.a(a, "doGet error", th);
                if (bufferedReader != null) {
                }
                if (inputStreamReader != null) {
                }
                if (inputStream != null) {
                }
                return str2;
            }
            return str2;
        } catch (Throwable th7) {
            ExceptionProcessor.processException(th7);
            return null;
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:100:0x0237, code lost:
        if (r1 != null) goto L_0x0239;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:101:0x0239, code lost:
        r1.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:108:0x0279, code lost:
        if (r1 != null) goto L_0x0239;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:115:0x02b7, code lost:
        if (r1 != null) goto L_0x0239;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:122:0x02f6, code lost:
        if (r1 != null) goto L_0x0239;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:129:0x0335, code lost:
        if (r1 != null) goto L_0x0239;
     */
    /* JADX WARNING: Removed duplicated region for block: B:107:0x0276  */
    /* JADX WARNING: Removed duplicated region for block: B:114:0x02b4  */
    /* JADX WARNING: Removed duplicated region for block: B:121:0x02f3  */
    /* JADX WARNING: Removed duplicated region for block: B:128:0x0332  */
    /* JADX WARNING: Removed duplicated region for block: B:99:0x0234  */
    public static String a(Context context, String str, String str2, Network network, String str3, String str4) {
        String str5;
        BufferedReader bufferedReader;
        SocketTimeoutException socketTimeoutException;
        InputStream inputStream;
        UnknownHostException unknownHostException;
        SSLPeerUnverifiedException sSLPeerUnverifiedException;
        IOException iOException;
        Throwable th;
        String str6;
        String str7;
        InputStream inputStream2;
        BufferedReader bufferedReader2;
        try {
            int i = 3000;
            int i2 = a.c <= 0 ? 3000 : a.c;
            if (a.d > 0) {
                i = a.d;
            }
            try {
                URL url = new URL(str);
                HttpsURLConnection httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url.openConnection() : network.openConnection(url));
                httpsURLConnection.setRequestProperty("accept", "*/*");
                httpsURLConnection.setRequestMethod(ae.b);
                httpsURLConnection.setDoOutput(true);
                httpsURLConnection.setDoInput(true);
                httpsURLConnection.setConnectTimeout(i2);
                httpsURLConnection.setReadTimeout(i);
                httpsURLConnection.setUseCaches(false);
                httpsURLConnection.setHostnameVerifier(a());
                if (Build.VERSION.SDK_INT < 21) {
                    httpsURLConnection.setInstanceFollowRedirects(false);
                }
                httpsURLConnection.addRequestProperty("Accept-Charset", "UTF-8");
                httpsURLConnection.addRequestProperty("deviceId", str3);
                httpsURLConnection.addRequestProperty("reqId", str4);
                if (!TextUtils.isEmpty(str2)) {
                    DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(httpsURLConnection.getOutputStream()));
                    dataOutputStream.write(str2.getBytes("UTF-8"));
                    dataOutputStream.flush();
                    dataOutputStream.close();
                } else {
                    httpsURLConnection.connect();
                }
                if (Build.VERSION.SDK_INT >= 21 || httpsURLConnection.getResponseCode() != 302) {
                    str7 = "";
                    str6 = "Location";
                } else {
                    String headerField = httpsURLConnection.getHeaderField("Location");
                    if (!TextUtils.isEmpty(headerField)) {
                        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
                        str7 = "";
                        if (connectivityManager.getNetworkInfo(5).getState().compareTo((Enum) NetworkInfo.State.CONNECTED) == 0) {
                            str6 = "Location";
                            Class.forName("android.net.ConnectivityManager").getMethod("requestRouteToHost", Integer.TYPE, Integer.TYPE).invoke(connectivityManager, 5, Integer.valueOf(e.a(e.b(headerField))));
                            URL url2 = new URL(headerField);
                            httpsURLConnection = (HttpsURLConnection) ((network != null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2));
                            httpsURLConnection.setRequestProperty("accept", "*/*");
                            httpsURLConnection.setRequestMethod(ae.b);
                            httpsURLConnection.setDoOutput(true);
                            httpsURLConnection.setDoInput(true);
                            httpsURLConnection.setConnectTimeout(i2);
                            httpsURLConnection.setReadTimeout(i);
                            httpsURLConnection.setUseCaches(false);
                            httpsURLConnection.addRequestProperty("Accept-Charset", "UTF-8");
                            httpsURLConnection.connect();
                        }
                    } else {
                        str7 = "";
                    }
                    str6 = "Location";
                    URL url22 = new URL(headerField);
                    httpsURLConnection = (HttpsURLConnection) ((network != null || Build.VERSION.SDK_INT < 21) ? url22.openConnection() : network.openConnection(url22));
                    httpsURLConnection.setRequestProperty("accept", "*/*");
                    httpsURLConnection.setRequestMethod(ae.b);
                    httpsURLConnection.setDoOutput(true);
                    httpsURLConnection.setDoInput(true);
                    httpsURLConnection.setConnectTimeout(i2);
                    httpsURLConnection.setReadTimeout(i);
                    httpsURLConnection.setUseCaches(false);
                    httpsURLConnection.addRequestProperty("Accept-Charset", "UTF-8");
                    httpsURLConnection.connect();
                }
                if (httpsURLConnection.getResponseCode() == 302) {
                    URL url3 = new URL(httpsURLConnection.getHeaderField(str6));
                    httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url3.openConnection() : network.openConnection(url3));
                    httpsURLConnection.setRequestProperty("accept", "*/*");
                    httpsURLConnection.setRequestMethod("GET");
                    httpsURLConnection.setConnectTimeout(i2);
                    httpsURLConnection.setReadTimeout(i);
                    httpsURLConnection.setUseCaches(false);
                    httpsURLConnection.addRequestProperty("Accept-Charset", "UTF-8");
                    httpsURLConnection.connect();
                }
                if (httpsURLConnection.getResponseCode() == 200) {
                    inputStream = httpsURLConnection.getInputStream();
                    try {
                        StringBuilder sb = new StringBuilder();
                        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                        while (true) {
                            try {
                                String readLine = bufferedReader.readLine();
                                if (readLine == null) {
                                    break;
                                }
                                sb.append(readLine);
                                sb.append("\n");
                            } catch (SocketTimeoutException e) {
                                socketTimeoutException = e;
                                str5 = "{\"result\":80005,\"msg\":\"Socket超时异常\"}";
                                String str8 = a;
                                a.a(str8, "sendRequest SocketTimeoutException-preauth-" + socketTimeoutException.getMessage(), socketTimeoutException);
                                b a2 = e.a(str4);
                                a2.h("doPost SocketTimeoutException -- " + socketTimeoutException.getMessage());
                                if (bufferedReader != null) {
                                    bufferedReader.close();
                                }
                            } catch (UnknownHostException e2) {
                                unknownHostException = e2;
                                str5 = "{\"result\":80006,\"msg\":\"域名解析异常\"}";
                                String str9 = a;
                                a.a(str9, "sendRequest UnknownHostException-preauth-" + unknownHostException.getMessage(), unknownHostException);
                                b a3 = e.a(str4);
                                a3.h("doPost UnknownHostException -- " + unknownHostException.getMessage());
                                if (bufferedReader != null) {
                                    bufferedReader.close();
                                }
                            } catch (SSLPeerUnverifiedException e3) {
                                sSLPeerUnverifiedException = e3;
                                str5 = "{\"result\":80013,\"msg\":\"域名校验未通过\"}";
                                String str10 = a;
                                a.a(str10, "sendRequest SSLPeerUnverifiedException-preauth-" + sSLPeerUnverifiedException.getMessage(), sSLPeerUnverifiedException);
                                b a4 = e.a(str4);
                                a4.h("doPost SSLPeerUnverifiedException -- " + sSLPeerUnverifiedException.getMessage());
                                if (bufferedReader != null) {
                                    bufferedReader.close();
                                }
                            } catch (IOException e4) {
                                iOException = e4;
                                str5 = "{\"result\":80007,\"msg\":\"IO异常\"}";
                                String str11 = a;
                                a.a(str11, "sendRequest IOException-preauth-" + iOException.getMessage(), iOException);
                                b a5 = e.a(str4);
                                a5.h("doPost IOException -- " + iOException.getMessage());
                                if (bufferedReader != null) {
                                    bufferedReader.close();
                                }
                            } catch (Throwable th2) {
                                th = th2;
                                str5 = "{\"result\":80001,\"msg\":\"请求异常\"}";
                                try {
                                    String str12 = a;
                                    a.a(str12, "sendRequest Throwable-preauth-" + th.getMessage(), th);
                                    b a6 = e.a(str4);
                                    a6.h("doPost Throwable -- " + th.getMessage());
                                    if (bufferedReader != null) {
                                        bufferedReader.close();
                                    }
                                } catch (Throwable unused) {
                                    throw th;
                                }
                            }
                        }
                        str5 = sb.toString();
                        e.a(str4).g(a(context, httpsURLConnection));
                        inputStream2 = inputStream;
                        bufferedReader2 = bufferedReader;
                    } catch (SocketTimeoutException e5) {
                        socketTimeoutException = e5;
                        bufferedReader = null;
                        str5 = "{\"result\":80005,\"msg\":\"Socket超时异常\"}";
                        String str82 = a;
                        a.a(str82, "sendRequest SocketTimeoutException-preauth-" + socketTimeoutException.getMessage(), socketTimeoutException);
                        b a22 = e.a(str4);
                        a22.h("doPost SocketTimeoutException -- " + socketTimeoutException.getMessage());
                        if (bufferedReader != null) {
                        }
                    } catch (UnknownHostException e6) {
                        unknownHostException = e6;
                        bufferedReader = null;
                        str5 = "{\"result\":80006,\"msg\":\"域名解析异常\"}";
                        String str92 = a;
                        a.a(str92, "sendRequest UnknownHostException-preauth-" + unknownHostException.getMessage(), unknownHostException);
                        b a32 = e.a(str4);
                        a32.h("doPost UnknownHostException -- " + unknownHostException.getMessage());
                        if (bufferedReader != null) {
                        }
                    } catch (SSLPeerUnverifiedException e7) {
                        sSLPeerUnverifiedException = e7;
                        bufferedReader = null;
                        str5 = "{\"result\":80013,\"msg\":\"域名校验未通过\"}";
                        String str102 = a;
                        a.a(str102, "sendRequest SSLPeerUnverifiedException-preauth-" + sSLPeerUnverifiedException.getMessage(), sSLPeerUnverifiedException);
                        b a42 = e.a(str4);
                        a42.h("doPost SSLPeerUnverifiedException -- " + sSLPeerUnverifiedException.getMessage());
                        if (bufferedReader != null) {
                        }
                    } catch (IOException e8) {
                        iOException = e8;
                        bufferedReader = null;
                        str5 = "{\"result\":80007,\"msg\":\"IO异常\"}";
                        String str112 = a;
                        a.a(str112, "sendRequest IOException-preauth-" + iOException.getMessage(), iOException);
                        b a52 = e.a(str4);
                        a52.h("doPost IOException -- " + iOException.getMessage());
                        if (bufferedReader != null) {
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        bufferedReader = null;
                        str5 = "{\"result\":80001,\"msg\":\"请求异常\"}";
                        String str122 = a;
                        a.a(str122, "sendRequest Throwable-preauth-" + th.getMessage(), th);
                        b a62 = e.a(str4);
                        a62.h("doPost Throwable -- " + th.getMessage());
                        if (bufferedReader != null) {
                        }
                    }
                } else {
                    str5 = str7;
                    bufferedReader2 = null;
                    inputStream2 = null;
                }
                if (bufferedReader2 != null) {
                    try {
                        bufferedReader2.close();
                    } catch (Throwable unused2) {
                    }
                }
                if (inputStream2 != null) {
                    inputStream2.close();
                }
            } catch (SocketTimeoutException e9) {
                socketTimeoutException = e9;
                inputStream = null;
                bufferedReader = null;
                str5 = "{\"result\":80005,\"msg\":\"Socket超时异常\"}";
                String str822 = a;
                a.a(str822, "sendRequest SocketTimeoutException-preauth-" + socketTimeoutException.getMessage(), socketTimeoutException);
                b a222 = e.a(str4);
                a222.h("doPost SocketTimeoutException -- " + socketTimeoutException.getMessage());
                if (bufferedReader != null) {
                }
            } catch (UnknownHostException e10) {
                unknownHostException = e10;
                inputStream = null;
                bufferedReader = null;
                str5 = "{\"result\":80006,\"msg\":\"域名解析异常\"}";
                String str922 = a;
                a.a(str922, "sendRequest UnknownHostException-preauth-" + unknownHostException.getMessage(), unknownHostException);
                b a322 = e.a(str4);
                a322.h("doPost UnknownHostException -- " + unknownHostException.getMessage());
                if (bufferedReader != null) {
                }
            } catch (SSLPeerUnverifiedException e11) {
                sSLPeerUnverifiedException = e11;
                inputStream = null;
                bufferedReader = null;
                str5 = "{\"result\":80013,\"msg\":\"域名校验未通过\"}";
                String str1022 = a;
                a.a(str1022, "sendRequest SSLPeerUnverifiedException-preauth-" + sSLPeerUnverifiedException.getMessage(), sSLPeerUnverifiedException);
                b a422 = e.a(str4);
                a422.h("doPost SSLPeerUnverifiedException -- " + sSLPeerUnverifiedException.getMessage());
                if (bufferedReader != null) {
                }
            } catch (IOException e12) {
                iOException = e12;
                inputStream = null;
                bufferedReader = null;
                str5 = "{\"result\":80007,\"msg\":\"IO异常\"}";
                String str1122 = a;
                a.a(str1122, "sendRequest IOException-preauth-" + iOException.getMessage(), iOException);
                b a522 = e.a(str4);
                a522.h("doPost IOException -- " + iOException.getMessage());
                if (bufferedReader != null) {
                }
            } catch (Throwable th4) {
                th = th4;
                inputStream = null;
                bufferedReader = null;
                str5 = "{\"result\":80001,\"msg\":\"请求异常\"}";
                String str1222 = a;
                a.a(str1222, "sendRequest Throwable-preauth-" + th.getMessage(), th);
                b a622 = e.a(str4);
                a622.h("doPost Throwable -- " + th.getMessage());
                if (bufferedReader != null) {
                }
            }
            return str5;
        } catch (Throwable th5) {
            ExceptionProcessor.processException(th5);
            return null;
        }
    }

    public static String a(Context context, HttpsURLConnection httpsURLConnection) {
        try {
            Map headerFields = httpsURLConnection.getHeaderFields();
            List list = (List) headerFields.get("Log-Level");
            if (list != null && !list.isEmpty()) {
                for (int i = 0; i < list.size(); i++) {
                    String str = (String) list.get(0);
                    if (!TextUtils.isEmpty(str)) {
                        e.b(context, str);
                    }
                }
            }
            List list2 = (List) headerFields.get("p-ikgx");
            if (list2 != null && !list2.isEmpty()) {
                String str2 = (String) list2.get(0);
                if (!TextUtils.isEmpty(str2)) {
                    return str2;
                }
            }
        } catch (Throwable th) {
            try {
                ExceptionProcessor.processException(th);
                return null;
            } catch (Throwable th2) {
                ExceptionProcessor.processException(th2);
                return null;
            }
        }
        return null;
    }

    public static final HostnameVerifier a() {
        try {
            return new HostnameVerifier() {
                /* class com.mobile.auth.d.d.AnonymousClass1 */

                public final boolean verify(String str, SSLSession sSLSession) {
                    try {
                        return HttpsURLConnection.getDefaultHostnameVerifier().verify("id6.me", sSLSession);
                    } catch (Throwable th) {
                        ExceptionProcessor.processException(th);
                        return false;
                    }
                }
            };
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }
}