CarrotChat v2.8.80.240429版本的 MD5 值为:fdf98761f01e715a89df24b85b0d206e

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


package com.kinggrid.commonrequestauthority;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.util.SparseArray;
import com.kinggrid.iapppdf.droids.mupdf.codec.cosobject.PdfBoolean;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;

class b extends AppRegister {
    private static String G;
    private static String J;
    private static String K;
    private static File N;

    private static b f27367ae;
    private String H;
    private String I;
    private l L;
    private String M;
    private String O = "";
    private String P = "";
    private String Q = "";
    private String R = "";
    private String S = "";
    private String T = "0";
    private String U = "http://www.kinggrid.com:8080/iWebRegister/register/app2Register.htm?os=1&UUID=";
    private String V = "http://www.kinggrid.com:8080/iWebRegister/register/app2RegisterVerify.htm?os=1&UUID=";
    private boolean W = true;
    private boolean X = true;
    private String Y;
    private String Z;

    private String f27368aa;

    private String f27369ab;

    private String f27370ac;

    private boolean f27371ad;

    private b(Context context, String str, String str2, String str3, String str4, String str5, String str6) {
        this.f27369ab = "";
        this.H = f.a(context);
        this.Y = f.b(context);
        this.Z = f.d(context);
        this.f27368aa = f.c(context);
        this.I = str5;
        if (!TextUtils.isEmpty(str)) {
            G = str;
        }
        if (!TextUtils.isEmpty(str2)) {
            AppRegister.licFilePath = str2;
        }
        if (!TextUtils.isEmpty(str3)) {
            J = str3;
        }
        if (!TextUtils.isEmpty(str4)) {
            K = str4;
        }
        if (!TextUtils.isEmpty(str6)) {
            this.f27369ab = str6;
        }
        a();
    }

    public static b a(Context context, String str, String str2, String str3, String str4, String str5, String str6) {
        if (f27367ae == null || !G.equals(str) || !J.equals(str3)) {
            f27367ae = new b(context, str, str2, str3, str4, str5, str6);
        }
        return f27367ae;
    }

    private SparseArray<String> b() {
        if (AppRegister.DEBUG) {
            Log.v(AppRegister.TAG, "file.exists()==" + N.exists());
        }
        if (N.exists()) {
            l lVar = this.L;
            if (lVar != null) {
                if (J.equalsIgnoreCase(lVar.j()) && this.P.equals(this.L.g())) {
                    if (AppRegister.DEBUG) {
                        Log.v(AppRegister.TAG, "解码成功:" + J + "---" + this.L.j() + ",and licType is " + this.P + "---" + this.L.g());
                    }
                    return d();
                }
                if (AppRegister.DEBUG) {
                    Log.v(AppRegister.TAG, "file.exists,and responceLic is not null,but match failed: productTypeValue is " + J + "---" + this.L.j() + ",and licType is " + this.P + "---" + this.L.g());
                }
            } else if (AppRegister.DEBUG) {
                Log.v(AppRegister.TAG, "file.exists,but responceLic is null ");
            }
            return c();
        }
        return c();
    }

    private SparseArray<String> c() {
        SparseArray<String> sparseArray = new SparseArray<>();
        int a10 = f.a() ? a(false, false) : 106;
        StringBuilder sb2 = new StringBuilder(String.valueOf("" + getAuthorizationType(this.P) + ","));
        sb2.append(this.S);
        sb2.append(",");
        String sb3 = sb2.toString();
        if (a10 == 200) {
            sb3 = String.valueOf(sb3) + this.validTime;
        } else if (a10 == 201) {
            sb3 = String.valueOf(sb3) + this.validTime;
        } else if (a10 == 300) {
            sb3 = String.valueOf(sb3) + this.M;
        }
        if (AppRegister.DEBUG) {
            Log.v(AppRegister.TAG, "doAppRegister_hasLicCode_and_noLicFile(),code==" + a10 + ",value==" + sb3);
        }
        sparseArray.put(a10, sb3);
        return sparseArray;
    }

    private SparseArray<String> d() {
        int i10;
        String str;
        SparseArray<String> sparseArray = new SparseArray<>();
        if (this.L != null) {
            i10 = d(this.P);
            if (AppRegister.DEBUG) {
                Log.v(AppRegister.TAG, "doAppRegister_hasLicCode_and_hasLicFile,code_key==" + i10);
            }
            String str2 = "";
            if (i10 != 113) {
                if (i10 == 300) {
                    str2 = this.M;
                } else if (i10 == 200) {
                    str = String.valueOf(String.valueOf("" + getAuthorizationType(this.P) + ",") + f.b(this.L.d()) + ",") + this.validTime;
                } else if (i10 == 201) {
                    str = String.valueOf(String.valueOf("" + getAuthorizationType(this.P) + ",") + f.b(this.L.d()) + ",") + this.validTime;
                }
                str = str2;
            } else {
                str = String.valueOf(String.valueOf("" + getAuthorizationType(this.P) + ",") + f.b(this.L.d()) + ",") + this.validTime;
            }
        } else {
            if (AppRegister.DEBUG) {
                Log.v(AppRegister.TAG, "doAppRegister_hasLicCode_and_hasLicFile() responceLic is null");
            }
            i10 = 109;
            str = "本地授权文件异常,请手动删除后再操作!";
        }
        sparseArray.put(i10, str);
        return sparseArray;
    }

    private boolean e() {
        l lVar = this.L;
        if (lVar == null) {
            return false;
        }
        try {
            this.W = lVar.d().trim().equals(this.O.trim());
            boolean c10 = c(this.L.e().trim());
            this.X = c10;
            if (!this.W) {
                Log.v(AppRegister.TAG, "File companySn:" + this.L.d().trim() + "==App companySn:" + this.O.trim());
            } else if (!c10) {
                Log.v(AppRegister.TAG, "File hardSn:" + this.L.e().trim() + "==App hardSn:" + this.H.trim());
            }
            if (!this.W) {
                return false;
            }
            if (!this.X) {
                return false;
            }
            return true;
        } catch (Exception e10) {
            Log.v(AppRegister.TAG, "checkCompanyIsOK failed,error info:" + e10.toString());
            return false;
        }
    }

    private int f() {
        if (a(false)) {
            long j10 = this.validTime;
            if (j10 <= 30 && j10 != -1) {
                if (!this.f27371ad) {
                    this.f27371ad = true;
                    if (f.a()) {
                        return a(false, true);
                    }
                    return 113;
                }
                return 200;
            }
            return 201;
        }
        if (this.validTime == -10000) {
            return 111;
        }
        if (this.W && this.X) {
            if (f.a()) {
                return a(false, true);
            }
            return 112;
        }
        return 105;
    }

    private int g() {
        if (e()) {
            this.validTime = -1L;
            return 201;
        }
        return 105;
    }

    @Override
    protected SparseArray<String> doInBackground(Void... voidArr) {
        if (!TextUtils.isEmpty(G)) {
            if (AppRegister.DEBUG) {
                Log.v(AppRegister.TAG, "doAppRegister(...) has licCode");
            }
            return a(G);
        }
        SparseArray<String> sparseArray = new SparseArray<>();
        sparseArray.put(107, "");
        return sparseArray;
    }

    private void a() {
        File file = new File(AppRegister.licFilePath);
        N = file;
        if (file.exists()) {
            this.L = f.a(f.a(N), true, J);
        }
    }

    private SparseArray<String> a(String str) {
        Document a10;
        SparseArray<String> sparseArray = new SparseArray<>();
        try {
            String b10 = h.b(str, k.f27392b, 0);
            if (!TextUtils.isEmpty(b10) && (a10 = o.a().a(b10)) != null) {
                String text = a10.selectSingleNode("/k/b/csn").getText();
                this.O = text;
                this.S = f.b(text);
                this.P = a10.selectSingleNode("/k/p[pc=" + J + "]/pt").getText();
                this.R = a10.selectSingleNode("/k/p[pc=" + J + "]/ed").getText();
                this.Q = J;
                K = this.P;
                this.f27370ac = a10.selectSingleNode("/k/p[pc=" + J + "]/ssn").getText();
            }
        } catch (Exception e10) {
            Log.e(AppRegister.TAG, "doAppRegister_hasLicCode(...) error:" + e10.toString());
        }
        if (AppRegister.DEBUG) {
            Log.v(AppRegister.TAG, "licType:" + this.P + ",expireDate:" + this.R + ",companyName:" + this.S);
        }
        int i10 = 110;
        String str2 = "";
        if (!TextUtils.isEmpty(this.P)) {
            StringBuilder sb2 = new StringBuilder(String.valueOf("" + getAuthorizationType(this.P) + ","));
            sb2.append(this.S);
            sb2.append(",");
            str2 = sb2.toString();
            if (this.P.equals("2")) {
                i10 = 202;
            } else if (this.P.equals("3")) {
                long a11 = f.a(this.R.replaceAll("-", CookieSpec.PATH_DELIM), f.a(k.f27393c));
                if (AppRegister.DEBUG) {
                    Log.v(AppRegister.TAG, "validDays:" + a11);
                }
                if (a11 >= 1 || this.validTime == -1) {
                    this.validTime = a11;
                    i10 = (a11 > 30 || a11 == -1) ? 201 : 200;
                    str2 = String.valueOf(str2) + this.validTime;
                } else {
                    i10 = 100;
                }
            } else {
                if (this.P.equals("1")) {
                    return b();
                }
                if (this.P.equals("0")) {
                    if (!TextUtils.isEmpty(this.f27370ac)) {
                        if (AppRegister.DEBUG) {
                            Log.i(AppRegister.TAG, "唯一码不为空,可能执行离线授权");
                        }
                        return a(this.f27370ac, this.S);
                    }
                    if (AppRegister.DEBUG) {
                        Log.i(AppRegister.TAG, "永久许可,唯一码为空,走正常授权流程");
                    }
                    return b();
                }
            }
        }
        sparseArray.put(i10, str2);
        return sparseArray;
    }

    private boolean c(String str) {
        if (str == null) {
            return false;
        }
        boolean equals = str.equals(this.Y);
        if (!equals) {
            equals = str.equals(this.Z);
        }
        return !equals ? str.equals(this.f27368aa) : equals;
    }

    private int d(String str) {
        if (str.equals("1")) {
            return f();
        }
        if (str.equals("0")) {
            return g();
        }
        if (!AppRegister.DEBUG) {
            return 0;
        }
        Log.v(AppRegister.TAG, "doAppRegister_hasLicCode_and_hasLicFile_and_hasLicType is other");
        return 0;
    }

    private String b(String str) {
        try {
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setConnectTimeout(3000);
            httpURLConnection.setReadTimeout(5000);
            return f.a(httpURLConnection.getInputStream());
        } catch (Exception e10) {
            Log.e(AppRegister.TAG, "requestAuthority(...) error:" + e10.toString());
            return null;
        }
    }

    @SuppressLint({"NewApi"})
    private SparseArray<String> a(String str, String str2) {
        String str3;
        SparseArray<String> sparseArray = new SparseArray<>();
        String str4 = "";
        int i10 = 301;
        if (TextUtils.isEmpty(str)) {
            str4 = "离线授权唯一码为空";
        } else if (TextUtils.isEmpty(this.f27369ab)) {
            str4 = "离线授权服务器地址为空";
        } else {
            try {
                str3 = b(String.valueOf(this.f27369ab) + "?username=" + Base64.encodeToString(str2.getBytes("UTF-8"), 2));
            } catch (UnsupportedEncodingException e10) {
                Log.e(AppRegister.TAG, "doOffLineAuth:" + e10.toString());
                str3 = "";
            }
            if (TextUtils.isEmpty(str3)) {
                str4 = "离线授权服务器返回数据为空,请检查网络后重试";
            } else if (str.equals(str3)) {
                i10 = 203;
            } else {
                if (AppRegister.DEBUG) {
                    Log.i(AppRegister.TAG, "不匹配:" + str + "===" + str3);
                }
                str4 = "离线授权检测不通过";
            }
        }
        sparseArray.put(i10, str4);
        return sparseArray;
    }

    private int a(boolean z10, boolean z11) {
        String a10;
        if (AppRegister.DEBUG) {
            Log.d(AppRegister.TAG, "hardSn = " + this.H + ", androidId = " + this.f27368aa);
        }
        String a11 = a(PdfBoolean.TRUE, "false");
        if (AppRegister.DEBUG) {
            Log.i(AppRegister.TAG, "判断是否注册过,result = " + a11);
        }
        if (a11.equals(PdfBoolean.TRUE)) {
            a10 = a("false", PdfBoolean.TRUE);
        } else {
            a10 = a("false", "false");
        }
        if (a10.equals(PdfBoolean.TRUE)) {
            return a(false, 102);
        }
        if (z10) {
            Log.i(AppRegister.TAG, "failed:" + a10 + ",and read the local file.");
            return a(false, 103);
        }
        this.M = a10;
        return 300;
    }

    private String a(String... strArr) {
        String str;
        String str2;
        String b10;
        int i10;
        String str3 = PdfBoolean.TRUE;
        new c().a(c.f27372a);
        try {
            n nVar = new n();
            nVar.a("2.0");
            nVar.g("WDDSED12KINGGRID");
            nVar.b(this.O);
            if (!strArr[0].equals(PdfBoolean.TRUE) && !strArr[1].equals(PdfBoolean.TRUE)) {
                nVar.c(c.a(this.H.getBytes("UTF-8")));
                nVar.p("1");
                nVar.h(c.a(this.I.getBytes("UTF-8")));
                nVar.i(f.a("yyyyMMddHHmmsss"));
                nVar.j(J);
                nVar.k(K);
                nVar.l(this.T);
                str = new String(h.a(o.a().a(nVar), k.f27391a, 0), "UTF-8");
                str2 = String.valueOf(!strArr[0].equals(PdfBoolean.TRUE) ? this.V : this.U) + f.a("yyyyMMddHHmmsss");
                b10 = f.b(str, str2, "requestStr=");
                for (i10 = 0; i10 < 10 && TextUtils.isEmpty(b10); i10++) {
                    b10 = f.b(str, str2, "requestStr=");
                    try {
                        Thread.sleep(1000L);
                    } catch (InterruptedException unused) {
                    }
                }
                if (!TextUtils.isEmpty(b10)) {
                    return "服务器返回注册数据为空";
                }
                l lVar = new l(b10, true, J);
                this.L = lVar;
                try {
                    if (lVar.b().equals("1")) {
                        if (AppRegister.DEBUG) {
                            Log.v(AppRegister.TAG, "注册成功!过期日期:" + this.L.i());
                        }
                        if (!strArr[0].equals("false")) {
                            return PdfBoolean.TRUE;
                        }
                        if (!new File(AppRegister.licFilePath).exists()) {
                            f.a(AppRegister.licFilePath, b10.getBytes("UTF-8"));
                            return PdfBoolean.TRUE;
                        }
                        String b11 = h.b(f.a(new File(AppRegister.licFilePath)), k.f27391a, 0);
                        if (b11 == null) {
                            f.a(AppRegister.licFilePath, b10.getBytes("UTF-8"));
                            return PdfBoolean.TRUE;
                        }
                        Document a10 = o.a().a(b11);
                        Node selectSingleNode = a10.selectSingleNode("/ks/k/rp[rpc=" + this.Q + "]");
                        if (selectSingleNode != null) {
                            selectSingleNode.selectSingleNode("rt").setText(this.L.g());
                            selectSingleNode.getParent().selectSingleNode("rr/rd").setText(this.L.h());
                            selectSingleNode.getParent().selectSingleNode("rr/ed").setText(this.L.i());
                        } else {
                            a10.getRootElement().add((Element) o.a().a(h.b(b10, k.f27391a, 0)).selectSingleNode("/ks/k").clone());
                        }
                        f.a(AppRegister.licFilePath, h.a(a10.asXML(), k.f27391a, 0));
                        return PdfBoolean.TRUE;
                    }
                    String c10 = this.L.c();
                    Log.e(AppRegister.TAG, "注册失败!错误信息:" + this.L.c());
                    return c10;
                } catch (UnsupportedEncodingException e10) {
                    e = e10;
                    e.printStackTrace();
                    return str3;
                } catch (Exception e11) {
                    e = e11;
                    e.printStackTrace();
                    return str3;
                }
            }
            nVar.c(c.a(this.f27368aa.getBytes("UTF-8")));
            nVar.p("1");
            nVar.h(c.a(this.I.getBytes("UTF-8")));
            nVar.i(f.a("yyyyMMddHHmmsss"));
            nVar.j(J);
            nVar.k(K);
            nVar.l(this.T);
            str = new String(h.a(o.a().a(nVar), k.f27391a, 0), "UTF-8");
            str2 = String.valueOf(!strArr[0].equals(PdfBoolean.TRUE) ? this.V : this.U) + f.a("yyyyMMddHHmmsss");
            b10 = f.b(str, str2, "requestStr=");
            while (i10 < 10) {
                b10 = f.b(str, str2, "requestStr=");
                Thread.sleep(1000L);
            }
            if (!TextUtils.isEmpty(b10)) {
            }
        } catch (UnsupportedEncodingException e12) {
            e = e12;
            str3 = "";
        } catch (Exception e13) {
            e = e13;
            str3 = "";
        }
    }

    private int a(boolean z10, int i10) {
        if (a(z10)) {
            long j10 = this.validTime;
            return (j10 > 30 || j10 == -1) ? 201 : 200;
        }
        if (this.validTime == -10000) {
            return 111;
        }
        return i10;
    }

    private boolean a(boolean z10) {
        if ((!z10 && !e()) || this.L == null) {
            return false;
        }
        String a10 = f.a(k.f27393c);
        String a11 = f.a(this.L, this.P);
        String b10 = f.b(this.L, this.P);
        if (AppRegister.DEBUG) {
            Log.v(AppRegister.TAG, "currentTime" + a10 + "====xmlTime:" + a11 + "regTime = " + b10);
        }
        if (a11.equals(PdfBoolean.TRUE)) {
            this.validTime = -1L;
        } else {
            long a12 = f.a(a11, a10, b10);
            if (a12 == -10000) {
                this.validTime = -10000L;
            }
            if (AppRegister.DEBUG) {
                Log.v(AppRegister.TAG, "validDays:" + a12);
            }
            if (a12 < 1) {
                return false;
            }
            this.validTime = a12;
        }
        return true;
    }
}