diff --git a/src/main/java/com/ecfront/dew/common/inner/IdcardUtils.java b/src/main/java/com/ecfront/dew/common/inner/IdcardUtils.java index 8fda4c9..9a9fd21 100644 --- a/src/main/java/com/ecfront/dew/common/inner/IdcardUtils.java +++ b/src/main/java/com/ecfront/dew/common/inner/IdcardUtils.java @@ -48,6 +48,7 @@ public class IdcardUtils { public static final String verifyCode[] = { "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2" }; + /** * 最低年限 */ @@ -142,13 +143,7 @@ private static String conver15CardTo18(String idCard) { */ public static boolean validateCard(String idCard) { String card = idCard.trim(); - if (validateIdCard18(card)) { - return true; - } - if (validateIdCard15(card)) { - return true; - } - return false; + return validateIdCard18(card) || validateIdCard15(card); } /** @@ -166,15 +161,13 @@ private static boolean validateIdCard18(String idCard) { String code18 = idCard.substring(17, CHINA_ID_MAX_LENGTH); if (isNum(code17)) { char[] cArr = code17.toCharArray(); - if (cArr != null) { - int[] iCard = converCharToInt(cArr); - int iSum17 = getPowerSum(iCard); - // 获取校验位 - String val = getCheckCode18(iSum17); - if (val.length() > 0) { - if (val.equalsIgnoreCase(code18)) { - bTrue = true; - } + int[] iCard = converCharToInt(cArr); + int iSum17 = getPowerSum(iCard); + // 获取校验位 + String val = getCheckCode18(iSum17); + if (val.length() > 0) { + if (val.equalsIgnoreCase(code18)) { + bTrue = true; } } } @@ -207,7 +200,7 @@ private static boolean validateIdCard15(String idCard) { Calendar cal = Calendar.getInstance(); if (birthDate != null) cal.setTime(birthDate); - if (!valiDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)), + if (!validateDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)), Integer.valueOf(birthCode.substring(4, 6)))) { return false; } @@ -428,7 +421,7 @@ public static String getProvinceByIdCard(String idCard) { * @return 提取的数字。 */ private static boolean isNum(String val) { - return val == null || "".equals(val) ? false : val.matches("^[0-9]*$"); + return !(val == null || "".equals(val)) && val.matches("^[0-9]*$"); } /** @@ -439,7 +432,7 @@ private static boolean isNum(String val) { * @param iDate 待验证日期(日) * @return 是否有效 */ - private static boolean valiDate(int iYear, int iMonth, int iDate) { + private static boolean validateDate(int iYear, int iMonth, int iDate) { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int datePerMonth; diff --git a/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java b/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java index b653b2b..0294343 100644 --- a/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java @@ -11,18 +11,6 @@ public class EncryptHelperTest { - @Test - public void a() throws UnsupportedEncodingException { - // 字符串 转 Base64 - String base64 = EncryptHelper.encodeStringToBase64("gudaoxuri", "UTF-8"); - // 数组 转 Base64 - base64 = EncryptHelper.encodeBytesToBase64("gudaoxuri".getBytes(), "UTF-8"); - // Base64 转 字符串 - String str = EncryptHelper.decodeBase64ToString(base64, "UTF-8"); - // Base64 转 字符串 - byte[] bytes = EncryptHelper.decodeBase64ToBytes(base64); - } - @Test public void symmetric() throws Exception { Assert.assertEquals("70C0CC2B7BF8A8EBCD7B59C49DDDA9A1E551122BA5D7AB3B7B02141D4CE4C626".toLowerCase(),