思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c

以下内容为反编译后的 d.java 源代码,内容仅作参考


package com.cmic.sso.sdk.utils;

import android.content.Context;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import com.bumptech.glide.load.data.HttpUrlFetcher;
import com.cmic.sso.sdk.auth.AuthnHelper;
import com.cmic.sso.sdk.b.a.c;
import com.cmic.sso.sdk.utils.aa;
import com.huawei.hms.framework.common.ContainerUtils;
import com.sitech.oncon.weex.adapter.OkHttpAdapter;
import com.taobao.weex.el.parse.Operators;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStreamReader;
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;
import org.opencv.videoio.Videoio;
public class d {
    public Network a;
    public String b;
    public String c = "";
    public int d = 1;
    public String e = null;
    public Bundle f;

    public interface a {
        void a(String str, String str2);

        void a(String str, String str2, String str3);
    }

    public <T extends com.cmic.sso.sdk.b.a.f> void a(String str, T t, boolean z, a aVar, String str2, String str3, Bundle bundle) {
        this.f = bundle;
        this.b = str3;
        if (!i.a(str3) || str.contains("logReport") || str.contains("Config")) {
            f.c("HttpUtils", "使用wifi下取号???????" + z);
            if (z) {
                a(str, t, aVar, str2);
                return;
            }
            if (str.contains("getPrePhonescrip")) {
                a((com.cmic.sso.sdk.b.a.c) t, bundle);
            }
            a(str, t.a().toString(), aVar, null, str2);
        }
    }

    private void a(com.cmic.sso.sdk.b.a.c cVar, Bundle bundle) {
        String a2 = y.a(true);
        String a3 = y.a(true, "1".equals(bundle.getString("operatorType", "")));
        bundle.putString("ipv4_list", a2);
        bundle.putString("ipv6_list", a3);
        c.a b = cVar.b();
        if (!bundle.getBoolean("isCloseIpv4", false)) {
            b.a(a2);
        }
        if (!bundle.getBoolean("isCloseIpv6", false)) {
            b.b(a3);
        }
        b.t(b.u(bundle.getString("appkey")));
        cVar.a(b);
    }

    private void a(String str, String str2, a aVar, Network network, String str3) {
        Throwable th;
        BufferedReader bufferedReader;
        DataOutputStream dataOutputStream;
        HttpURLConnection httpURLConnection;
        DataOutputStream dataOutputStream2;
        int responseCode;
        BufferedReader bufferedReader2;
        if (i.a(this.b) && !str.contains("logReport") && !str.contains("Config")) {
            return;
        }
        DataOutputStream dataOutputStream3 = null;
        try {
            try {
                f.a("HttpUtils", "try " + this.d + " http reqeust, url: " + str);
                URL url = new URL(str);
                if (Build.VERSION.SDK_INT >= 21 && network != null) {
                    httpURLConnection = (HttpURLConnection) network.openConnection(url);
                    f.c("HttpUtils", "is network null?不为空");
                } else {
                    httpURLConnection = (HttpURLConnection) url.openConnection();
                    f.c("HttpUtils", "is network null?为空");
                }
                if (str.startsWith("https")) {
                    a((HttpsURLConnection) httpURLConnection, this.f, str);
                }
                httpURLConnection.setConnectTimeout(15000);
                httpURLConnection.setReadTimeout(Videoio.W3);
                httpURLConnection.addRequestProperty("traceId", this.b);
                if (this.f != null) {
                    httpURLConnection.addRequestProperty("appid", this.f.getString("appid", ""));
                    httpURLConnection.addRequestProperty("interfaceVersion", this.f.getString("interfaceVersion", ""));
                }
                httpURLConnection.addRequestProperty(b50.C, AuthnHelper.SDK_VERSION);
                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);
                    dataOutputStream2 = new DataOutputStream(httpURLConnection.getOutputStream());
                    try {
                        byte[] bytes = str2.getBytes("UTF-8");
                        dataOutputStream2.write(bytes, 0, bytes.length);
                        dataOutputStream2.flush();
                    } catch (Exception e) {
                        e = e;
                        dataOutputStream = dataOutputStream2;
                        bufferedReader = null;
                        try {
                            e.printStackTrace();
                            com.cmic.sso.sdk.c.a.a.add(e);
                            if (e instanceof SSLHandshakeException) {
                            }
                            if (e instanceof EOFException) {
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            dataOutputStream3 = dataOutputStream;
                            if (dataOutputStream3 != null) {
                                try {
                                    dataOutputStream3.close();
                                } catch (IOException e2) {
                                    com.cmic.sso.sdk.c.a.a.add(e2);
                                    e2.printStackTrace();
                                    throw th;
                                }
                            }
                            if (bufferedReader != null) {
                                bufferedReader.close();
                            }
                            throw th;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        bufferedReader = null;
                        dataOutputStream3 = dataOutputStream2;
                        th = th;
                        if (dataOutputStream3 != null) {
                        }
                        if (bufferedReader != null) {
                        }
                        throw th;
                    }
                } else {
                    try {
                        if (str3.equals(OkHttpAdapter.METHOD_GET)) {
                            httpURLConnection.setRequestMethod(OkHttpAdapter.METHOD_GET);
                        }
                        dataOutputStream2 = null;
                    } catch (Exception e3) {
                        e = e3;
                        bufferedReader = null;
                        dataOutputStream = null;
                        e.printStackTrace();
                        com.cmic.sso.sdk.c.a.a.add(e);
                        if (e instanceof SSLHandshakeException) {
                            this.f.putBoolean("isNeedToGetCert", true);
                            a(null, Integer.valueOf("200072").intValue(), aVar, null, network, str2, str, str3);
                        }
                        if (e instanceof EOFException) {
                            a(null, Integer.valueOf("200050").intValue(), aVar, null, network, str2, str, str3);
                            if (dataOutputStream != null) {
                                try {
                                    dataOutputStream.close();
                                } catch (IOException e4) {
                                    com.cmic.sso.sdk.c.a.a.add(e4);
                                    e4.printStackTrace();
                                    return;
                                }
                            }
                            if (bufferedReader != null) {
                                bufferedReader.close();
                                return;
                            }
                            return;
                        }
                        a(null, -1, aVar, null, network, str2, str, str3);
                        if (dataOutputStream != null) {
                            try {
                                dataOutputStream.close();
                            } catch (IOException e5) {
                                com.cmic.sso.sdk.c.a.a.add(e5);
                                e5.printStackTrace();
                                return;
                            }
                        }
                        if (bufferedReader != null) {
                            bufferedReader.close();
                            return;
                        }
                        return;
                    }
                }
                responseCode = httpURLConnection.getResponseCode();
                bufferedReader2 = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
            } catch (Exception e6) {
                e = e6;
            }
        } catch (Throwable th4) {
            th = th4;
            bufferedReader = null;
        }
        try {
            StringBuilder sb = new StringBuilder("");
            while (true) {
                String readLine = bufferedReader2.readLine();
                if (readLine == null) {
                    break;
                }
                sb.append(new String(readLine.getBytes(), "utf-8"));
            }
            String sb2 = sb.toString();
            if (dataOutputStream2 != null) {
                try {
                    dataOutputStream2.close();
                } catch (IOException e7) {
                    com.cmic.sso.sdk.c.a.a.add(e7);
                    e7.printStackTrace();
                }
            }
            bufferedReader2.close();
            a(sb2, responseCode, aVar, httpURLConnection, network, str2, str, str3);
        } catch (Exception e8) {
            e = e8;
            dataOutputStream = dataOutputStream2;
            bufferedReader = bufferedReader2;
            e.printStackTrace();
            com.cmic.sso.sdk.c.a.a.add(e);
            if (e instanceof SSLHandshakeException) {
            }
            if (e instanceof EOFException) {
            }
        } catch (Throwable th5) {
            th = th5;
            dataOutputStream3 = dataOutputStream2;
            bufferedReader = bufferedReader2;
            th = th;
            if (dataOutputStream3 != null) {
            }
            if (bufferedReader != null) {
            }
            throw th;
        }
    }

    public static void a(HttpsURLConnection httpsURLConnection, Bundle bundle, String str) {
        if (bundle.getBoolean("CLOSE_CERT_VERIFY", true) || str.contains("https://config.cmpassport.com/client/uniConfig")) {
            return;
        }
        httpsURLConnection.setSSLSocketFactory(new com.cmic.sso.sdk.b.c.a(bundle).a().getSocketFactory());
    }

    private <T extends com.cmic.sso.sdk.b.a.f> void a(String str, T t, a aVar, String str2) {
        f.b("HttpUtils", "in  wifiNetwork");
        aa a2 = aa.a((Context) null);
        int i = 0;
        if (Build.VERSION.SDK_INT >= 21) {
            this.a = null;
            a2.a(new aa.a() {
                @Override
                public void a(Network network) {
                    d.this.a = network;
                    f.b("HttpUtils", "onAvailable");
                }
            });
            while (this.a == null) {
                i++;
                SystemClock.sleep(50L);
                f.b("HttpUtils", "waiting for newtwork");
                if (i > 60) {
                    aVar.a("200024", "数据网络切换失败", this.c);
                    return;
                }
            }
            this.c = v.a();
            if (str.contains("getPrePhonescrip")) {
                a((com.cmic.sso.sdk.b.a.c) t, this.f);
            }
            a(str, t.a().toString(), aVar, this.a, str2);
            return;
        }
        aa.a.startUsingNetworkFeature(0, "enableHIPRI");
        while (i < 30) {
            try {
                if (aa.a.getNetworkInfo(5).getState().compareTo(NetworkInfo.State.CONNECTED) == 0) {
                    break;
                }
                SystemClock.sleep(1000L);
                i++;
            } catch (Exception e) {
                com.cmic.sso.sdk.c.a.a.add(e);
                f.a("HttpUtils", "check hipri failed");
                aVar.a("200024", "数据网络切换失败", this.c);
                return;
            }
        }
        boolean requestRouteToHost = aa.a.requestRouteToHost(5, aa.a(aa.b(str)));
        f.a("HttpUtils", "切换数据网络结果 >>> " + requestRouteToHost);
        if (requestRouteToHost) {
            f.a("HttpUtils", "切换网络成功");
            this.c = v.a();
            if (str.contains("getPrePhonescrip")) {
                a((com.cmic.sso.sdk.b.a.c) t, this.f);
            }
            a(str, t.a().toString(), aVar, null, str2);
            return;
        }
        f.a("HttpUtils", "切换网络失败or无数据网络");
        aVar.a("200024", "数据网络切换失败", this.c);
    }

    private void a(String str, int i, a aVar, HttpURLConnection httpURLConnection, Network network, String str2, String str3, String str4) {
        String str5;
        String str6;
        String str7 = str;
        try {
            if (i == 302 || i == 301) {
                String string = this.f.getString("interfacecode", "");
                this.f.putString("interfacecode", string + i + ";");
                String headerField = httpURLConnection.getHeaderField(HttpUrlFetcher.REDIRECT_HEADER_FIELD);
                f.b("HttpUtils", "Location head =" + headerField);
                if (this.e == null) {
                    this.e = httpURLConnection.getHeaderField("pplocation");
                }
                if (!TextUtils.isEmpty(headerField) && this.e != null) {
                    String string2 = this.f.getString("interfacetype", "");
                    if ("2".equals(this.f.getString("operatorType", "0"))) {
                        this.f.putString("interfacetype", string2 + "getUnicomMobile;");
                    } else {
                        this.f.putString("interfacetype", string2 + "getTelecomMobile;");
                    }
                    a(headerField, "", aVar, network, "POST");
                    return;
                }
                aVar.a("200021", "数据解析异常", this.c);
            } else if (i != 200) {
                f.a("HttpUtils", "http response code is not 200 ---" + i);
                this.d = this.d + 1;
                if (this.d > 3 || (i.a(this.b) && !str3.contains("logReport"))) {
                    if (i == 0) {
                        aVar.a(i + "", "请求出错", this.c);
                        return;
                    } else if (i == Integer.valueOf("200050").intValue()) {
                        aVar.a("200050", "EOF异常", this.c);
                        return;
                    } else if (i == Integer.valueOf("200072").intValue()) {
                        aVar.a("200072", "ca根证书校验失败", this.c);
                        return;
                    } else if (i == Integer.valueOf("102507").intValue()) {
                        aVar.a(i + "", str7, this.c);
                        return;
                    } else {
                        aVar.a("200028", TextUtils.isEmpty(str) ? "网络异常" : str7, this.c);
                        return;
                    }
                }
                a(str3, str2, aVar, network, str4);
            } else if (!TextUtils.isEmpty(this.e)) {
                try {
                    f.c("HttpUtils", "异网取号结果 = " + str7);
                    JSONObject jSONObject = new JSONObject(str7);
                    String optString = jSONObject.optString("result", "0");
                    String string3 = this.f.getString("interfacecode", "");
                    this.f.putString("interfacecode", string3 + optString + ";");
                    if (!TextUtils.isEmpty(jSONObject.getString("result")) && "0".equals(jSONObject.getString("result"))) {
                        f.c("HttpUtils", "pplocation=" + this.e);
                        String substring = this.e.substring(this.e.indexOf(Operators.CONDITION_IF_STRING) + 1);
                        JSONObject jSONObject2 = new JSONObject();
                        jSONObject2.put(substring.split(ContainerUtils.KEY_VALUE_DELIMITER)[0], substring.split(ContainerUtils.KEY_VALUE_DELIMITER)[1]);
                        jSONObject2.put("data", str7);
                        this.e = this.e.substring(1, this.e.lastIndexOf(Operators.CONDITION_IF_STRING));
                        String str8 = "http://onekey.cmpassport.com/unisdk/" + this.e;
                        String string4 = this.f.getString("interfacetype", "");
                        this.f.putString("interfacetype", string4 + "getNewTelecomPhoneNumberNotify;");
                        this.e = null;
                        f.c("HttpUtils", "location" + str8);
                        a(str8, jSONObject2.toString(), aVar, network, "POST");
                    } else {
                        str5 = "取号接口失败";
                        str6 = "200039";
                        try {
                            aVar.a(str6, str5, this.c);
                        } catch (JSONException e) {
                            e = e;
                            com.cmic.sso.sdk.c.a.a.add(e);
                            aVar.a(str6, str5, this.c);
                        }
                    }
                } catch (JSONException e2) {
                    e = e2;
                    str5 = "取号接口失败";
                    str6 = "200039";
                }
            } else {
                aVar.a(str7, this.c);
            }
        } catch (Exception e3) {
            com.cmic.sso.sdk.c.a.a.add(e3);
            if (TextUtils.isEmpty(str)) {
                str7 = "网络异常";
            }
            aVar.a("200028", str7, this.c);
        }
    }
}