Skip to content

Commit

Permalink
Writing documents
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed May 28, 2017
1 parent 6fa36e3 commit a622989
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
31 changes: 12 additions & 19 deletions src/main/java/com/ecfront/dew/common/inner/IdcardUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class IdcardUtils {
public static final String verifyCode[] = {
"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"
};

/**
* 最低年限
*/
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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]*$");
}

/**
Expand All @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions src/test/java/com/ecfront/dew/common/EncryptHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a622989

Please sign in to comment.