package com.common.uitl;

import androidx.exifinterface.media.ExifInterface;
import com.common.net.NetResult;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;
import okhttp3.internal.cache.DiskLruCache;

/* loaded from: classes.dex */
public class IdcardValidator {
    private String[][] codeAndCity = {new String[]{"11", "北京"}, new String[]{"12", "天津"}, new String[]{"13", "河北"}, new String[]{"14", "山西"}, new String[]{"15", "内蒙古"}, new String[]{"21", "辽宁"}, new String[]{"22", "吉林"}, new String[]{"23", "黑龙江"}, new String[]{"31", "上海"}, new String[]{"32", "江苏"}, new String[]{"33", "浙江"}, new String[]{"34", "安徽"}, new String[]{"35", "福建"}, new String[]{"36", "江西"}, new String[]{"37", "山东"}, new String[]{"41", "河南"}, new String[]{"42", "湖北"}, new String[]{"43", "湖南"}, new String[]{"44", "广东"}, new String[]{"45", "广西"}, new String[]{"46", "海南"}, new String[]{"50", "重庆"}, new String[]{"51", "四川"}, new String[]{"52", "贵州"}, new String[]{"53", "云南"}, new String[]{"54", "西藏"}, new String[]{"61", "陕西"}, new String[]{"62", "甘肃"}, new String[]{"63", "青海"}, new String[]{"64", "宁夏"}, new String[]{"65", "新疆"}, new String[]{"71", "台湾"}, new String[]{"81", "香港"}, new String[]{"82", "澳门"}, new String[]{"91", "国外"}};
    private String[] cityCode = {"11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41", "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71", "81", "82", "91"};
    private int[] power = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    private String[] verifyCode = {DiskLruCache.VERSION_1, NetResult.CODE_OK, "X", "9", "8", "7", "6", "5", "4", ExifInterface.GPS_MEASUREMENT_3D, ExifInterface.GPS_MEASUREMENT_2D};

    public boolean isValidatedAllIdcard(String str) {
        if (str.length() == 15) {
            str = convertIdcarBy15bit(str);
        }
        return isValidate18Idcard(str);
    }

    private boolean isValidate18Idcard(String str) {
        String checkCodeBySum;
        if (str.length() != 18) {
            return false;
        }
        String substring = str.substring(0, 17);
        String substring2 = str.substring(17, 18);
        if (!isDigital(substring)) {
            return false;
        }
        char[] charArray = substring.toCharArray();
        if (charArray == null) {
            return true;
        }
        int[] iArr = new int[substring.length()];
        int powerSum = getPowerSum(converCharToInt(charArray));
        return (powerSum == 0 || (checkCodeBySum = getCheckCodeBySum(powerSum)) == null || !substring2.equalsIgnoreCase(checkCodeBySum)) ? false : true;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to find 'out' block for switch in B:24:0x009a. Please report as an issue. */
    /* JADX WARN: Removed duplicated region for block: B:28:0x00c3 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean isValidate15Idcard(java.lang.String r12) {
        /*
            r11 = this;
            int r0 = r12.length()
            r1 = 15
            r2 = 0
            if (r0 == r1) goto La
            return r2
        La:
            boolean r0 = r11.isDigital(r12)
            if (r0 == 0) goto Lc8
            r0 = 2
            java.lang.String r1 = r12.substring(r2, r0)
            r3 = 6
            r4 = 12
            java.lang.String r5 = r12.substring(r3, r4)
            r6 = 8
            java.lang.String r3 = r12.substring(r3, r6)
            java.lang.String r3 = r3.trim()
            int r3 = java.lang.Integer.parseInt(r3)
            r7 = 10
            java.lang.String r6 = r12.substring(r6, r7)
            java.lang.String r6 = r6.trim()
            int r6 = java.lang.Integer.parseInt(r6)
            java.lang.String r12 = r12.substring(r7, r4)
            java.lang.String r12 = r12.trim()
            int r12 = java.lang.Integer.parseInt(r12)
            java.lang.String[] r7 = r11.cityCode
            int r8 = r7.length
            r9 = r2
        L48:
            if (r9 >= r8) goto Lc8
            r10 = r7[r9]
            boolean r10 = r10.equals(r1)
            if (r10 == 0) goto Lc5
            java.text.SimpleDateFormat r1 = new java.text.SimpleDateFormat     // Catch: java.text.ParseException -> L5e
            java.lang.String r7 = "yyMMdd"
            r1.<init>(r7)     // Catch: java.text.ParseException -> L5e
            java.util.Date r1 = r1.parse(r5)     // Catch: java.text.ParseException -> L5e
            goto L63
        L5e:
            r1 = move-exception
            r1.printStackTrace()
            r1 = 0
        L63:
            if (r1 == 0) goto Lc4
            java.util.Date r5 = new java.util.Date
            r5.<init>()
            boolean r5 = r5.before(r1)
            if (r5 == 0) goto L71
            goto Lc4
        L71:
            java.util.GregorianCalendar r5 = new java.util.GregorianCalendar
            r5.<init>()
            r7 = 1
            int r8 = r5.get(r7)
            java.lang.String r8 = java.lang.String.valueOf(r8)
            java.lang.String r0 = r8.substring(r0)
            java.lang.String r0 = r0.trim()
            int r0 = java.lang.Integer.parseInt(r0)
            r8 = 50
            if (r3 >= r8) goto L92
            if (r3 <= r0) goto L92
            return r2
        L92:
            if (r6 < r7) goto Lc4
            if (r6 <= r4) goto L97
            goto Lc4
        L97:
            r5.setTime(r1)
            switch(r6) {
                case 1: goto Lbd;
                case 2: goto La5;
                case 3: goto Lbd;
                case 4: goto L9e;
                case 5: goto Lbd;
                case 6: goto L9e;
                case 7: goto Lbd;
                case 8: goto Lbd;
                case 9: goto L9e;
                case 10: goto Lbd;
                case 11: goto L9e;
                case 12: goto Lbd;
                default: goto L9d;
            }
        L9d:
            goto Lc4
        L9e:
            if (r12 < r7) goto Lc4
            r0 = 30
            if (r12 > r0) goto Lc4
            goto Lc3
        La5:
            int r0 = r5.get(r7)
            boolean r0 = r5.isLeapYear(r0)
            if (r0 == 0) goto Lb6
            if (r12 < r7) goto Lc4
            r0 = 29
            if (r12 > r0) goto Lc4
            goto Lc3
        Lb6:
            if (r12 < r7) goto Lc4
            r0 = 28
            if (r12 > r0) goto Lc4
            goto Lc3
        Lbd:
            if (r12 < r7) goto Lc4
            r0 = 31
            if (r12 > r0) goto Lc4
        Lc3:
            return r7
        Lc4:
            return r2
        Lc5:
            int r9 = r9 + 1
            goto L48
        Lc8:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.common.uitl.IdcardValidator.isValidate15Idcard(java.lang.String):boolean");
    }

    private String convertIdcarBy15bit(String str) {
        Date date;
        if (str.length() != 15 || !isDigital(str)) {
            return null;
        }
        try {
            date = new SimpleDateFormat("yyMMdd").parse(str.substring(6, 12));
        } catch (ParseException e) {
            e.printStackTrace();
            date = null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        String str2 = str.substring(0, 6) + String.valueOf(calendar.get(1)) + str.substring(8);
        char[] charArray = str2.toCharArray();
        if (charArray == null) {
            return str2;
        }
        int[] iArr = new int[str2.length()];
        String checkCodeBySum = getCheckCodeBySum(getPowerSum(converCharToInt(charArray)));
        if (checkCodeBySum == null) {
            return null;
        }
        return str2 + checkCodeBySum;
    }

    private boolean isIdcard(String str) {
        if (str == null || "".equals(str)) {
            return false;
        }
        return Pattern.matches("(^\\d{15}$)|(\\d{17}(?:\\d|x|X)$)", str);
    }

    public boolean is15Idcard(String str) {
        if (str == null || "".equals(str)) {
            return false;
        }
        return Pattern.matches("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$", str);
    }

    public boolean is18Idcard(String str) {
        return Pattern.matches("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([\\d|x|X]{1})$", str);
    }

    private boolean isDigital(String str) {
        if (str == null || "".equals(str)) {
            return false;
        }
        return str.matches("^[0-9]*$");
    }

    private int getPowerSum(int[] iArr) {
        if (this.power.length != iArr.length) {
            return 0;
        }
        int i = 0;
        for (int i2 = 0; i2 < iArr.length; i2++) {
            int i3 = 0;
            while (true) {
                int[] iArr2 = this.power;
                if (i3 < iArr2.length) {
                    if (i2 == i3) {
                        i += iArr[i2] * iArr2[i3];
                    }
                    i3++;
                }
            }
        }
        return i;
    }

    private String getCheckCodeBySum(int i) {
        switch (i % 11) {
            case 0:
                return DiskLruCache.VERSION_1;
            case 1:
                return NetResult.CODE_OK;
            case 2:
                return "x";
            case 3:
                return "9";
            case 4:
                return "8";
            case 5:
                return "7";
            case 6:
                return "6";
            case 7:
                return "5";
            case 8:
                return "4";
            case 9:
                return ExifInterface.GPS_MEASUREMENT_3D;
            case 10:
                return ExifInterface.GPS_MEASUREMENT_2D;
            default:
                return null;
        }
    }

    private int[] converCharToInt(char[] cArr) throws NumberFormatException {
        int[] iArr = new int[cArr.length];
        int length = cArr.length;
        int i = 0;
        int i2 = 0;
        while (i < length) {
            iArr[i2] = Integer.parseInt(String.valueOf(cArr[i]).trim());
            i++;
            i2++;
        }
        return iArr;
    }
}
