Ultra-SDP v1.0.0版本的 MD5 值为:5418115cd4b552c4cd79d6d68815af17

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


package com.cmic.sso.sdk.d;

import android.content.Context;
import android.net.Network;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import androidx.exifinterface.media.ExifInterface;
import cn.hutool.extra.servlet.ServletUtil;
import com.cmic.sso.sdk.auth.AuthnHelper;
import com.cmic.sso.sdk.b.a.d;
import com.cmic.sso.sdk.d.ad;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession;
import org.json.JSONException;
import org.json.JSONObject;
public class g {
    private static int a;
    private ad d;
    private Network e;
    private String g;
    private Bundle h;
    private int b = 1;
    private int c = -1;
    private boolean f = false;
    private String i = null;
    private String j = "";
    private String k = "";
    private String l = "";

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

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

    public <T extends com.cmic.sso.sdk.b.a.e> void a(String str, T t, boolean z, b bVar, String str2, String str3, Bundle bundle) {
        this.g = str3;
        this.h = bundle;
        m.c("HttpUtils", "使用wifi下取号???????" + z, bundle);
        if (z) {
            a(str, t, bVar, str2);
            return;
        }
        if (t instanceof com.cmic.sso.sdk.b.a.d) {
            a((com.cmic.sso.sdk.b.a.d) t);
        }
        a(str, t.b().toString(), bVar, null, str2);
    }

    public String a(String str, String str2, int i) {
        try {
            String c = c.a((Context) null).c(str);
            if (!TextUtils.isEmpty(c) && c.contains(",")) {
                String[] split = c.split(",");
                if (split.length > i && !TextUtils.isEmpty(split[i])) {
                    return split[i];
                }
            } else if (!TextUtils.isEmpty(c) && c.startsWith("http") && i == 0) {
                return c;
            } else {
                if (!TextUtils.isEmpty(c) && c.startsWith("https") && i == 1) {
                    return c;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str2;
    }

    private void a(com.cmic.sso.sdk.b.a.d dVar) {
        String a2 = w.a(0);
        String a3 = w.a(1);
        d.a d = dVar.d();
        if (!c.a((Context) null).g()) {
            d.t(a2);
        }
        if (!c.a((Context) null).h()) {
            d.u(a3);
        }
        d.s(d.v(this.h.getString("appkey")));
        dVar.a(d);
    }

    public void a(String str, String str2, b bVar, Network network, String str3) {
        String str4;
        long currentTimeMillis;
        HttpURLConnection httpURLConnection;
        BufferedReader bufferedReader;
        StringBuffer stringBuffer;
        String readLine;
        m.a("HttpUtils", "requestHttp2 url : " + str + ">>>>>>> PARAMS : " + str2);
        long currentTimeMillis2 = System.currentTimeMillis();
        AuthnHelper.getInstance(null).setRequestTime4TimeOut(currentTimeMillis2, this.j, this.k, this.l);
        try {
            m.c("HttpUtils", "http reqeust, url: " + str, this.h);
            URL url = new URL(str);
            if (Build.VERSION.SDK_INT >= 21 && network != null) {
                httpURLConnection = (HttpURLConnection) network.openConnection(url);
                m.c("HttpUtils", "is network null?不为空", this.h);
            } else {
                httpURLConnection = (HttpURLConnection) url.openConnection();
                m.c("HttpUtils", "is network null?为空", this.h);
            }
        } catch (Throwable th) {
            th = th;
            str4 = "HttpUtils";
        }
        try {
            if (str.startsWith("https")) {
                try {
                    if (!str.contains("uniConfig") && !str.contains("simQuickAuthReq") && !str.contains("simQuickAuthCheck")) {
                        if (str.contains("logReport") || str.contains("checkSdkVer")) {
                            str4 = "HttpUtils";
                        } else {
                            str4 = "HttpUtils";
                            try {
                                if (this.h.getString("authtype", "").equals(ExifInterface.GPS_MEASUREMENT_2D)) {
                                    a((HttpsURLConnection) httpURLConnection, a("M002", "https://smsks1.cmpassport.com/unisdk/", 1));
                                    httpURLConnection.setConnectTimeout(15000);
                                    httpURLConnection.setReadTimeout(19000);
                                    httpURLConnection.addRequestProperty("traceId", this.g);
                                    httpURLConnection.addRequestProperty("appid", com.cmic.sso.sdk.a.b);
                                    httpURLConnection.addRequestProperty("sdkVersion", AuthnHelper.SDK_VERSION);
                                    httpURLConnection.addRequestProperty("networktype", this.h.getInt("networktype", 0) + "");
                                    httpURLConnection.addRequestProperty("requestType", this.h.getString("requestType", ""));
                                    httpURLConnection.addRequestProperty("reqDevice", z.b());
                                    httpURLConnection.addRequestProperty("reqSystem", z.c());
                                    httpURLConnection.addRequestProperty("interfaceVersion", this.h.getString("interfaceVersion"));
                                    httpURLConnection.setUseCaches(false);
                                    httpURLConnection.setRequestProperty("Charset", "UTF-8");
                                    if (str.contains("preGetMobile")) {
                                        httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded ");
                                    } else {
                                        httpURLConnection.setRequestProperty("Content-Type", "application/json");
                                        httpURLConnection.setRequestProperty("Accept-Encoding", "");
                                    }
                                    httpURLConnection.setDoInput(true);
                                    httpURLConnection.setInstanceFollowRedirects(false);
                                    if (str3.equals(ServletUtil.METHOD_POST)) {
                                        httpURLConnection.setRequestMethod(ServletUtil.METHOD_POST);
                                        httpURLConnection.setDoOutput(true);
                                        httpURLConnection.connect();
                                        DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
                                        byte[] bytes = str2.getBytes("UTF-8");
                                        dataOutputStream.write(bytes, 0, bytes.length);
                                        dataOutputStream.flush();
                                        dataOutputStream.close();
                                    } else if (str3.equals(ServletUtil.METHOD_GET)) {
                                        httpURLConnection.setRequestMethod(ServletUtil.METHOD_GET);
                                        httpURLConnection.connect();
                                    }
                                    bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
                                    stringBuffer = new StringBuffer("");
                                    while (true) {
                                        readLine = bufferedReader.readLine();
                                        if (readLine != null) {
                                            stringBuffer.append(new String(readLine.getBytes(), "utf-8"));
                                        } else {
                                            String stringBuffer2 = stringBuffer.toString();
                                            bufferedReader.close();
                                            httpURLConnection.disconnect();
                                            this.c = httpURLConnection.getResponseCode();
                                            long currentTimeMillis3 = System.currentTimeMillis() - currentTimeMillis2;
                                            int i = this.c;
                                            a(stringBuffer2, i, bVar, httpURLConnection, network, str2, str, str3, currentTimeMillis3 + "");
                                            return;
                                        }
                                    }
                                }
                            } catch (Throwable th2) {
                                th = th2;
                                th.printStackTrace();
                                currentTimeMillis = System.currentTimeMillis() - currentTimeMillis2;
                                com.cmic.sso.sdk.a.h.add(th);
                                if (!(th instanceof SSLHandshakeException) || (th instanceof NoSuchAlgorithmException) || (th instanceof KeyManagementException) || (th instanceof CertificateException)) {
                                    m.c(str4, "发生CA认证异常", this.h);
                                    this.h.putBoolean("isNeedToGetCert", true);
                                    bVar.a("200072", "CA根证书认证失败", "", currentTimeMillis + "", "");
                                    return;
                                } else if (th instanceof EOFException) {
                                    int parseInt = Integer.parseInt("200050");
                                    a(null, parseInt, bVar, null, network, str2, str, str3, currentTimeMillis + "");
                                    return;
                                } else {
                                    int i2 = this.c;
                                    a(null, i2, bVar, null, network, str2, str, str3, currentTimeMillis + "");
                                    return;
                                }
                            }
                        }
                        if (!str.contains("logReport") && str.contains("updateNewKs") && this.h.getString("ksauthtype", "").equals(ExifInterface.GPS_MEASUREMENT_2D)) {
                            a((HttpsURLConnection) httpURLConnection, a("M002", "https://smsks1.cmpassport.com/unisdk/", 1));
                        } else if (!str.contains("logReport")) {
                            a((HttpsURLConnection) httpURLConnection, a("M004", "https://onekey1.cmpassport.com/unisdk/", 1));
                        } else if (str.contains("logReport")) {
                            a((HttpsURLConnection) httpURLConnection, a("M007", "https://log1.cmpassport.com:9443/log/logReport", 1));
                        }
                        httpURLConnection.setConnectTimeout(15000);
                        httpURLConnection.setReadTimeout(19000);
                        httpURLConnection.addRequestProperty("traceId", this.g);
                        httpURLConnection.addRequestProperty("appid", com.cmic.sso.sdk.a.b);
                        httpURLConnection.addRequestProperty("sdkVersion", AuthnHelper.SDK_VERSION);
                        httpURLConnection.addRequestProperty("networktype", this.h.getInt("networktype", 0) + "");
                        httpURLConnection.addRequestProperty("requestType", this.h.getString("requestType", ""));
                        httpURLConnection.addRequestProperty("reqDevice", z.b());
                        httpURLConnection.addRequestProperty("reqSystem", z.c());
                        httpURLConnection.addRequestProperty("interfaceVersion", this.h.getString("interfaceVersion"));
                        httpURLConnection.setUseCaches(false);
                        httpURLConnection.setRequestProperty("Charset", "UTF-8");
                        if (str.contains("preGetMobile")) {
                        }
                        httpURLConnection.setDoInput(true);
                        httpURLConnection.setInstanceFollowRedirects(false);
                        if (str3.equals(ServletUtil.METHOD_POST)) {
                        }
                        bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
                        stringBuffer = new StringBuffer("");
                        while (true) {
                            readLine = bufferedReader.readLine();
                            if (readLine != null) {
                            }
                            stringBuffer.append(new String(readLine.getBytes(), "utf-8"));
                        }
                    }
                } catch (Throwable th3) {
                    th = th3;
                    str4 = "HttpUtils";
                    th.printStackTrace();
                    currentTimeMillis = System.currentTimeMillis() - currentTimeMillis2;
                    com.cmic.sso.sdk.a.h.add(th);
                    if (!(th instanceof SSLHandshakeException)) {
                    }
                    m.c(str4, "发生CA认证异常", this.h);
                    this.h.putBoolean("isNeedToGetCert", true);
                    bVar.a("200072", "CA根证书认证失败", "", currentTimeMillis + "", "");
                    return;
                }
            }
            if (str3.equals(ServletUtil.METHOD_POST)) {
            }
            bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
            stringBuffer = new StringBuffer("");
            while (true) {
                readLine = bufferedReader.readLine();
                if (readLine != null) {
                }
                stringBuffer.append(new String(readLine.getBytes(), "utf-8"));
            }
        } catch (Throwable th4) {
            th = th4;
            th.printStackTrace();
            currentTimeMillis = System.currentTimeMillis() - currentTimeMillis2;
            com.cmic.sso.sdk.a.h.add(th);
            if (!(th instanceof SSLHandshakeException)) {
            }
            m.c(str4, "发生CA认证异常", this.h);
            this.h.putBoolean("isNeedToGetCert", true);
            bVar.a("200072", "CA根证书认证失败", "", currentTimeMillis + "", "");
            return;
        }
        str4 = "HttpUtils";
        httpURLConnection.setConnectTimeout(15000);
        httpURLConnection.setReadTimeout(19000);
        httpURLConnection.addRequestProperty("traceId", this.g);
        httpURLConnection.addRequestProperty("appid", com.cmic.sso.sdk.a.b);
        httpURLConnection.addRequestProperty("sdkVersion", AuthnHelper.SDK_VERSION);
        httpURLConnection.addRequestProperty("networktype", this.h.getInt("networktype", 0) + "");
        httpURLConnection.addRequestProperty("requestType", this.h.getString("requestType", ""));
        httpURLConnection.addRequestProperty("reqDevice", z.b());
        httpURLConnection.addRequestProperty("reqSystem", z.c());
        httpURLConnection.addRequestProperty("interfaceVersion", this.h.getString("interfaceVersion"));
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setRequestProperty("Charset", "UTF-8");
        if (str.contains("preGetMobile")) {
        }
        httpURLConnection.setDoInput(true);
        httpURLConnection.setInstanceFollowRedirects(false);
    }

    private void a(HttpsURLConnection httpsURLConnection, String str) throws Exception {
        m.b("HttpUtils", "cerByUrl = " + c.a((Context) null).d(str));
        if (c.a((Context) null).f() && !TextUtils.isEmpty(c.a((Context) null).d(str))) {
            m.b("HttpUtils", "initHostnameVerifier=" + str);
            httpsURLConnection.setSSLSocketFactory(new com.cmic.sso.sdk.b.c.a(this.h, str).a().getSocketFactory());
        }
        if (str.contains("logReport")) {
            return;
        }
        httpsURLConnection.setHostnameVerifier(new a(str));
    }

    protected <T extends com.cmic.sso.sdk.b.a.e> void a(String str, T t, b bVar, String str2) {
        m.b("HttpUtils", "in  wifiNetwork", this.h);
        this.d = ad.a((Context) null);
        long currentTimeMillis = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 21) {
            this.e = null;
            this.d.a(new ad.a() {
                @Override
                public void a(Network network) {
                    g.this.e = network;
                    m.b("HttpUtils", "onAvailable", g.this.h);
                }
            });
            int i = 0;
            while (this.e == null) {
                i++;
                SystemClock.sleep(50L);
                m.b("HttpUtils", "waiting for newtwork", this.h);
                if (i > 100) {
                    break;
                }
            }
            com.cmic.sso.sdk.a.j = ab.a();
            if (this.e == null) {
                a = 2;
                bVar.a("200024", "数据网络切换失败", "", (System.currentTimeMillis() - currentTimeMillis) + "", "");
                return;
            }
            a = 1;
            if (t instanceof com.cmic.sso.sdk.b.a.d) {
                a((com.cmic.sso.sdk.b.a.d) t);
            }
            a(str, t.b().toString(), bVar, this.e, str2);
            return;
        }
        a(str, t.b().toString(), bVar, null, str2);
    }

    private void a(String str, int i, b bVar, HttpURLConnection httpURLConnection, Network network, String str2, String str3, String str4, String str5) {
        String str6 = str;
        try {
            this.k += str5 + ";";
        } catch (Exception e) {
            e = e;
        }
        try {
            if (i == 302 || i == 301) {
                String headerField = httpURLConnection.getHeaderField("Location");
                if (this.i == null) {
                    this.i = httpURLConnection.getHeaderField("pplocation");
                }
                m.a("HttpUtils", "responseCode:" + i + "|location:" + headerField + "|ppLocation:" + this.i, this.h);
                if (!TextUtils.isEmpty(headerField)) {
                    if (headerField.contains("simQuickAuthReq")) {
                        a(headerField, "", bVar, network, ServletUtil.METHOD_POST);
                        return;
                    }
                    this.l += i + ";";
                    this.j = "preGetMobile;";
                    a(headerField, "", bVar, network, ServletUtil.METHOD_GET);
                } else if (this.h.getString("operatortype").equals(ExifInterface.GPS_MEASUREMENT_2D)) {
                    bVar.a("200091", "联通重定向失败", this.j, this.k, this.l);
                } else {
                    bVar.a("200038", "电信重定向失败", this.j, this.k, this.l);
                }
            } else if (i != 200) {
                m.a("HttpUtils", "http response code is not 200 ---" + i, this.h);
                this.b = this.b + 1;
                if (this.b <= 3 && !o.a(this.g)) {
                    this.l += i + ";";
                    a(str3, str2, bVar, network, str4);
                } else if (i == 0) {
                    bVar.a(i + "", "网络请求出错", this.j, this.k, this.l);
                } else if (i == Integer.valueOf("200050").intValue()) {
                    bVar.a("200050", "EOF异常", this.j, this.k, this.l);
                } else if (i == Integer.valueOf("200023").intValue()) {
                    bVar.a(i + "", str, this.j, this.k, this.l);
                } else {
                    bVar.a("200028", TextUtils.isEmpty(str) ? "网络请求出错" : str6, this.j, this.k, this.l);
                }
            } else if (!TextUtils.isEmpty(this.i)) {
                try {
                    m.b("HttpUtils", "电信取号结果 = " + str, this.h);
                    JSONObject jSONObject = new JSONObject(str);
                    if (!TextUtils.isEmpty(jSONObject.getString("result")) && "0".equals(jSONObject.getString("result"))) {
                        this.l += "0;";
                        this.i = null;
                        this.j += "getNewTelecomPhoneNumberNotify;";
                        a(a("M004", "http://www.cmpassport.com/unisdk/", 0) + this.i + "&data=" + jSONObject.getString("data"), "", bVar, network, ServletUtil.METHOD_GET);
                    } else if (this.h.getString("operatortype").equals(ExifInterface.GPS_MEASUREMENT_2D)) {
                        bVar.a("200092", "联通取号接口失败", this.j, this.k, this.l);
                    } else {
                        bVar.a("200039", "电信取号接口失败", this.j, this.k, this.l);
                    }
                } catch (JSONException e2) {
                    com.cmic.sso.sdk.a.h.add(e2);
                    if (this.h.getString("operatortype").equals(ExifInterface.GPS_MEASUREMENT_2D)) {
                        bVar.a("200092", "联通取号接口失败", this.j, this.k, this.l);
                    } else {
                        bVar.a("200039", "电信取号接口失败", this.j, this.k, this.l);
                    }
                }
            } else {
                AuthnHelper.getInstance(null).setRequestTime4TimeOut(0L, "", "", "");
                bVar.a(str, this.j, this.k, this.l);
            }
        } catch (Exception e3) {
            e = e3;
            com.cmic.sso.sdk.a.h.add(e);
            if (TextUtils.isEmpty(str)) {
                str6 = "网络请求出错";
            }
            bVar.a("200028", str6, this.j, this.k, this.l);
        }
    }

    public static class a implements HostnameVerifier {
        private String a;

        public a(String str) {
            this.a = null;
            this.a = str;
        }

        @Override
        public boolean verify(String str, SSLSession sSLSession) {
            m.b("HttpUtils", "---certificate host name: " + str);
            m.b("HttpUtils", "---server url: " + this.a);
            return !TextUtils.isEmpty(this.a) && this.a.contains(str);
        }
    }
}