米游社.apk(点击下载) / b.java


package com.unikuwei.mianmi.account.shield.d;

import android.net.Network;
import android.os.Build;
import android.text.TextUtils;
import cn.jpush.android.local.JPushConstants;
import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.tencent.imsdk.BaseConstants;
import com.unikuwei.mianmi.account.shield.UniAccountHelper;
import com.unikuwei.mianmi.account.shield.e.d;
import com.unikuwei.mianmi.account.shield.e.g;
import com.unikuwei.mianmi.account.shield.e.h;
import com.unikuwei.mianmi.account.shield.e.j;
import io.rong.imlib.filetransfer.download.BaseRequest;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
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;

public class b {
    /* JADX WARNING: Removed duplicated region for block: B:18:0x002e A[SYNTHETIC, Splitter:B:18:0x002e] */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x0033 A[Catch:{ Exception -> 0x0036 }] */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x003a A[SYNTHETIC, Splitter:B:28:0x003a] */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x003f A[Catch:{ Exception -> 0x0042 }] */
    private String a(InputStream inputStream) {
        ByteArrayOutputStream byteArrayOutputStream;
        Throwable th2;
        try {
            byteArrayOutputStream = new ByteArrayOutputStream();
            try {
                byte[] bArr = new byte[1024];
                while (true) {
                    int read = inputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr, 0, read);
                }
                String str = new String(byteArrayOutputStream.toByteArray());
                try {
                    byteArrayOutputStream.close();
                    inputStream.close();
                } catch (Exception unused) {
                }
                return str;
            } 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;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:25:0x0085  */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x008b  */
    public String a(String str, String str2) {
        Throwable th2;
        Exception e10;
        String str3 = "";
        if (Build.VERSION.SDK_INT < 21) {
            return str3;
        }
        HttpsURLConnection httpsURLConnection = null;
        try {
            HttpsURLConnection httpsURLConnection2 = (HttpsURLConnection) new URL(str).openConnection();
            try {
                httpsURLConnection2.setDoInput(true);
                httpsURLConnection2.setDoOutput(true);
                httpsURLConnection2.setUseCaches(false);
                httpsURLConnection2.setInstanceFollowRedirects(true);
                httpsURLConnection2.setReadTimeout(30000);
                httpsURLConnection2.setConnectTimeout(30000);
                httpsURLConnection2.setRequestMethod("POST");
                httpsURLConnection2.setHostnameVerifier(new HostnameVerifier() {
                    /* class com.unikuwei.mianmi.account.shield.d.b.AnonymousClass3 */

                    public boolean verify(String str, SSLSession sSLSession) {
                        if (!TextUtils.isEmpty(str)) {
                            return str.endsWith(".wostore.cn") || str.endsWith(".10010.com");
                        }
                        return false;
                    }
                });
                httpsURLConnection2.addRequestProperty("Connection", BaseRequest.CONNECTION_CLOSE);
                httpsURLConnection2.addRequestProperty("Content-Type", FastJsonJsonView.DEFAULT_CONTENT_TYPE);
                httpsURLConnection2.connect();
                DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection2.getOutputStream());
                if (str2 != null) {
                    dataOutputStream.write(str2.getBytes("UTF-8"));
                }
                dataOutputStream.flush();
                dataOutputStream.close();
                if (httpsURLConnection2.getResponseCode() == 200) {
                    str3 = a(httpsURLConnection2.getInputStream());
                }
                httpsURLConnection2.disconnect();
                return str3;
            } catch (Exception e11) {
                e10 = e11;
                httpsURLConnection = httpsURLConnection2;
                try {
                    e10.printStackTrace();
                    if (httpsURLConnection != null) {
                    }
                    return str3;
                } catch (Throwable th3) {
                    th2 = th3;
                    if (httpsURLConnection != null) {
                    }
                    throw th2;
                }
            } catch (Throwable th4) {
                th2 = th4;
                httpsURLConnection = httpsURLConnection2;
                if (httpsURLConnection != null) {
                    httpsURLConnection.disconnect();
                }
                throw th2;
            }
        } catch (Exception e12) {
            e10 = e12;
            e10.printStackTrace();
            if (httpsURLConnection != null) {
                httpsURLConnection.disconnect();
            }
            return str3;
        }
    }

    public String a(String str, HashMap<String, String> hashMap, Network network) {
        String str2;
        g.a("url:" + str);
        if (Build.VERSION.SDK_INT < 21) {
            return c(str, hashMap, network);
        }
        try {
            URL url = new URL(str);
            str2 = JPushConstants.HTTPS_PRE + url.getHost();
        } catch (MalformedURLException e10) {
            e10.printStackTrace();
            str2 = "";
        }
        h.c(str);
        try {
            URL url2 = new URL(str);
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2));
            httpsURLConnection.setDoInput(true);
            httpsURLConnection.setDoOutput(false);
            httpsURLConnection.setUseCaches(false);
            httpsURLConnection.setInstanceFollowRedirects(false);
            httpsURLConnection.setReadTimeout(30000);
            httpsURLConnection.setConnectTimeout(30000);
            httpsURLConnection.setRequestMethod("GET");
            httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
                /* class com.unikuwei.mianmi.account.shield.d.b.AnonymousClass1 */

                public boolean verify(String str, SSLSession sSLSession) {
                    if (!TextUtils.isEmpty(str)) {
                        return str.endsWith(".wostore.cn") || str.endsWith(".10010.com");
                    }
                    return false;
                }
            });
            if (hashMap != null) {
                for (String str3 : hashMap.keySet()) {
                    httpsURLConnection.setRequestProperty(str3, hashMap.get(str3));
                }
            }
            httpsURLConnection.addRequestProperty("Connection", str.startsWith("https://opencloud.wostore.cn/openapi/netauth/precheck/wp?") ? "Keep-Alive" : BaseRequest.CONNECTION_CLOSE);
            httpsURLConnection.connect();
            if (httpsURLConnection.getResponseCode() == 200) {
                String a10 = a(httpsURLConnection.getInputStream());
                if (!TextUtils.isEmpty(a10)) {
                    return a10;
                }
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("code", 10012);
                jSONObject.put("msg", "10012");
                jSONObject.put("data", str2);
                return jSONObject.toString();
            } else if (httpsURLConnection.getResponseCode() == 302) {
                String headerField = httpsURLConnection.getHeaderField("Location");
                if (!TextUtils.isEmpty(headerField)) {
                    return headerField.startsWith("https") ? a(headerField, null, network) : b(headerField, null, network);
                }
                JSONObject jSONObject2 = new JSONObject();
                jSONObject2.put("code", 10013);
                jSONObject2.put("msg", "无跳转地址");
                jSONObject2.put("data", str2);
                return jSONObject2.toString();
            } else {
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("code", 10010);
                jSONObject3.put("msg", "https状态码" + httpsURLConnection.getResponseCode());
                jSONObject3.put("data", str2);
                return jSONObject3.toString();
            }
        } catch (Exception e11) {
            e11.printStackTrace();
            try {
                JSONObject jSONObject4 = new JSONObject();
                jSONObject4.put("code", 10011);
                jSONObject4.put("msg", "https异常" + e11.getMessage());
                jSONObject4.put("data", str2);
                return jSONObject4.toString();
            } catch (Exception unused) {
                return null;
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:63:0x0194  */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x01a2  */
    public String b(String str, HashMap<String, String> hashMap, Network network) {
        String str2;
        Throwable th2;
        HttpURLConnection httpURLConnection;
        Exception e10;
        if (Build.VERSION.SDK_INT < 21) {
            try {
                if (j.a(UniAccountHelper.getInstance().getApplicationContext()) == 1) {
                    new d().a(UniAccountHelper.getInstance().getApplicationContext(), str);
                }
            } catch (Exception e11) {
                e11.printStackTrace();
            }
        }
        try {
            URL url = new URL(str);
            str2 = JPushConstants.HTTP_PRE + url.getHost();
        } catch (MalformedURLException e12) {
            e12.printStackTrace();
            str2 = str;
        }
        h.c(str);
        g.a(str);
        HttpURLConnection httpURLConnection2 = null;
        try {
            URL url2 = new URL(str);
            HttpURLConnection httpURLConnection3 = (HttpURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2));
            try {
                httpURLConnection3.setDoInput(true);
                httpURLConnection3.setDoOutput(false);
                httpURLConnection3.setUseCaches(false);
                httpURLConnection3.setInstanceFollowRedirects(false);
                httpURLConnection3.setReadTimeout(30000);
                httpURLConnection3.setConnectTimeout(30000);
                httpURLConnection3.setRequestMethod("GET");
                if (hashMap != null) {
                    for (String str3 : hashMap.keySet()) {
                        httpURLConnection3.setRequestProperty(str3, hashMap.get(str3));
                    }
                }
                httpURLConnection3.addRequestProperty("Connection", BaseRequest.CONNECTION_CLOSE);
                httpURLConnection3.connect();
                if (httpURLConnection3.getResponseCode() == 200) {
                    String a10 = a(httpURLConnection3.getInputStream());
                    if (TextUtils.isEmpty(a10)) {
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("code", 10012);
                        jSONObject.put("msg", "10012");
                        jSONObject.put("data", str2);
                        String jSONObject2 = jSONObject.toString();
                        httpURLConnection3.disconnect();
                        return jSONObject2;
                    }
                    httpURLConnection3.disconnect();
                    return a10;
                } else if (httpURLConnection3.getResponseCode() == 302) {
                    String headerField = httpURLConnection3.getHeaderField("Location");
                    if (TextUtils.isEmpty(headerField)) {
                        JSONObject jSONObject3 = new JSONObject();
                        jSONObject3.put("code", 10013);
                        jSONObject3.put("msg", "无跳转地址");
                        jSONObject3.put("data", str2);
                        String jSONObject4 = jSONObject3.toString();
                        httpURLConnection3.disconnect();
                        return jSONObject4;
                    } else if (headerField.startsWith("https")) {
                        String a11 = a(headerField, null, network);
                        httpURLConnection3.disconnect();
                        return a11;
                    } else {
                        String b10 = b(headerField, null, network);
                        httpURLConnection3.disconnect();
                        return b10;
                    }
                } else {
                    JSONObject jSONObject5 = new JSONObject();
                    jSONObject5.put("code", 10010);
                    jSONObject5.put("msg", "https状态码" + httpURLConnection3.getResponseCode());
                    jSONObject5.put("data", str2);
                    String jSONObject6 = jSONObject5.toString();
                    httpURLConnection3.disconnect();
                    return jSONObject6;
                }
            } catch (Exception e13) {
                httpURLConnection = httpURLConnection3;
                e10 = e13;
                try {
                    e10.printStackTrace();
                    try {
                        JSONObject jSONObject7 = new JSONObject();
                        jSONObject7.put("code", BaseConstants.ERR_SVR_GROUP_REQ_ALLREADY_BEEN_PROCESSED);
                        jSONObject7.put("msg", "http异常" + e10.getMessage());
                        jSONObject7.put("data", str2);
                        String jSONObject8 = jSONObject7.toString();
                        if (httpURLConnection != null) {
                            httpURLConnection.disconnect();
                        }
                        return jSONObject8;
                    } catch (Exception unused) {
                        if (httpURLConnection != null) {
                            httpURLConnection.disconnect();
                        }
                        return null;
                    }
                } catch (Throwable th3) {
                    th2 = th3;
                    httpURLConnection2 = httpURLConnection;
                    if (httpURLConnection2 != null) {
                    }
                    throw th2;
                }
            } catch (Throwable th4) {
                httpURLConnection2 = httpURLConnection3;
                th2 = th4;
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                throw th2;
            }
        } catch (Exception e14) {
            e10 = e14;
            httpURLConnection = null;
            e10.printStackTrace();
            JSONObject jSONObject72 = new JSONObject();
            jSONObject72.put("code", BaseConstants.ERR_SVR_GROUP_REQ_ALLREADY_BEEN_PROCESSED);
            jSONObject72.put("msg", "http异常" + e10.getMessage());
            jSONObject72.put("data", str2);
            String jSONObject82 = jSONObject72.toString();
            if (httpURLConnection != null) {
            }
            return jSONObject82;
        } catch (Throwable th5) {
            th2 = th5;
            if (httpURLConnection2 != null) {
            }
            throw th2;
        }
    }

    public String c(String str, HashMap<String, String> hashMap, Network network) {
        String str2;
        g.a("url:" + str);
        if (Build.VERSION.SDK_INT < 21) {
            try {
                if (j.a(UniAccountHelper.getInstance().getApplicationContext()) == 1) {
                    new d().a(UniAccountHelper.getInstance().getApplicationContext(), str);
                }
            } catch (Exception e10) {
                e10.printStackTrace();
            }
        }
        try {
            URL url = new URL(str);
            str2 = JPushConstants.HTTPS_PRE + url.getHost();
        } catch (MalformedURLException e11) {
            e11.printStackTrace();
            str2 = "";
        }
        h.c(str);
        try {
            SSLContext instance = SSLContext.getInstance("TLS");
            instance.init(null, null, new SecureRandom());
            c cVar = new c(instance.getSocketFactory());
            URL url2 = new URL(str);
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2));
            httpsURLConnection.setDoInput(true);
            httpsURLConnection.setDoOutput(false);
            httpsURLConnection.setUseCaches(false);
            httpsURLConnection.setInstanceFollowRedirects(false);
            httpsURLConnection.setReadTimeout(30000);
            httpsURLConnection.setConnectTimeout(30000);
            httpsURLConnection.setRequestMethod("GET");
            httpsURLConnection.setSSLSocketFactory(cVar);
            httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
                /* class com.unikuwei.mianmi.account.shield.d.b.AnonymousClass2 */

                public boolean verify(String str, SSLSession sSLSession) {
                    if (!TextUtils.isEmpty(str)) {
                        return str.endsWith(".wostore.cn") || str.endsWith(".10010.com");
                    }
                    return false;
                }
            });
            if (hashMap != null) {
                for (String str3 : hashMap.keySet()) {
                    httpsURLConnection.setRequestProperty(str3, hashMap.get(str3));
                }
            }
            httpsURLConnection.addRequestProperty("Connection", str.startsWith("https://opencloud.wostore.cn/openapi/netauth/precheck/wp?") ? "Keep-Alive" : BaseRequest.CONNECTION_CLOSE);
            httpsURLConnection.connect();
            if (httpsURLConnection.getResponseCode() == 200) {
                String a10 = a(httpsURLConnection.getInputStream());
                if (!TextUtils.isEmpty(a10)) {
                    return a10;
                }
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("code", 10012);
                jSONObject.put("msg", "10012");
                jSONObject.put("data", str2);
                return jSONObject.toString();
            } else if (httpsURLConnection.getResponseCode() == 302) {
                String headerField = httpsURLConnection.getHeaderField("Location");
                if (!TextUtils.isEmpty(headerField)) {
                    return headerField.startsWith("https") ? a(headerField, null, network) : b(headerField, null, network);
                }
                JSONObject jSONObject2 = new JSONObject();
                jSONObject2.put("code", 10013);
                jSONObject2.put("msg", "无跳转地址");
                jSONObject2.put("data", str2);
                return jSONObject2.toString();
            } else {
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("code", 10010);
                jSONObject3.put("msg", "https状态码" + httpsURLConnection.getResponseCode());
                jSONObject3.put("data", str2);
                return jSONObject3.toString();
            }
        } catch (Exception e12) {
            e12.printStackTrace();
            try {
                JSONObject jSONObject4 = new JSONObject();
                jSONObject4.put("code", 10011);
                jSONObject4.put("msg", "https异常" + e12.getMessage());
                jSONObject4.put("data", str2);
                return jSONObject4.toString();
            } catch (Exception unused) {
                return null;
            }
        }
    }
}