开发中常用的工具类(一)

目录

字符串工具类

加密工具类

AES加解密

DES加解密

MD5

系统操作工具类

获取系统CPU,内存,硬盘使用率

获取系统系统相关序列号

获取ip及用户名

封装信息的工具类

国家名与代码

银行卡信息查询

身份证工具类

物流公司工具类

随机工具类

随机数序列

根据时间生产唯一id序列

其他随机方法



字符串工具类


package com.github.wxiaoqi.demo;

import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *   
 * 
 * @Title: StringHelper.java
 * @Package com.jarvis.base.utils
 * @Description:
 * @date 2017年9月2日 下午2:23:51
 * @version V1.0   字符串处理工具类。
 */
public final class StringHelper {

	/**
	 * 描述: 构造方法
	 */
	private StringHelper() {
	}

	/**
	 * 空字符串
	 */
	public static final String EMPTY_STRING = "";

	/**
	 * 点
	 */
	public static final char DOT = '.';

	/**
	 * 下划线
	 */
	public static final char UNDERSCORE = '_';

	/**
	 * 逗点及空格
	 */
	public static final String COMMA_SPACE = ", ";

	/**
	 * 逗点
	 */
	public static final String COMMA = ",";

	/**
	 * 开始括号
	 */
	public static final String OPEN_PAREN = "(";

	/**
	 * 结束括号
	 */
	public static final String CLOSE_PAREN = ")";

	/**
	 * 单引号
	 */
	public static final char SINGLE_QUOTE = '\'';

	/**
	 * 回车
	 */
	public static final String CRLF = "\r\n";

	/**
	 * 常量 12
	 */
	public static final int FIANL_TWELVE = 12;

	/**
	 * 十六进制常量 0x80
	 */
	public static final int HEX_80 = 0x80;

	/**
	 * 十六进制常量 0xff
	 */
	public static final int HEX_FF = 0xff;

	/**
	 * 把字符数组,转化为一个字符
	 *
	 * @param seperator
	 *            字符分隔符
	 * @param strings
	 *            数组对象
	 * @return 字符串
	 */
	public static String join(String seperator, String[] strings) {
		int length = strings.length;
		if (length == 0) {
			return EMPTY_STRING;
		}
		StringBuffer buf = new StringBuffer(length * strings[0].length()).append(strings[0]);
		for (int i = 1; i < length; i++) {
			buf.append(seperator).append(strings[i]);
		}
		return buf.toString();
	}

	/**
	 * 把迭代对象转化为一个字符串
	 *
	 * @param seperator
	 *            分隔符
	 * @param objects
	 *            迭代器对象
	 * @return 字符串
	 */
	public static String join(String seperator, Iterator objects) {
		StringBuffer buf = new StringBuffer();
		if (objects.hasNext()) {
			buf.append(objects.next());
		}
		while (objects.hasNext()) {
			buf.append(seperator).append(objects.next());
		}
		return buf.toString();
	}

	/**
	 * 把两个字符串数组的元素用分隔符连接,生成新的数组,生成的数组以第一个字符串数组为参照,与其长度相同。
	 *
	 * @param x
	 *            字符串数组
	 * @param seperator
	 *            分隔符
	 * @param y
	 *            字符串数组
	 * @return 组合后的字符串数组
	 */
	public static String[] add(String[] x, String seperator, String[] y) {
		String[] result = new String[x.length];
		for (int i = 0; i < x.length; i++) {
			result[i] = x[i] + seperator + y[i];
		}
		return result;
	}

	/**
	 * 生成一个重复的字符串,如需要重复*10次,则生成:**********。
	 *
	 * @param string
	 *            重复元素
	 * @param times
	 *            重复次数
	 * @return 生成后的字符串
	 */
	public static String repeat(String string, int times) {
		StringBuffer buf = new StringBuffer(string.length() * times);
		for (int i = 0; i < times; i++) {
			buf.append(string);
		}
		return buf.toString();
	}

	/**
	 * 字符串替换处理,把旧的字符串替换为新的字符串,主要是通过字符串查找进行处理
	 *
	 * @param source
	 *            需要进行替换的字符串
	 * @param old
	 *            需要进行替换的字符串
	 * @param replace
	 *            替换成的字符串
	 * @return 替换处理后的字符串
	 */
	public static String replace(String source, String old, String replace) {
		StringBuffer output = new StringBuffer();

		int sourceLen = source.length();
		int oldLen = old.length();

		int posStart = 0;
		int pos;

		// 通过截取字符串的方式,替换字符串
		while ((pos = source.indexOf(old, posStart)) >= 0) {
			output.append(source.substring(posStart, pos));

			output.append(replace);
			posStart = pos + oldLen;
		}

		// 如果还有没有处理的字符串,则都添加到新字符串后面
		if (posStart < sourceLen) {
			output.append(source.substring(posStart));
		}

		return output.toString();
	}

	/**
	 * 替换字符,如果指定进行全替换,必须设wholeWords=true,否则只替换最后出现的字符。
	 *
	 * @param template
	 *            字符模板
	 * @param placeholder
	 *            需要替换的字符
	 * @param replacement
	 *            新的字符
	 * @param wholeWords
	 *            是否需要全替换,true为需要,false为不需要。如果不需要,则只替换最后出现的字符。
	 * @return 替换后的新字符
	 */
	public static String replace(String template, String placeholder, String replacement, boolean wholeWords) {
		int loc = template.indexOf(placeholder);
		if (loc < 0) {
			return template;
		} else {
			final boolean actuallyReplace = wholeWords || loc + placeholder.length() == template.length()
					|| !Character.isJavaIdentifierPart(template.charAt(loc + placeholder.length()));
			String actualReplacement = actuallyReplace ? replacement : placeholder;
			return new StringBuffer(template.substring(0, loc)).append(actualReplacement).append(
					replace(template.substring(loc + placeholder.length()), placeholder, replacement, wholeWords))
					.toString();
		}
	}

	/**
	 * 替换字符,只替换第一次出现的字符串。
	 *
	 * @param template
	 *            字符模板
	 * @param placeholder
	 *            需要替换的字符串
	 * @param replacement
	 *            新字符串
	 * @return 替换后的字符串
	 */
	public static String replaceOnce(String template, String placeholder, String replacement) {
		int loc = template.indexOf(placeholder);
		if (loc < 0) {
			return template;
		} else {
			return new StringBuffer(template.substring(0, loc)).append(replacement)
					.append(template.substring(loc + placeholder.length())).toString();
		}
	}

	/**
	 * 把字符串,按指字的分隔符分隔为字符串数组
	 *
	 * @param seperators
	 *            分隔符
	 * @param list
	 *            字符串
	 * @return 字符串数组
	 */
	public static String[] split(String list, String seperators) {
		return split(list, seperators, false);
	}

	/**
	 * 把字符串,按指字的分隔符分隔为字符串数组
	 *
	 * @param seperators
	 *            分隔符
	 * @param list
	 *            字符串
	 * @param include
	 *            是否需要把分隔符也返回
	 * @return 字符串数组
	 */
	public static String[] split(String list, String seperators, boolean include) {
		StringTokenizer tokens = new StringTokenizer(list, seperators, include);
		String[] result = new String[tokens.countTokens()];
		int i = 0;
		while (tokens.hasMoreTokens()) {
			result[i++] = tokens.nextToken();
		}
		return result;
	}

	/**
	 * 提取字符串中,以.为分隔符后的所有字符,如string.exe,将返回exe。
	 *
	 * @param qualifiedName
	 *            字符串
	 * @return 提取后的字符串
	 */
	public static String unqualify(String qualifiedName) {
		return unqualify(qualifiedName, ".");
	}

	/**
	 * 提取字符串中,以指定分隔符后的所有字符,如string.exe,将返回exe。
	 *
	 * @param qualifiedName
	 *            字符串
	 * @param seperator
	 *            分隔符
	 * @return 提取后的字符串
	 */
	public static String unqualify(String qualifiedName, String seperator) {
		return qualifiedName.substring(qualifiedName.lastIndexOf(seperator) + 1);
	}

	/**
	 * 提取字符串中,以.为分隔符以前的字符,如string.exe,则返回string
	 *
	 * @param qualifiedName
	 *            字符串
	 * @return 提取后的字符串
	 */
	public static String qualifier(String qualifiedName) {
		int loc = qualifiedName.lastIndexOf(".");
		if (loc < 0) {
			return EMPTY_STRING;
		} else {
			return qualifiedName.substring(0, loc);
		}
	}

	/**
	 * 向字符串数组中的所有元素添加上后缀
	 *
	 * @param columns
	 *            字符串数组
	 * @param suffix
	 *            后缀
	 * @return 添加后缀后的数组
	 */
	public static String[] suffix(String[] columns, String suffix) {
		if (suffix == null) {
			return columns;
		}
		String[] qualified = new String[columns.length];
		for (int i = 0; i < columns.length; i++) {
			qualified[i] = suffix(columns[i], suffix);
		}
		return qualified;
	}

	/**
	 * 向字符串加上后缀
	 *
	 * @param name
	 *            需要添加后缀的字符串
	 * @param suffix
	 *            后缀
	 * @return 添加后缀的字符串
	 */
	public static String suffix(String name, String suffix) {
		return (suffix == null) ? name : name + suffix;
	}

	/**
	 * 向字符串数组中的所有元素,添加上前缀
	 *
	 * @param columns
	 *            需要添加前缀的字符串数组
	 * @param prefix
	 *            prefix
	 * @return
	 */
	public static String[] prefix(String[] columns, String prefix) {
		if (prefix == null) {
			return columns;
		}
		String[] qualified = new String[columns.length];
		for (int i = 0; i < columns.length; i++) {
			qualified[i] = prefix + columns[i];
		}
		return qualified;
	}

	/**
	 * 向字符串添加上前缀
	 *
	 * @param name
	 *            需要添加前缀的字符串
	 * @param prefix
	 *            前缀
	 * @return 添加前缀后的字符串
	 */
	public static String prefix(String name, String prefix) {
		return (prefix == null) ? name : prefix + name;
	}

	/**
	 * 判断字符串是否为"true"、"t",如果是,返回true,否则返回false
	 *
	 * @param tfString
	 *            需要进行判断真/假的字符串
	 * @return true/false
	 */
	public static boolean booleanValue(String tfString) {
		String trimmed = tfString.trim().toLowerCase();
		return trimmed.equals("true") || trimmed.equals("t");
	}

	/**
	 * 把对象数组转化为字符串
	 *
	 * @param array
	 *            对象数组
	 * @return 字符串
	 */
	public static String toString(Object[] array) {
		int len = array.length;
		if (len == 0) {
			return StringHelper.EMPTY_STRING;
		}
		StringBuffer buf = new StringBuffer(len * FIANL_TWELVE);
		for (int i = 0; i < len - 1; i++) {
			buf.append(array[i]).append(StringHelper.COMMA_SPACE);
		}
		return buf.append(array[len - 1]).toString();
	}

	/**
	 * 描述:把数组中的所有元素出现的字符串进行替换,把旧字符串替换为新字符数组的所有元素,只替换第一次出现的字符。
	 * 
	 * @param string
	 *            需要替换的数组
	 * @param placeholders
	 *            需要替换的字符串
	 * @param replacements
	 *            新字符串数组
	 * @return 替换后的字符串数组
	 */
	public static String[] multiply(String string, Iterator placeholders, Iterator replacements) {
		String[] result = new String[] { string };
		while (placeholders.hasNext()) {
			result = multiply(result, (String) placeholders.next(), (String[]) replacements.next());
		}
		return result;
	}

	/**
	 * 把数组中的所有元素出现的字符串进行替换,把旧字符串替换为新字符数组的所有元素,只替换第一次出现的字符。
	 *
	 * @param strings
	 *            需要替换的数组
	 * @param placeholder
	 *            需要替换的字符串
	 * @param replacements
	 *            新字符串数组
	 * @return 替换后的字符串数组
	 */
	private static String[] multiply(String[] strings, String placeholder, String[] replacements) {
		String[] results = new String[replacements.length * strings.length];
		int n = 0;
		for (int i = 0; i < replacements.length; i++) {
			for (int j = 0; j < strings.length; j++) {
				results[n++] = replaceOnce(strings[j], placeholder, replacements[i]);
			}
		}
		return results;
	}

	/**
	 * 统计Char在字符串中出现在次数,如"s"在字符串"string"中出现的次数
	 *
	 * @param string
	 *            字符串
	 * @param character
	 *            需要进行统计的char
	 * @return 数量
	 */
	public static int count(String string, char character) {
		int n = 0;
		for (int i = 0; i < string.length(); i++) {
			if (string.charAt(i) == character) {
				n++;
			}
		}
		return n;
	}

	/**
	 * 描述:计算字符串中未引用的字符
	 * 
	 * @param string
	 *            字符串
	 * @param character
	 *            字符
	 * @return 未引用的字符数
	 */
	public static int countUnquoted(String string, char character) {
		if (SINGLE_QUOTE == character) {
			throw new IllegalArgumentException("Unquoted count of quotes is invalid");
		}

		int count = 0;
		int stringLength = string == null ? 0 : string.length();
		boolean inQuote = false;
		for (int indx = 0; indx < stringLength; indx++) {
			if (inQuote) {
				if (SINGLE_QUOTE == string.charAt(indx)) {
					inQuote = false;
				}
			} else if (SINGLE_QUOTE == string.charAt(indx)) {
				inQuote = true;
			} else if (string.charAt(indx) == character) {
				count++;
			}
		}
		return count;
	}

	/**
	 * 
	 * 描述:描述:判断字符串是否为空,如果为true则为空。与isEmpty不同,如果字符为" "也视为空字符
	 * 
	 * @param str
	 *            字符串
	 * @return
	 */
	public static boolean isBlank(String str) {
		boolean b = true;// 20140507 modify by liwei 修复对" "为false的bug
		if (str == null) {
			b = true;
		} else {
			int strLen = str.length();
			if (strLen == 0) {
				b = true;
			}

			for (int i = 0; i < strLen; i++) {
				if (!Character.isWhitespace(str.charAt(i))) {
					b = false;
					break;
				}
			}
		}

		return b;
	}

	/**
	 * 
	 * 描述:描述:判断字符串是否为空,如果为true则不为空。与isNotEmpty不同,如果字符为" "也视为空字符
	 * 
	 * @param str
	 *            字符串
	 * @return
	 */
	public static boolean isNotBlank(String str) {
		int strLen = 0;
		if (str != null) {
			strLen = str.length();
		}
		if (str == null || strLen == 0) {
			return false;
		}
		for (int i = 0; i < strLen; i++) {
			if (!Character.isWhitespace(str.charAt(i))) {
				return true;
			}
		}

		return false;
	}

	/**
	 * 判断字符串是否非空,如果为true则不为空
	 *
	 * @param string
	 *            字符串
	 * @return true/false
	 */
	public static boolean isNotEmpty(String string) {
		return string != null && string.length() > 0;
	}

	/**
	 * 判断字符串是否空,如果为true则为空
	 *
	 * @param str
	 *            字符串
	 * @return true/false
	 */

	public static boolean isEmpty(String str) {
		if (str == null || str.trim().length() == 0) {
			return true;
		}
		return false;
	}

	/**
	 * 向字符串添加上前缀,并以.作为分隔符
	 *
	 * @param name
	 *            需要添加前缀的字符串
	 * @param prefix
	 *            前缀
	 * @return 添加前缀后的字符串
	 */
	public static String qualify(String name, String prefix) {
		if (name.startsWith("'")) {
			return name;
		}

		return new StringBuffer(prefix.length() + name.length() + 1).append(prefix).append(DOT).append(name).toString();
	}

	/**
	 * 向字符串数组中的所有字符添加上前缀,前以点作为分隔符
	 *
	 * @param names
	 *            字符串数组
	 * @param prefix
	 *            前缀
	 * @return 添加前缀后的字符串数组
	 */
	public static String[] qualify(String[] names, String prefix) {
		if (prefix == null) {
			return names;
		}
		int len = names.length;
		String[] qualified = new String[len];
		for (int i = 0; i < len; i++) {
			qualified[i] = qualify(prefix, names[i]);
		}
		return qualified;
	}

	/**
	 * 在字符串中,查找字符第一次出现的位置
	 *
	 * @param sqlString
	 *            原字符串
	 * @param string
	 *            需要查找到字符串
	 * @param startindex
	 *            开始位置
	 * @return 第一个出现的位置
	 */
	public static int firstIndexOfChar(String sqlString, String string, int startindex) {
		int matchAt = -1;
		for (int i = 0; i < string.length(); i++) {
			int curMatch = sqlString.indexOf(string.charAt(i), startindex);
			if (curMatch >= 0) {
				if (matchAt == -1) {
					matchAt = curMatch;
				} else {
					matchAt = Math.min(matchAt, curMatch);
				}
			}
		}
		return matchAt;
	}

	/**
	 * 从字符串中提取指字长度的字符。区分中英文。
* 如果需要加省略号,则将在指定长度上少取3个字符宽度,末尾加上"......"。 * * @param string * 字符串 * @param length * 要取的字符长度,此为中文长度,英文仅当作半个字符。 * @param appendSuspensionPoints * 是否需要加省略号 * @return 提取后的字符串 */ public static String truncate(String string, int length, boolean appendSuspensionPoints) { if (isEmpty(string) || length < 0) { return string; } if (length == 0) { return ""; } int strLength = string.length(); // 字符串字符个数 int byteLength = byteLength(string); // 字符串字节长度 length *= 2; // 换成字节长度 // 判断是否需要加省略号 boolean needSus = false; if (appendSuspensionPoints && byteLength >= length) { needSus = true; // 如果需要加省略号,则要少取2个字节用来加省略号 length -= 2; } StringBuffer result = new StringBuffer(); int count = 0; for (int i = 0; i < strLength; i++) { if (count >= length) { // 取完了 break; } char c = string.charAt(i); if (isLetter(c)) { // Ascill字符 result.append(c); count += 1; } else { // 非Ascill字符 if (count == length - 1) { // 如果只要取1个字节了,而后面1个是汉字,就放空格 result.append(" "); count += 1; } else { result.append(c); count += 2; } } } if (needSus) { result.append("..."); } return result.toString(); } /** * 描述:判断一个字符是Ascill字符还是其它字符(如汉,日,韩文字符) * * @param c * 需要判断的字符 * @return */ public static boolean isLetter(char c) { int k = HEX_80; return c / k == 0 ? true : false; } /** * 得到一个字符串的长度,显示的长度,一个汉字或日韩文长度为2,英文字符长度为1 * * @param s * ,需要得到长度的字符串 * @return int, 得到的字符串长度 */ public static int byteLength(String s) { char[] c = s.toCharArray(); int len = 0; for (int i = 0; i < c.length; i++) { if (isLetter(c[i])) { len++; } else { len += 2; } } return len; } /** * 从字符串中提取指字长度的字符 * * @param string * 字符串 * @param length * 字符长度 * @return 提取后的字符串 */ public static String truncate(String string, int length) { if (isEmpty(string)) { return string; } if (string.length() <= length) { return string; } else { return string.substring(0, length); } } /** * 去丢字符的左侧空格 * * @param value * 字符串 * @return 去丢左侧空格后的字符串 */ public static String leftTrim(String value) { String result = value; if (result == null) { return result; } char ch[] = result.toCharArray(); int index = -1; for (int i = 0; i < ch.length; i++) { if (!Character.isWhitespace(ch[i])) { break; } index = i; } if (index != -1) { result = result.substring(index + 1); } return result; } /** * 去丢字符的右侧空格 * * @param value * 字符串 * @return 去右侧空格后的字符串 */ public static String rightTrim(String value) { String result = value; if (result == null) { return result; } char ch[] = result.toCharArray(); int endIndex = -1; for (int i = ch.length - 1; i > -1; i--) { if (!Character.isWhitespace(ch[i])) { break; } endIndex = i; } if (endIndex != -1) { result = result.substring(0, endIndex); } return result; } /** * 把null字符串转化为"" * * @param source * 空字符串 * @return 转化后的字符串 */ public static String n2s(String source) { return source != null ? source : ""; } /** * 如果字符串为空,则返回默认字符串 * * @param source * 源字符串 * @param defaultStr * 默认字符串 * @return 转换后的字符串 */ public static String n2s(String source, String defaultStr) { return source != null ? source : defaultStr; } /** * 将字符串格式化成 HTML 以SCRIPT变量 主要是替换单,双引号,以将内容格式化输出,适合于 HTML 中的显示输出 * * @param str * 要格式化的字符串 * @return 格式化后的字符串 */ public static String toScript(String str) { if (str == null) { return null; } String html = new String(str); html = replace(html, "\"", "\\\""); html = replace(html, "\r\n", "\n"); html = replace(html, "\n", "\\n"); html = replace(html, "\t", " "); html = replace(html, "\'", "\\\'"); html = replace(html, " ", "  "); html = replace(html, "", "<\\/script>"); html = replace(html, "", "<\\/SCRIPT>"); return html; } /** * 同于String#trim(),但是检测null,如果原字符串为null,则仍然返回null * * @param s * s * @return */ public static String trim(String s) { return s == null ? s : s.trim(); } /** * 对字符串进行空格处理,如果字符串为null呀是空字符串, 则返回默认的数字。 * * @param source * 需要进行处理的字符串 * @param defaultValue * 缺省值 * @return 字符串的数字值 */ public static int strTrim(String source, int defaultValue) { if (isEmpty(source)) { return defaultValue; } try { source = source.trim(); int value = (new Integer(source)).intValue(); return value; } catch (Exception ex) { ex.printStackTrace(); System.err.println("数字转换出错,请检查数据来源。返回默认值"); return defaultValue; } } /** * 对字符串进行过滤处理,如果字符串是null或为空字符串, 返回默认值。 * * @param source * 需要进行处理的字符串 * @param defaultValue * 缺省值 * @return 过滤后的字符串 */ public static String strTrim(String source, String defaultValue) { if (StringHelper.isEmpty(source)) { return defaultValue; } try { source = source.trim(); return source; } catch (Exception ex) { ex.printStackTrace(); System.err.println("字符串去空格失败,返回默认值"); return defaultValue; } } /** * 描述:为了防止跨站脚本攻击,转换<>这种尖括号。 * * @param source * @return */ public static String encodeURL(String source) { if (source == null) { return null; } String html = new String(source); html = replace(html, "<", "<"); html = replace(html, ">", ">"); html = replace(html, "\"", """); html = replace(html, " ", " "); html = replace(html, "\'", "´"); html = replace(html, "\\", "\"); html = replace(html, "&", "&"); html = replace(html, "\r", ""); html = replace(html, "\n", ""); html = replace(html, "(", "("); html = replace(html, ")", ")"); html = replace(html, "[", "["); html = replace(html, "]", "]"); html = replace(html, ";", ";"); html = replace(html, "/", "/"); return html; } /** * 把字符串中一些特定的字符转换成html字符,如&、<、>、"号等 * * @param source * 需要进行处理的字符串 * @return 处理后的字符串 */ public static String encodeHtml(String source) { if (source == null) { return null; } String html = new String(source); html = replace(html, "&", "&"); html = replace(html, "<", "<"); html = replace(html, ">", ">"); html = replace(html, "\"", """); html = replace(html, " ", " "); html = replace(html, "\'", "´"); return html; } /** * 把一些html的字符串还原 * * @param source * 需要进行处理的字符串 * @return 处理后的字符串 */ public static String decodeHtml(String source) { if (source == null) { return null; } String html = new String(source); html = replace(html, "&", "&"); html = replace(html, "<", "<"); html = replace(html, ">", ">"); html = replace(html, """, "\""); html = replace(html, " ", " "); html = replace(html, "\r\n", "\n"); html = replace(html, "\n", "
\n"); html = replace(html, "\t", " "); html = replace(html, " ", "  "); return html; } /** * 判断字符串是否为布尔值,如true/false等 * * @param source * 需要进行判断的字符串 * @return 返回字符串的布尔值 */ public static boolean isBoolean(String source) { if (source.equalsIgnoreCase("true") || source.equalsIgnoreCase("false")) { return true; } return false; } /** * 去除字符串中的最后字符 * * @param str * 原字符串 * @param strMove * 要去除字符 比如"," * @return 去除后的字符串 */ public static String lastCharTrim(String str, String strMove) { if (isEmpty(str)) { return ""; } String newStr = ""; if (str.lastIndexOf(strMove) != -1 && str.lastIndexOf(strMove) == str.length() - 1) { newStr = str.substring(0, str.lastIndexOf(strMove)); } return newStr; } /** * 清除字符串里的html代码 * * @param html * 需要进行处理的字符串 * @return 清除html后的代码 */ public static String clearHtml(String html) { if (isEmpty(html)) { return ""; } String patternStr = "(<[^>]*>)"; Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE); Matcher matcher = null; StringBuffer bf = new StringBuffer(); try { matcher = pattern.matcher(html); boolean first = true; int start = 0; int end = 0; while (matcher.find()) { start = matcher.start(1); if (first) { bf.append(html.substring(0, start)); first = false; } else { bf.append(html.substring(end, start)); } end = matcher.end(1); } if (end < html.length()) { bf.append(html.substring(end)); } html = bf.toString(); return html; } catch (Exception ex) { ex.printStackTrace(); System.err.println("清除html标签失败"); } finally { pattern = null; matcher = null; } return html; } /** * 把文杯格式转换为html格式 * * @param content * 转换的内容 * @return */ public static String textFmtToHtmlFmt(String content) { content = StringHelper.replace(content, " ", " "); content = StringHelper.replace(content, "\r\n", "
"); content = StringHelper.replace(content, "\n", "
"); return content; } /** * * 描述:大写英文字母转换成小写 * * @param strIn * 字符串参数 * @return */ public static String toLowerStr(String strIn) { String strOut = new String(); // 输出的字串 int len = strIn.length(); // 参数的长度 int i = 0; // 计数器 char ch; // 存放参数的字符 while (i < len) { ch = strIn.charAt(i); if (ch >= 'A' && ch <= 'Z') { ch = (char) (ch - 'A' + 'a'); } strOut += ch; i++; } return strOut; } /** * * 描述:小写英文字母转换成大写 * * @param strIn * 字符串参数 * @return */ public static String toUpperStr(String strIn) { String strOut = new String(); // 输出的字串 int len = strIn.length(); // 参数的长度 int i = 0; // 计数器 char ch; // 存放参数的字符 while (i < len) { ch = strIn.charAt(i); if (ch >= 'a' && ch <= 'z') { ch = (char) (ch - 'a' + 'A'); } strOut += ch; i++; } return strOut; } /** * 货币缩写,提供亿和万两个单位,并精确到小数点2位 切换到新的算法:对数算法 * * @param original * @return */ public static String currencyShortFor(String original) { if (StringHelper.isBlank(original)) { return ""; } else { String shortFor = ""; double shortForValue = 0; DecimalFormat df = new DecimalFormat("#.00"); try { double account = Double.parseDouble(original); if (account / 100000000 > 1) { shortForValue = account / 100000000; shortFor = df.format(shortForValue) + "亿"; } else if (account / 10000 > 1) { shortForValue = account / 10000; shortFor = df.format(shortForValue) + "万"; } else { shortFor = original; } } catch (NumberFormatException e) { e.printStackTrace(); System.err.println("字符串[" + original + "]转换成数字出错"); } return shortFor; } } /** * 将日期格式由yyyyMMdd装换为yyyy-MM-dd * * @param date * Date string whose format is yyyyMMdd. * @return */ public static String formatDate(String date) { if (isBlank(date) || date.length() < 8) { return ""; } StringBuffer dateBuf = new StringBuffer(); dateBuf.append(date.substring(0, 4)); dateBuf.append("-"); dateBuf.append(date.substring(4, 6)); dateBuf.append("-"); dateBuf.append(date.substring(6, 8)); return dateBuf.toString(); } static Pattern pattern = Pattern.compile("^\\d+(\\.0)?$", Pattern.CASE_INSENSITIVE); /** * 判断是否为整数 * * @param str * 传入的字符串 * @return 是整数返回true,否则返回false */ public static boolean isInteger(String str) { return pattern.matcher(str).matches(); } /** * 用于=中英文混排标题中限定字符串长度。保证显示长度最多只相差一个全角字符。 * * @param string * 需要截取的字符串 * @param byteCount * 字节数(度量标准为中文为两个字节,ASCII字符为一个字节,这样子,刚好匹配ASCII为半角字符,而中文为全角字符, * 保证在网页上中英文混合的句子长度一致) * @return * @throws UnsupportedEncodingException */ public static String substring(String string, int byteCount) throws UnsupportedEncodingException { if (isBlank(string)) { return string; } byte[] bytes = string.getBytes("Unicode");// 使用UCS-2编码. int viewBytes = 0; // 表示当前的字节数(英文为单字节,中文为双字节的表示方法) int ucs2Bytes = 2; // 要截取的字节数,从第3个字节开始,前两位为位序。(UCS-2的表示方法) // UCS-2每个字符使用两个字节来编码。 // ASCII n+=1,i+=2 // 中文 n+=2,i+=2 for (; ucs2Bytes < bytes.length && viewBytes < byteCount; ucs2Bytes++) { // 奇数位置,如3、5、7等,为UCS2编码中两个字节的第二个字节 if (ucs2Bytes % 2 == 1) { viewBytes++; // 低字节,无论中英文,都算一个字节。 } else { // 当UCS2编码的第一个字节不等于0时,该UCS2字符为汉字,一个汉字算两个字节 // 高位时,仅中文的高位算一字节。 if (bytes[ucs2Bytes] != 0) { viewBytes++; } } } // 截一半的汉字要保留 if (ucs2Bytes % 2 == 1) { ucs2Bytes = ucs2Bytes + 1; } String result = new String(bytes, 0, ucs2Bytes, "Unicode");// 将字节流转换为java默认编码UTF-8的字符串 if (bytes.length > ucs2Bytes) { result += "..."; } return result; } /** * 描述:根据长度截断字串 * * @param str * 字串 * @param length * 截取长度 * @return */ public static String[] splite(String str, int length) { if (StringHelper.isEmpty(str)) { return null; } String[] strArr = new String[(str.length() + length - 1) / length]; for (int i = 0; i < strArr.length; i++) { if (str.length() > i * length + length - 1) { strArr[i] = str.substring(i * length, i * length + length - 1); } else { strArr[i] = str.substring(i * length); } } return strArr; } /** * 描述:把某一个字符变成大写 * * @param str * str 字串 * @param index * 第几个字符 * @return */ public static String toUpOneChar(String str, int index) { return toUpOrLowOneChar(str, index, 1); } /** * 描述:把某一个字符变成小写 作者:李建 时间:Dec 17, 2010 9:42:32 PM * * @param str * str 字串 * @param index * 第几个字符 * @return */ public static String toLowOneChar(String str, int index) { return toUpOrLowOneChar(str, index, 0); } /** * 描述:把某一个字符变成大写或小写 作者:李建 时间:Dec 17, 2010 9:39:32 PM * * @param str * 字串 * @param index * 第几个字符 * @param upOrLow * 大小写 1:大写;0小写 * @return */ public static String toUpOrLowOneChar(String str, int index, int upOrLow) { if (StringHelper.isNotEmpty(str) && index > -1 && index < str.length()) { char[] chars = str.toCharArray(); if (upOrLow == 1) { chars[index] = Character.toUpperCase(chars[index]); } else { chars[index] = Character.toLowerCase(chars[index]); } return new String(chars); } return str; } /** * 将字符串用分隔符断裂成字符串列表 * * @param value * 原字符串 * @param separator * 分隔字符 * @return 结果列表 */ public static List split2List(String value, String separator) { List ls = new ArrayList(); int i = 0, j = 0; while ((i = value.indexOf(separator, i)) != -1) { ls.add(value.substring(j, i)); ++i; j = i; } ls.add(value.substring(j)); return ls; } /** * 将数组用分隔符连接成新字符串(split的逆方法) * * @param strs * 字符串数组 * @param sep * 分隔符 * @return 结果字符串 */ public static String join(String[] strs, String sep) { StringBuilder res = new StringBuilder(); for (int i = 0; i < strs.length; i++) { res.append(strs[i] + sep); } return res.substring(0, res.length() - sep.length()); } /** * 获得一个UUID * * @return String UUID */ public static String getUUID() { String str = UUID.randomUUID().toString();// 标准的UUID格式为:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx(8-4-4-4-12) // 去掉"-"符号,不用replaceAll的原因与split一样,replaceAll支持正则表达式,频繁使用时效率不够高(当然偶尔用一下影响也不会特别严重) return join(split(str, "-"), ""); } /** *
	 * 例: String strVal="This is a dog"; String
	 * strResult=CTools.replace(strVal,"dog","cat"); 结果: strResult equals
	 * "This is cat"
	 *
	 * @param strSrc
	 *            要进行替换操作的字符串
	 * @param strOld
	 *            要查找的字符串
	 * @param strNew
	 *            要替换的字符串
	 * @return 替换后的字符串
	 * 
	 *         
	 */
	public static final String replaceAllStr(String strSrc, String strOld, String strNew) {
		if (strSrc == null || strOld == null || strNew == null) {
			return "";
		}

		int i = 0;
// 避免新旧字符一样产生死循环
		if (strOld.equals(strNew))  {
			return strSrc;
		}

		if ((i = strSrc.indexOf(strOld, i)) >= 0) {
			char[] arr_cSrc = strSrc.toCharArray();
			char[] arr_cNew = strNew.toCharArray();

			int intOldLen = strOld.length();
			StringBuffer buf = new StringBuffer(arr_cSrc.length);
			buf.append(arr_cSrc, 0, i).append(arr_cNew);

			i += intOldLen;
			int j = i;

			while ((i = strSrc.indexOf(strOld, i)) > 0) {
				buf.append(arr_cSrc, j, i - j).append(arr_cNew);
				i += intOldLen;
				j = i;
			}

			buf.append(arr_cSrc, j, arr_cSrc.length - j);

			return buf.toString();
		}

		return strSrc;
	}

	/**
	 * 用于将字符串中的特殊字符转换成Web页中可以安全显示的字符串 可对表单数据据进行处理对一些页面特殊字符进行处理如'
	 * <','>','"',''','&'
	 * 
	 * @param strSrc
	 *            要进行替换操作的字符串
	 * @return 替换特殊字符后的字符串
	 * @since 1.0
	 */

	public static String htmlEncode(String strSrc) {
		if (strSrc == null) {
			return "";
		}

		char[] arr_cSrc = strSrc.toCharArray();
		StringBuffer buf = new StringBuffer(arr_cSrc.length);
		char ch;

		for (int i = 0; i < arr_cSrc.length; i++) {
			ch = arr_cSrc[i];

			if (ch == '<') {
				buf.append("<");
			} else if (ch == '>') {
				buf.append(">");
			} else if (ch == '"') {
				buf.append(""");
			} else if (ch == '\'') {
				buf.append("'");
			} else if (ch == '&') {
				buf.append("&");
			} else {
				buf.append(ch);
			}
		}

		return buf.toString();
	}

	/**
	 * 用于将字符串中的特殊字符转换成Web页中可以安全显示的字符串 可对表单数据据进行处理对一些页面特殊字符进行处理如'
	 * <','>','"',''','&'
	 * 
	 * @param strSrc
	 *            要进行替换操作的字符串
	 * @param quotes
	 *            为0时单引号和双引号都替换,为1时不替换单引号,为2时不替换双引号,为3时单引号和双引号都不替换
	 * @return 替换特殊字符后的字符串
	 * @since 1.0
	 */
	public static String htmlEncode(String strSrc, int quotes) {

		if (strSrc == null) {
			return "";
		}
		if (quotes == 0) {
			return htmlEncode(strSrc);
		}

		char[] arr_cSrc = strSrc.toCharArray();
		StringBuffer buf = new StringBuffer(arr_cSrc.length);
		char ch;

		for (int i = 0; i < arr_cSrc.length; i++) {
			ch = arr_cSrc[i];
			if (ch == '<') {
				buf.append("<");
			} else if (ch == '>') {
				buf.append(">");
			} else if (ch == '"' && quotes == 1) {
				buf.append(""");
			} else if (ch == '\'' && quotes == 2) {
				buf.append("'");
			} else if (ch == '&') {
				buf.append("&");
			} else {
				buf.append(ch);
			}
		}

		return buf.toString();
	}

	/**
	 * 和htmlEncode正好相反
	 * 
	 * @param strSrc
	 *            要进行转换的字符串
	 * @return 转换后的字符串
	 * @since 1.0
	 */
	public static String htmlDecode(String strSrc) {
		if (strSrc == null) {
			return "";
		}
		strSrc = strSrc.replaceAll("<", "<");
		strSrc = strSrc.replaceAll(">", ">");
		strSrc = strSrc.replaceAll(""", "\"");
		strSrc = strSrc.replaceAll("'", "'");
		strSrc = strSrc.replaceAll("&", "&");
		return strSrc;
	}

	/**
	 * 实际处理 return toChineseNoReplace(null2Blank(str));
	 * 
	 * @param str
	 *            要进行处理的字符串
	 * @return 转换后的字符串
	 */
	public static String toChineseAndHtmlEncode(String str, int quotes) {
		try {
			if (str == null) {
				return "";
			} else {
				str = str.trim();
				str = new String(str.getBytes("ISO8859_1"), "GBK");
				String htmlEncode = htmlEncode(str, quotes);
				return htmlEncode;
			}
		} catch (Exception exp) {
			return "";
		}
	}

	/**
	 * 把null值和""值转换成  主要应用于页面表格格的显示
	 * 
	 * @param str
	 *            要进行处理的字符串
	 * @return 转换后的字符串
	 */
	public static String str4Table(String str) {
		if (str == null) {
			return " ";
		}
		else if (str.equals("")) {
			return " ";
		} else {
			return str;
		}
	}

}

加密工具类

  • AES加解密

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;

/**
 * AES加解密
 *
 * @Author:Devil
 */
public class AESUtils {
	/** 默认秘钥 */
	protected static final String KEY = "BC3EKnzMD3dndw1Xs2KzESXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0";
	
    /**
     *  AES解密
     */
    protected static String decrypt(String encryptValue, String key) throws Exception {  
        return aesDecryptByBytes(base64Decode(encryptValue), key);  
    }
    
    /**
     * AES加密
     */
    protected static String encrypt(String value, String key) throws Exception {  
        return base64Encode(aesEncryptToBytes(value, key));  
    }  
	
    private static String base64Encode(byte[] bytes){  
        return Base64Utils.encrypt(bytes);
    }  
      
    @SuppressWarnings("static-access")
    private static byte[] base64Decode(String base64Code) throws Exception{  
        return base64Code == null ? null : Base64Utils.decrypt(base64Code);
    }  
      
    private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {  
        KeyGenerator kgen = KeyGenerator.getInstance("AES");  
        kgen.init(128, new SecureRandom(encryptKey.getBytes()));  
  
        Cipher cipher = Cipher.getInstance("AES");  
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));  
          
        return cipher.doFinal(content.getBytes("utf-8"));  
    }  
      
    private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {  
        KeyGenerator kgen = KeyGenerator.getInstance("AES");  
        kgen.init(128, new SecureRandom(decryptKey.getBytes()));  
          
        Cipher cipher = Cipher.getInstance("AES");  
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));  
        byte[] decryptBytes = cipher.doFinal(encryptBytes);  
          
        return new String(decryptBytes);  
    }  
    
}
  • DES加解密

package com.demo;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.SecureRandom;

/**
 * DES加解密工具类
 *
 * @Author:Devil
 *
 */
class DESUtils {
	/** 默认key */
	protected final static String KEY = "ScAKC0XhadTHT3Al0QIDAQAB";

	/**
	 * DES加密
	 */
	protected static String encrypt(String data, String key) {
		String encryptedData = null;
		try {
			// DES算法要求有一个可信任的随机数源
			SecureRandom sr = new SecureRandom();
			DESKeySpec deskey = new DESKeySpec(key.getBytes());
			// 创建一个密匙工厂,然后用它把DESKeySpec转换成一个SecretKey对象
			SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
			SecretKey secretKey = keyFactory.generateSecret(deskey);
			// 加密对象
			Cipher cipher = Cipher.getInstance("DES");
			cipher.init(Cipher.ENCRYPT_MODE, secretKey, sr);
			// 加密,并把字节数组编码成字符串
			encryptedData = new sun.misc.BASE64Encoder().encode(cipher.doFinal(data.getBytes()));
		} catch (Exception e) {
			throw new RuntimeException("加密错误,错误信息:", e);
		}
		return encryptedData;
	}

	/**
	 * DES解密
	 */
	protected static String decrypt(String cryptData, String key) {
		String decryptedData = null;
		try {
			// DES算法要求有一个可信任的随机数源
			SecureRandom sr = new SecureRandom();
			DESKeySpec deskey = new DESKeySpec(key.getBytes());
			// 创建一个密匙工厂,然后用它把DESKeySpec转换成一个SecretKey对象
			SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
			SecretKey secretKey = keyFactory.generateSecret(deskey);
			// 解密对象
			Cipher cipher = Cipher.getInstance("DES");
			cipher.init(Cipher.DECRYPT_MODE, secretKey, sr);
			// 把字符串解码为字节数组,并解密
			decryptedData = new String(cipher.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(cryptData)));
		} catch (Exception e) {
			throw new RuntimeException("解密错误,错误信息:", e);
		}
		return decryptedData;
	}
	
//######################################################################################################################

	static Key key; 
    /**    
     * 根据参数生成KEY    
     */      
    public static void getKey(String strKey) {       
        try {       
            KeyGenerator _generator = KeyGenerator.getInstance("DES");  
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG" );
            secureRandom.setSeed(strKey.getBytes()); 
            //_generator.init(new SecureRandom(strKey.getBytes()));Linux下会报错
            _generator.init(secureRandom);
            key = _generator.generateKey();     
            _generator = null;       
        } catch (Exception e) {       
            e.printStackTrace();       
        }       
    }       
      
     
      
    /**    
     * 加密以byte[]明文输入,byte[]密文输出    
     */      
    private static byte[] getEncCode(byte[] byteS) {       
        byte[] byteFina = null;       
        Cipher cipher;       
        try {       
            cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");       
            cipher.init(Cipher.ENCRYPT_MODE, key);       
            byteFina = cipher.doFinal(byteS);       
        } catch (Exception e) {       
            e.printStackTrace();       
        } finally {       
            cipher = null;       
        }       
        return byteFina;       
    }       
      
    /**    
     * 解密以byte[]密文输入,以byte[]明文输出    
     */      
    private static byte[] getDesCode(byte[] byteD) {       
        Cipher cipher;       
        byte[] byteFina = null;       
        try {       
            cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");//DES/ECB/NoPadding;DES/ECB/ISO10126Padding
            cipher.init(Cipher.DECRYPT_MODE, key);       
            byteFina = cipher.doFinal(byteD);       
        } catch (Exception e) {       
            e.printStackTrace();       
        } finally {       
            cipher = null;       
        }       
        return byteFina;       
    }  

}

  • MD5

import java.nio.charset.Charset;
import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

//################################################################# MD5工具类 #####################################################
	
	/**
	 * 获取字符串的MD5
	 * @param string 字符串
	 * @return String MD5字符串
	 * @throws NoSuchAlgorithmException
	 */
	public static String getStringMD5(String string,String salt) throws NoSuchAlgorithmException{
		
		String target=null;
		if(StringUtils.isBlank(salt)){
			target=string;
		}else{
			target=getStringMD5(salt+string+salt, null);
		}
		
		byte[] byteString=target.getBytes(Charset.forName("utf-8"));
		MessageDigest md=MessageDigest.getInstance("MD5");
		byte[] array=md.digest(byteString);
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < array.length; ++i) {
	          sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
	    }
		return sb.toString();
	}
	
	/**
	 * 获取文件MD5
	 * @param filePath 文件路径
	 * @return String
	 * @throws NoSuchAlgorithmException
	 * @throws IOException
	 * @throws DigestException
	 */
	public static String getFileMD5(String filePath) throws NoSuchAlgorithmException, IOException, DigestException{
		MessageDigest md=MessageDigest.getInstance("MD5");
		int length=0;
		byte[] buffer=new byte[1024];
		byte[] array=null;
		InputStream is=new FileInputStream(new File(filePath));
		while((length=is.read(buffer))!=-1){
			md.update(buffer,0,length);
		}
		
		is.close();
		
		array=md.digest();
		
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < array.length; ++i) {
	          sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
	    }
		
		return sb.toString();
	}

  • Base64编码
package com.demo;

/**
 * BASE64加解密工具类
 *
 * @Author:Devil
 *
 */
class Base64Utils {

	private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D',
			'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
			'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
			'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
			'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
			'4', '5', '6', '7', '8', '9', '+', '/' };

	private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1, -1,
			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
			-1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59,
			60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
			10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,
			-1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
			38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1,
			-1, -1 };

	/**
	 * BASE64加密
	 */
	protected static String encrypt(byte[] data) {
		StringBuffer sb = new StringBuffer();
		int len = data.length;
		int i = 0;
		int b1, b2, b3;
		while (i < len) {
			b1 = data[i++] & 0xff;
			if (i == len) {
				sb.append(base64EncodeChars[b1 >>> 2]);
				sb.append(base64EncodeChars[(b1 & 0x3) << 4]);
				sb.append("==");
				break;
			}
			b2 = data[i++] & 0xff;
			if (i == len) {
				sb.append(base64EncodeChars[b1 >>> 2]);
				sb.append(base64EncodeChars[((b1 & 0x03) << 4)
						| ((b2 & 0xf0) >>> 4)]);
				sb.append(base64EncodeChars[(b2 & 0x0f) << 2]);
				sb.append("=");
				break;
			}
			b3 = data[i++] & 0xff;
			sb.append(base64EncodeChars[b1 >>> 2]);
			sb.append(base64EncodeChars[((b1 & 0x03) << 4)
					| ((b2 & 0xf0) >>> 4)]);
			sb.append(base64EncodeChars[((b2 & 0x0f) << 2)
					| ((b3 & 0xc0) >>> 6)]);
			sb.append(base64EncodeChars[b3 & 0x3f]);
		}
		return sb.toString();
	}

	/**
	 * Base64 解密
	 */
	protected static byte[] decrypt(String str) throws Exception{
		StringBuffer sb = new StringBuffer();
		byte[] data =  str.getBytes("US-ASCII");
		int len = data.length;
		int i = 0;
		int b1, b2, b3, b4;
		while (i < len) {

			do {
				b1 = base64DecodeChars[data[i++]];
			} while (i < len && b1 == -1);
			if (b1 == -1) {
				break;
			}

			do {
				b2 = base64DecodeChars[data[i++]];
			} while (i < len && b2 == -1);
			if (b2 == -1) {
				break;
			}
			sb.append((char) ((b1 << 2) | ((b2 & 0x30) >>> 4)));

			do {
				b3 = data[i++];
				if (b3 == 61) {
					return sb.toString().getBytes("iso8859-1");
				}
				b3 = base64DecodeChars[b3];
			} while (i < len && b3 == -1);
			if (b3 == -1) {
				break;
			}
			sb.append((char) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));

			do {
				b4 = data[i++];
				if (b4 == 61) {
					return sb.toString().getBytes("iso8859-1");
				}
				b4 = base64DecodeChars[b4];
			} while (i < len && b4 == -1);
			if (b4 == -1) {
				break;
			}
			sb.append((char) (((b3 & 0x03) << 6) | b4));
		}
		return sb.toString().getBytes("iso8859-1");
	}
}

系统操作工具类

  • 获取系统CPU,内存,硬盘使用率

package com.demo;

import com.sun.management.OperatingSystemMXBean;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.lang.management.ManagementFactory;
import java.math.BigDecimal;
import java.util.*;
@Slf4j
public class ComputerMonitorUtil {

    private static String osName = System.getProperty("os.name");
    private static final int CPUTIME = 500;
    private static final int PERCENT = 100;
    private static final int FAULTLENGTH = 10;

    /**
     * 功能:获取Linux和Window系统cpu使用率
     */
    public static double getCpuUsage() {
// 如果是window系统
        if (osName.toLowerCase().contains("windows")
                || osName.toLowerCase().contains("win")) {
            try {
                String procCmd = System.getenv("windir")
                        + "//system32//wbem//wmic.exe process get Caption,CommandLine,KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";
// 取进程信息
                long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));//第一次读取CPU信息
                Thread.sleep(CPUTIME);//睡500ms
                long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));//第二次读取CPU信息
                if (c0 != null && c1 != null) {
                    long idletime = c1[0] - c0[0];//空闲时间
                    long busytime = c1[1] - c0[1];//使用时间
                    Double cpusage = Double.valueOf(PERCENT * (busytime) * 1.0 / (busytime + idletime));
                    BigDecimal b1 = new BigDecimal(cpusage);
                    double cpuUsage = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    return cpuUsage;
                } else {
                    return 0.0;
                }
            } catch (Exception ex) {
                log.debug(ex.toString());
                return 0.0;
            }

        } else {

            try {
                Map map1 = ComputerMonitorUtil.cpuinfo();
                Thread.sleep(CPUTIME);
                Map map2 = ComputerMonitorUtil.cpuinfo();

                long user1 = Long.parseLong(map1.get("user").toString());
                long nice1 = Long.parseLong(map1.get("nice").toString());
                long system1 = Long.parseLong(map1.get("system").toString());
                long idle1 = Long.parseLong(map1.get("idle").toString());

                long user2 = Long.parseLong(map2.get("user").toString());
                long nice2 = Long.parseLong(map2.get("nice").toString());
                long system2 = Long.parseLong(map2.get("system").toString());
                long idle2 = Long.parseLong(map2.get("idle").toString());

                long total1 = user1 + system1 + nice1;
                long total2 = user2 + system2 + nice2;
                float total = total2 - total1;

                long totalIdle1 = user1 + nice1 + system1 + idle1;
                long totalIdle2 = user2 + nice2 + system2 + idle2;
                float totalidle = totalIdle2 - totalIdle1;

                float cpusage = (total / totalidle) * 100;

                BigDecimal b1 = new BigDecimal(cpusage);
                double cpuUsage = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                return cpuUsage;
            } catch (InterruptedException e) {
                log.debug(e.toString());
            }
        }
        return 0;
    }

    /**
     * 功能:Linux CPU使用信息
     */
    public static Map cpuinfo() {
        InputStreamReader inputs = null;
        BufferedReader buffer = null;
        Map map = new HashMap();
        try {
            inputs = new InputStreamReader(new FileInputStream("/proc/stat"));
            buffer = new BufferedReader(inputs);
            String line = "";
            while (true) {
                line = buffer.readLine();
                if (line == null) {
                    break;
                }
                if (line.startsWith("cpu")) {
                    StringTokenizer tokenizer = new StringTokenizer(line);
                    List temp = new ArrayList();
                    while (tokenizer.hasMoreElements()) {
                        String value = tokenizer.nextToken();
                        temp.add(value);
                    }
                    map.put("user", temp.get(1));
                    map.put("nice", temp.get(2));
                    map.put("system", temp.get(3));
                    map.put("idle", temp.get(4));
                    map.put("iowait", temp.get(5));
                    map.put("irq", temp.get(6));
                    map.put("softirq", temp.get(7));
                    map.put("stealstolen", temp.get(8));
                    break;
                }
            }
        } catch (Exception e) {
            log.debug(e.toString());
        } finally {
            try {
                buffer.close();
                inputs.close();
            } catch (Exception e2) {
                log.debug(e2.toString());
            }
        }
        return map;
    }

    /**
     * 功能:Linux 和 Window 内存使用率
     */
    public static double getMemUsage() {
        if (osName.toLowerCase().contains("windows")
                || osName.toLowerCase().contains("win")) {

            try {
                OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
                        .getOperatingSystemMXBean();
// 总的物理内存+虚拟内存
                long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();
// 剩余的物理内存
                long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
                Double usage = (Double) (1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100;
                BigDecimal b1 = new BigDecimal(usage);
                double memoryUsage = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                return memoryUsage;
            } catch (Exception e) {
                log.debug(e.toString());
            }
        } else {
            Map map = new HashMap();
            InputStreamReader inputs = null;
            BufferedReader buffer = null;
            try {
                inputs = new InputStreamReader(new FileInputStream("/proc/meminfo"));
                buffer = new BufferedReader(inputs);
                String line = "";
                while (true) {
                    line = buffer.readLine();
                    if (line == null) {
                        break;
                    }
                    int beginIndex = 0;
                    int endIndex = line.indexOf(":");
                    if (endIndex != -1) {
                        String key = line.substring(beginIndex, endIndex);
                        beginIndex = endIndex + 1;
                        endIndex = line.length();
                        String memory = line.substring(beginIndex, endIndex);
                        String value = memory.replace("kB", "").trim();
                        map.put(key, value);
                    }
                }

                long memTotal = Long.parseLong(map.get("MemTotal").toString());
                long memFree = Long.parseLong(map.get("MemFree").toString());
                long memused = memTotal - memFree;
                long buffers = Long.parseLong(map.get("Buffers").toString());
                long cached = Long.parseLong(map.get("Cached").toString());

                double usage = (double) (memused - buffers - cached) / memTotal * 100;
                BigDecimal b1 = new BigDecimal(usage);
                double memoryUsage = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                return memoryUsage;
            } catch (Exception e) {
                log.debug(e.toString());
            } finally {
                try {
                    buffer.close();
                    inputs.close();
                } catch (Exception e2) {
                    log.debug(e2.toString());
                }
            }

        }
        return 0.0;
    }
    /**
     * Window 和Linux 得到磁盘的使用率
     *
     * @return
     * @throws Exception
     */
    public static double getDiskUsage() throws Exception {
        double totalHD = 0;
        double usedHD = 0;
        if (osName.toLowerCase().contains("windows")
                || osName.toLowerCase().contains("win")) {
            long allTotal = 0;
            long allFree = 0;
            for (char c = 'A'; c <= 'Z'; c++) {
                String dirName = c + ":/";
                File win = new File(dirName);
                if (win.exists()) {
                    long total = (long) win.getTotalSpace();
                    long free = (long) win.getFreeSpace();
                    allTotal = allTotal + total;
                    allFree = allFree + free;
                }
            }
            Double precent = (Double) (1 - allFree * 1.0 / allTotal) * 100;
            BigDecimal b1 = new BigDecimal(precent);
            precent = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            return precent;
        } else {
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec("df -hl");// df -hl 查看硬盘空间
            BufferedReader in = null;
            try {
                in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String str = null;
                String[] strArray = null;
                while ((str = in.readLine()) != null) {
                    int m = 0;
                    strArray = str.split(" ");
                    for (String tmp : strArray) {
                        if (tmp.trim().length() == 0) {
                            continue;
                        }
                        ++m;
                        if (tmp.indexOf("G") != -1) {
                            if (m == 2) {
                                if (!tmp.equals("") && !tmp.equals("0")) {
                                    totalHD += Double.parseDouble(tmp.substring(0, tmp.length() - 1)) * 1024;
                                }
                            }
                            if (m == 3) {
                                if (!tmp.equals("none") && !tmp.equals("0")) {
                                    usedHD += Double.parseDouble(tmp.substring(0, tmp.length() - 1)) * 1024;
                                }
                            }
                        }
                        if (tmp.indexOf("M") != -1) {
                            if (m == 2) {
                                if (!tmp.equals("") && !tmp.equals("0")) {
                                    totalHD += Double.parseDouble(tmp.substring(0, tmp.length() - 1));
                                }
                            }
                            if (m == 3) {
                                if (!tmp.equals("none") && !tmp.equals("0")) {
                                    usedHD += Double.parseDouble(tmp.substring(0, tmp.length() - 1));
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                log.debug(e.toString());
            } finally {
                in.close();
            }
// 保留2位小数
            double precent = (usedHD / totalHD) * 100;
            BigDecimal b1 = new BigDecimal(precent);
            precent = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            return precent;
        }
    }
    // window读取cpu相关信息
    private static long[] readCpu(final Process proc) {
        long[] retn = new long[2];
        try {
            proc.getOutputStream().close();
            InputStreamReader ir = new InputStreamReader(proc.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line = input.readLine();
            if (line == null || line.length() < FAULTLENGTH) {
                return null;
            }
            int capidx = line.indexOf("Caption");
            int cmdidx = line.indexOf("CommandLine");
            int rocidx = line.indexOf("ReadOperationCount");
            int umtidx = line.indexOf("UserModeTime");
            int kmtidx = line.indexOf("KernelModeTime");
            int wocidx = line.indexOf("WriteOperationCount");
            long idletime = 0;
            long kneltime = 0;//读取物理设备时间
            long usertime = 0;//执行代码占用时间
            while ((line = input.readLine()) != null) {
                if (line.length() < wocidx) {
                    continue;
                }
// 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount
                String caption = substring(line, capidx, cmdidx - 1).trim();
//	System.out.println("caption:"+caption);
                String cmd = substring(line, cmdidx, kmtidx - 1).trim();
//	System.out.println("cmd:"+cmd);
                if (cmd.indexOf("wmic.exe") >= 0) {
                    continue;
                }
                String s1 = substring(line, kmtidx, rocidx - 1).trim();
                String s2 = substring(line, umtidx, wocidx - 1).trim();
                List digitS1 = getDigit(s1);
                List digitS2 = getDigit(s2);
                if (caption.equals("System Idle Process") || caption.equals("System")) {
                    if (s1.length() > 0) {
                        if (!digitS1.get(0).equals("") && digitS1.get(0) != null) {
                            idletime += Long.valueOf(digitS1.get(0)).longValue();
                        }
                    }
                    if (s2.length() > 0) {
                        if (!digitS2.get(0).equals("") && digitS2.get(0) != null) {
                            idletime += Long.valueOf(digitS2.get(0)).longValue();
                        }
                    }
                    continue;
                }
                if (s1.length() > 0) {
                    if (!digitS1.get(0).equals("") && digitS1.get(0) != null) {
                        kneltime += Long.valueOf(digitS1.get(0)).longValue();
                    }
                }
                if (s2.length() > 0) {
                    if (!digitS2.get(0).equals("") && digitS2.get(0) != null) {
                        kneltime += Long.valueOf(digitS2.get(0)).longValue();
                    }
                }
            }
            retn[0] = idletime;
            retn[1] = kneltime + usertime;

            return retn;
        } catch (Exception ex) {
            log.debug(ex.toString());
        } finally {
            try {
                proc.getInputStream().close();
            } catch (Exception e) {
                log.debug(e.toString());
            }
        }
        return null;
    }

    /**
     * 从字符串文本中获得数字
     *
     * @param text
     * @return
     */
    private static List getDigit(String text) {
        List digitList = new ArrayList();
        digitList.add(text.replaceAll("\\D", ""));
        return digitList;
    }

    /**
     * 由于String.subString对汉字处理存在问题(把一个汉字视为一个字节),因此在 包含汉字的字符串时存在隐患,现调整如下:
     *
     * @param src       要截取的字符串
     * @param start_idx 开始坐标(包括该坐标)
     * @param end_idx   截止坐标(包括该坐标)
     * @return
     */
    private static String substring(String src, int start_idx, int end_idx) {
        byte[] b = src.getBytes();
        String tgt = "";
        for (int i = start_idx; i <= end_idx; i++) {
            tgt += (char) b[i];
        }
        return tgt;
    }
    public static void main(String[] args) throws Exception {
        double cpuUsage = ComputerMonitorUtil.getCpuUsage();
//当前系统的内存使用率
        double memUsage = ComputerMonitorUtil.getMemUsage();
//当前系统的硬盘使用率
        double diskUsage = ComputerMonitorUtil.getDiskUsage();
        System.out.println("cpuUsage:" + cpuUsage);
        System.out.println("memUsage:" + memUsage);
        System.out.println("diskUsage:" + diskUsage);
    }
}
  • 获取系统系统相关序列号

	/**
     * 获取主板序列号
     * 
     * @return
     */
    public static String getMotherboardSN() {
        String result = "";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
 
            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
                    + "Set colItems = objWMIService.ExecQuery _ \n"
                    + "   (\"Select * from Win32_BaseBoard\") \n"
                    + "For Each objItem in colItems \n"
                    + "    Wscript.Echo objItem.SerialNumber \n"
                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
 
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec(
                    "cscript //NoLogo " + file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;
            }
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.trim();
    }
 
    /**
     * 获取硬盘序列号
     * 
     * @param drive
     *            盘符
     * @return
     */
    public static String getHardDiskSN(String drive) {
        String result = "";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
 
            String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
                    + "Set colDrives = objFSO.Drives\n"
                    + "Set objDrive = colDrives.item(\""
                    + drive
                    + "\")\n"
                    + "Wscript.Echo objDrive.SerialNumber"; // see note
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec(
                    "cscript //NoLogo " + file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;
            }
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.trim();
    }
 
    /**
     * 获取CPU序列号
     * 
     * @return
     */
    public static String getCPUSerial() {
        String result = "";
        try {
            File file = File.createTempFile("tmp", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
                    + "Set colItems = objWMIService.ExecQuery _ \n"
                    + "   (\"Select * from Win32_Processor\") \n"
                    + "For Each objItem in colItems \n"
                    + "    Wscript.Echo objItem.ProcessorId \n"
                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
 
            // + "    exit for  \r\n" + "Next";
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec(
                    "cscript //NoLogo " + file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;
            }
            input.close();
            file.delete();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
        if (result.trim().length() < 1 || result == null) {
            result = "无CPU_ID被读取";
        }
        return result.trim();
    }
 
    /**
     * 获取MAC地址,使用前请修改,只适合中文系统,并且名称为以太网适配器的网卡地址
     */
    @Deprecated
    public static String getMac() {
        String result = "";
        try {
 
            Process process = Runtime.getRuntime().exec("ipconfig /all");
 
            InputStreamReader ir = new InputStreamReader(process.getInputStream(),"GBK");
 
            LineNumberReader input = new LineNumberReader(ir);
 
            String line;
            
            while ((line = input.readLine()) != null){
            	if(line.indexOf("以太网适配器")!=-1){
            		 while ((line = input.readLine()) != null){
            			 if (line.indexOf("Physical Address") >=0||line.indexOf("物理地址")>=0) {
                             String MACAddr = line.substring(line.indexOf("-") - 2);
                             result = MACAddr;
                             break;
                         }
            		 }
            		 break;
            	}
            }
        } catch (java.io.IOException e) {
            System.err.println("IOException " + e.getMessage());
        }
        return result;
    }
    
    public static void main(String[] args) {
		System.out.println("CPU序列号:"+getCPUSerial());
	}
 
}
  • 获取ip及用户名

package com.github.wxiaoqi.demo;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 获取IP地址和机器名
 */
public class GetIPAddress {

	/**
	 * 获取本机的IP地址
	 * @return
	 * @throws UnknownHostException
	 */
	public static String getLocalIP() throws UnknownHostException {
		InetAddress addr = InetAddress.getLocalHost();
		return addr.getHostAddress();
	}

	/**
	 * 获取本机的机器名
	 * @return
	 * @throws UnknownHostException
	 */
	public static String getLocalHostName() throws UnknownHostException {
		InetAddress addr = InetAddress.getLocalHost();
		return addr.getHostName();
	}
	/**
	 * 根据域名获得主机的IP地址
	 * @param hostName	域名
	 * @return
	 * @throws UnknownHostException
	 */
	public static String getIPByName(String hostName)
			throws UnknownHostException {
		InetAddress addr = InetAddress.getByName(hostName);
		return addr.getHostAddress();
	}
	/**
	 * 根据域名获得主机所有的IP地址
	 * @param hostName	域名
	 * @return
	 * @throws UnknownHostException
	 */
	public static String[] getAllIPByName(String hostName)
			throws UnknownHostException {
		InetAddress[] addrs = InetAddress.getAllByName(hostName);
		String[] ips = new String[addrs.length];
		for (int i = 0; i < addrs.length; i++) {
			ips[i] = addrs[i].getHostAddress();
		}
		return ips;
	}
	
	public static void main(String[] args) throws UnknownHostException {
		// 获取本机的IP地址和机器名
		System.out.println("Local IP: " + GetIPAddress.getLocalIP());
		System.out.println("Local HostName: " + GetIPAddress.getLocalHostName());
	}
}

封装信息的工具类

  • 国家名与代码

package com.hz.tgb.common;

import com.hz.tgb.common.pojo.CountryInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 国家名称与代码
 * Created by hezhao on 2018/7/3 11:22.
 */
public class CountryUtil {

    /** 所有的国家信息列表 */
    public static final List COUNTRY_INFO_LIST = new ArrayList<>(233);
    /** 电话区号与国家信息键值对 */
    public static final Map COUNTRY_PHONE_CODE_MAP = new HashMap<>();
    /** 电话区号(带+号)与国家信息键值对 */
    public static final Map COUNTRY_PHONE_CODE_PLUS_MAP = new HashMap<>();
    /** 英文名称与国家信息键值对 */
    public static final Map COUNTRY_ENGLISH_NAME_MAP = new HashMap<>();
    /** 中文名称与国家信息键值对 */
    public static final Map COUNTRY_CHINESE_NAME_MAP = new HashMap<>();
    /** 国际域名缩写与国家信息键值对 */
    public static final Map COUNTRY_SHORT_NAME_MAP = new HashMap<>();

    static {
        initialCountryInfoList();
        initialCountryMap();
    }

    /**
     * 初始化所有国家信息
     */
    private static void initialCountryInfoList() {
        COUNTRY_INFO_LIST.add(new CountryInfo("Angola", "安哥拉", "AO", "244", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Afghanistan", "阿富汗", "AF", "93", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Albania", "阿尔巴尼亚", "AL", "355", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Algeria", "阿尔及利亚", "DZ", "213", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Andorra", "安道尔共和国", "AD", "376", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Anguilla", "安圭拉岛", "AI", "1264", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Antigua and Barbuda", "安提瓜和巴布达", "AG", "1268", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Argentina", "阿根廷", "AR", "54", "-11"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Armenia", "亚美尼亚", "AM", "374", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ascension", "阿森松", "", "247", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Australia ", "澳大利亚", "AU", "61", "+2"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Austria", "奥地利", "AT", "43", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Azerbaijan", "阿塞拜疆", "AZ", "994", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Bahamas", "巴哈马", "BS", "1242", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Bahrain", "巴林", "BH", "973", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Bangladesh", "孟加拉国", "BD", "880", "-2"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Barbados", "巴巴多斯", "BB", "1246", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Belarus", "白俄罗斯", "BY", "375", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Belgium", "比利时", "BE", "32", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Belize", "伯利兹", "BZ", "501", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Benin", "贝宁", "BJ", "229", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Bermuda Is.", "百慕大群岛", "BM", "1441", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Bolivia", "玻利维亚", "BO", "591", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Botswana", "博茨瓦纳", "BW", "267", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Brazil", "巴西", "BR", "55", "-11"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Brunei", "文莱", "BN", "673", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Bulgaria", "保加利亚", "BG", "359", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Burkina-faso", "布基纳法索", "BF", "226", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Burma", "缅甸", "MM", "95", "-1.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Burundi", "布隆迪", "BI", "257", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Cameroon", "喀麦隆", "CM", "237", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Canada", "加拿大", "CA", "1", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Cayman Is.", "开曼群岛", "", "1345", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Central African Republic", "中非共和国", "CF", "236", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Chad", "乍得", "TD", "235", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Chile", "智利", "CL", "56", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("China", "中国", "CN", "86", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Colombia", "哥伦比亚", "CO", "57", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Congo", "刚果", "CG", "242", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Cook Is.", "库克群岛", "CK", "682", "-18.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Costa Rica", "哥斯达黎加", "CR", "506", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Cuba", "古巴", "CU", "53", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Cyprus", "塞浦路斯", "CY", "357", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Czech Republic", "捷克", "CZ", "420", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Denmark", "丹麦", "DK", "45", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Djibouti", "吉布提", "DJ", "253", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Dominica Rep.", "多米尼加共和国", "DO", "1890", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ecuador", "厄瓜多尔", "EC", "593", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Egypt", "埃及", "EG", "20", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("EI Salvador", "萨尔瓦多", "SV", "503", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Estonia", "爱沙尼亚", "EE", "372", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ethiopia", "埃塞俄比亚", "ET", "251", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Fiji", "斐济", "FJ", "679", "+4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Finland", "芬兰", "FI", "358", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("France", "法国", "FR", "33", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("French Guiana", "法属圭亚那", "GF", "594", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Gabon", "加蓬", "GA", "241", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Gambia", "冈比亚", "GM", "220", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Georgia", "格鲁吉亚", "GE", "995", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Germany", "德国", "DE", "49", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ghana", "加纳", "GH", "233", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Gibraltar", "直布罗陀", "GI", "350", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Greece", "希腊", "GR", "30", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Grenada", "格林纳达", "GD", "1809", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Guam", "关岛", "GU", "1671", "+2"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Guatemala", "危地马拉", "GT", "502", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Guinea", "几内亚", "GN", "224", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Guyana", "圭亚那", "GY", "592", "-11"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Haiti", "海地", "HT", "509", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Honduras", "洪都拉斯", "HN", "504", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Hongkong", "香港", "HK", "852", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Hungary", "匈牙利", "HU", "36", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Iceland", "冰岛", "IS", "354", "-9"));
        COUNTRY_INFO_LIST.add(new CountryInfo("India", "印度", "IN", "91", "-2.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Indonesia", "印度尼西亚", "ID", "62", "-0.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Iran", "伊朗", "IR", "98", "-4.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Iraq", "伊拉克", "IQ", "96", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ireland", "爱尔兰", "IE", "353", "-4.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Israel", "以色列", "IL", "972", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Italy", "意大利", "IT", "39", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ivory Coast", "科特迪瓦", "", "225", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Jamaica", "牙买加", "JM", "1876", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Japan", "日本", "JP", "81", "+1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Jordan", "约旦", "JO", "962", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Kampuchea (Cambodia )", "柬埔寨", "KH", "855", "-1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Kazakstan", "哈萨克斯坦", "KZ", "327", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Kenya", "肯尼亚", "KE", "254", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Korea", "韩国", "KR", "82", "+1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Kuwait", "科威特", "KW", "965", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Kyrgyzstan", "吉尔吉斯坦", "KG", "331", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Laos", "老挝", "LA", "856", "-1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Latvia", "拉脱维亚", "LV", "371", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Lebanon", "黎巴嫩", "LB", "961", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Lesotho", "莱索托", "LS", "266", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Liberia", "利比里亚", "LR", "231", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Libya", "利比亚", "LY", "218", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Liechtenstein", "列支敦士登", "LI", "423", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Lithuania", "立陶宛", "LT", "370", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Luxembourg", "卢森堡", "LU", "352", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Macao", "澳门", "MO", "853", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Madagascar", "马达加斯加", "MG", "261", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Malawi", "马拉维", "MW", "265", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Malaysia", "马来西亚", "MY", "60", "-0.5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Maldives", "马尔代夫", "MV", "960", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Mali", "马里", "ML", "223", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Malta", "马耳他", "MT", "356", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Mariana Is", "马里亚那群岛", "", "1670", "+1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Martinique", "马提尼克", "", "596", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Mauritius", "毛里求斯", "MU", "230", "-4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Mexico", "墨西哥", "MX", "52", "-15"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Moldova Republic of", "摩尔多瓦", "MD", "373", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Monaco", "摩纳哥", "MC", "377", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Mongolia", "蒙古", "MN", "976", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Montserrat Is", "蒙特塞拉特岛", "MS", "1664", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Morocco", "摩洛哥", "MA", "212", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Mozambique", "莫桑比克", "MZ", "258", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Namibia", "纳米比亚", "NA", "264", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Nauru", "瑙鲁", "NR", "674", "+4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Nepal", "尼泊尔", "NP", "977", "-2.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Netheriands Antilles", "荷属安的列斯", "599", "", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Netherlands", "荷兰", "NL", "31", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("New Zealand", "新西兰", "NZ", "64", "+4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Nicaragua", "尼加拉瓜", "NI", "505", "-14"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Niger", "尼日尔", "NE", "227", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Nigeria", "尼日利亚", "NG", "234", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("North Korea", "朝鲜", "KP", "850", "+1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Norway", "挪威", "NO", "47", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Oman", "阿曼", "OM", "968", "-4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Pakistan", "巴基斯坦", "PK", "92", "-2.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Panama", "巴拿马", "PA", "507", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Papua New Cuinea", "巴布亚新几内亚", "PG", "675", "+2"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Paraguay", "巴拉圭", "PY", "595", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Peru", "秘鲁", "PE", "51", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Philippines", "菲律宾", "PH", "63", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Poland", "波兰", "PL", "48", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("French Polynesia", "法属玻利尼西亚", "PF", "689", "+3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Portugal", "葡萄牙", "PT", "351", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Puerto Rico", "波多黎各", "PR", "1787", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Qatar", "卡塔尔", "QA", "974", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Reunion", "留尼旺", "", "262", "-4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Romania", "罗马尼亚", "RO", "40", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Russia", "俄罗斯", "RU", "7", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Saint Lueia", "圣卢西亚", "LC", "1758", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Saint Vincent", "圣文森特岛", "VC", "1784", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Samoa Eastern", "东萨摩亚(美)", "", "684", "-19"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Samoa Western", "西萨摩亚", "", "685", "-19"));
        COUNTRY_INFO_LIST.add(new CountryInfo("San Marino", "圣马力诺", "SM", "978", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Sao Tome and Principe", "圣多美和普林西比", "ST", "239", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Saudi Arabia", "沙特阿拉伯", "SA", "966", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Senegal", "塞内加尔", "SN", "221", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Seychelles", "塞舌尔", "SC", "248", "-4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Sierra Leone", "塞拉利昂", "SL", "232", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Singapore", "新加坡", "SG", "65", "+0.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Slovakia", "斯洛伐克", "SK", "421", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Slovenia", "斯洛文尼亚", "SI", "386", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Solomon Is", "所罗门群岛", "SB", "677", "+3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Somali", "索马里", "SO", "252", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("South Africa", "南非", "ZA", "27", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Spain", "西班牙", "ES", "34", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Sri Lanka", "斯里兰卡", "LK", "94", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Sudan", "苏丹", "SD", "249", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Suriname", "苏里南", "SR", "597", "-11.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Swaziland", "斯威士兰", "SZ", "268", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Sweden", "瑞典", "SE", "46", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Switzerland", "瑞士", "CH", "41", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Syria", "叙利亚", "SY", "963", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Taiwan", "台湾", "TW", "886", "0"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Tajikstan", "塔吉克斯坦", "TJ", "992", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Tanzania", "坦桑尼亚", "TZ", "255", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Thailand", "泰国", "TH", "66", "-1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Togo", "多哥", "TG", "228", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Tonga", "汤加", "TO", "676", "+4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Trinidad and Tobago", "特立尼达和多巴哥", "TT", "1809", "-12"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Tunisia", "突尼斯", "TN", "216", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Turkey", "土耳其", "TR", "90", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Turkmenistan", "土库曼斯坦", "TM", "993", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Uganda", "乌干达", "UG", "256", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Ukraine", "乌克兰", "UA", "380", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("United Arab Emirates", "阿拉伯联合酋长国", "AE", "971", "-4"));
        COUNTRY_INFO_LIST.add(new CountryInfo("United Kiongdom", "英国", "UK", "44", "-8"));
        COUNTRY_INFO_LIST.add(new CountryInfo("United States of America", "美国", "US", "1", "-13"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Uruguay", "乌拉圭", "UY", "598", "-10.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Uzbekistan", "乌兹别克斯坦", "UZ", "233", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Venezuela", "委内瑞拉", "VE", "58", "-12.3"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Vietnam", "越南", "VN", "84", "-1"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Yemen", "也门", "YE", "967", "-5"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Yugoslavia", "南斯拉夫", "YU", "381", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Zimbabwe", "津巴布韦", "ZW", "263", "-6"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Zaire", "扎伊尔", "ZR", "243", "-7"));
        COUNTRY_INFO_LIST.add(new CountryInfo("Zambia", "赞比亚", "ZM", "260", "-6"));
    }

    /**
     * 初始化国家信息键值对
     */
    private static void initialCountryMap() {
        for (CountryInfo countryInfo : COUNTRY_INFO_LIST) {
            COUNTRY_PHONE_CODE_MAP.put(countryInfo.getPhoneCode(), countryInfo);
            COUNTRY_PHONE_CODE_PLUS_MAP.put("+" + countryInfo.getPhoneCode(), countryInfo);
            COUNTRY_ENGLISH_NAME_MAP.put(countryInfo.getEnglishName(), countryInfo);
            COUNTRY_CHINESE_NAME_MAP.put(countryInfo.getChineseName(), countryInfo);
            COUNTRY_SHORT_NAME_MAP.put(countryInfo.getShortName(), countryInfo);
        }
    }

    public static void main(String[] args) {
        // 根据电话区号查询国家信息
        CountryInfo countryInfo = CountryUtil.COUNTRY_PHONE_CODE_PLUS_MAP.get("+86");
        System.out.println(countryInfo);

        // 根据缩写查询国家信息
        CountryInfo countryInfo2 = CountryUtil.COUNTRY_SHORT_NAME_MAP.get("JP");
        System.out.println(countryInfo2);
    }

}


// 附录:国家代号(CountryCode)与区号
// 拷贝自:https://www.cnblogs.com/catvi/archive/2009/01/06/1952961.html
/*
Countries and Regions	    国家或地区   	    国际域名缩写	电话代码	时差
===================================================================

Angola	                    安哥拉	            AO	    244	    -7
Afghanistan	                阿富汗	            AF	    93	    0
Albania	                    阿尔巴尼亚	        AL	    355	    -7
Algeria	                    阿尔及利亚	        DZ	    213	    -8
Andorra	                    安道尔共和国	        AD	    376	    -8
Anguilla	                安圭拉岛	            AI	    1264    -12
Antigua and Barbuda	        安提瓜和巴布达	    AG	    1268    -12
Argentina	                阿根廷	            AR	    54	    -11
Armenia	                    亚美尼亚	            AM	    374	    -6
Ascension	                阿森松	 	                247	    -8
Australia           	    澳大利亚	            AU	    61	    +2
Austria	                    奥地利	            AT	    43	    -7
Azerbaijan	                阿塞拜疆	            AZ	    994	    -5
Bahamas	                    巴哈马	            BS	    1242    -13
Bahrain	                    巴林	                BH	    973	    -5
Bangladesh          	    孟加拉国	            BD	    880	    -2
Barbados	                巴巴多斯	            BB	    1246    -12
Belarus	                    白俄罗斯	            BY	    375	    -6
Belgium	                    比利时	            BE	    32	    -7
Belize	                    伯利兹	            BZ	    501	    -14
Benin	                    贝宁              	BJ	    229	    -7
Bermuda Is.             	百慕大群岛	        BM	    1441    -12
Bolivia	                    玻利维亚	            BO	    591 	-12
Botswana	                博茨瓦纳	            BW	    267	    -6
Brazil	                    巴西              	BR	    55	    -11
Brunei	                    文莱	                BN	    673	    0
Bulgaria	                保加利亚	            BG	    359 	-6
Burkina-faso	            布基纳法索	        BF	    226	    -8
Burma	                    缅甸	                MM	    95	    -1.3
Burundi	                    布隆迪	            BI	    257	    -6
Cameroon	                喀麦隆	            CM	    237	    -7
Canada	                    加拿大	            CA	    1       -13
Cayman Is.	                开曼群岛	 	                1345    -13
Central African Republic    中非共和国	        CF	    236 	-7
Chad	                    乍得	                TD	    235	    -7
Chile	                    智利	                CL	    56	    -13
China	                    中国	                CN	    86	    0
Colombia	                哥伦比亚	            CO	    57	    0
Congo	                    刚果	                CG	    242	    -7
Cook Is.	                库克群岛	            CK	    682	    -18.3
Costa Rica	                哥斯达黎加	        CR	    506	    -14
Cuba	                    古巴              	CU	    53	    -13
Cyprus	                    塞浦路斯	            CY	    357	    -6
Czech Republic	            捷克	                CZ	    420	    -7
Denmark	                    丹麦	                DK	    45	    -7
Djibouti	                吉布提	            DJ	    253	    -5
Dominica Rep.	            多米尼加共和国	    DO	    1890    -13
Ecuador	                    厄瓜多尔	            EC	    593	    -13
Egypt	                    埃及	                EG	    20	    -6
EI Salvador	                萨尔瓦多	            SV	    503	    -14
Estonia	                    爱沙尼亚            	EE	    372	    -5
Ethiopia	                埃塞俄比亚	        ET	    251	    -5
Fiji	                    斐济	                FJ	    679	    +4
Finland	                    芬兰	                FI	    358	    -6
France	                    法国	                FR	    33	    -8
French Guiana	            法属圭亚那	        GF	    594	    -12
Gabon	                    加蓬	                GA	    241	    -7
Gambia	                    冈比亚	            GM	    220	    -8
Georgia	                    格鲁吉亚	            GE	    995	    0
Germany	                    德国	                DE	    49	    -7
Ghana	                    加纳	                GH	    233	    -8
Gibraltar	                直布罗陀	            GI	    350	    -8
Greece	                    希腊	                GR	    30	    -6
Grenada	                    格林纳达	            GD	    1809    -14
Guam	                    关岛	                GU	    1671    +2
Guatemala	                危地马拉	            GT	    502	    -14
Guinea	                    几内亚	            GN	    224	    -8
Guyana	                    圭亚那	            GY	    592	    -11
Haiti	                    海地  	            HT	    509	    -13
Honduras	                洪都拉斯	            HN	    504	    -14
Hongkong	                香港	                HK	    852 	0
Hungary	                    匈牙利	            HU	    36	    -7
Iceland	                    冰岛	                IS	    354	    -9
India	                    印度	                IN	    91	    -2.3
Indonesia	                印度尼西亚	        ID	    62	    -0.3
Iran	                    伊朗	                IR	    98	    -4.3
Iraq	                    伊拉克	            IQ	    964	    -5
Ireland	                    爱尔兰	            IE	    353	    -4.3
Israel	                    以色列	            IL	    972	    -6
Italy	                    意大利	            IT	    39	    -7
Ivory Coast	                科特迪瓦	 	                225	    -6
Jamaica	                    牙买加	            JM	    1876    -12
Japan	                    日本	                JP	    81	    +1
Jordan	                    约旦  	            JO	    962	    -6
Kampuchea (Cambodia )	    柬埔寨	            KH	    855	    -1
Kazakstan	                哈萨克斯坦	        KZ	    327	    -5
Kenya	                    肯尼亚	            KE	    254	    -5
Korea	                    韩国  	            KR	    82	    +1
Kuwait	                    科威特	            KW	    965	    -5
Kyrgyzstan	                吉尔吉斯坦	        KG	    331	    -5
Laos	                    老挝	                LA	    856	    -1
Latvia	                    拉脱维亚	            LV	    371	    -5
Lebanon	                    黎巴嫩	            LB	    961	    -6
Lesotho	                    莱索托	            LS	    266	    -6
Liberia	                    利比里亚	            LR	    231	    -8
Libya	                    利比亚	            LY	    218	    -6
Liechtenstein	            列支敦士登	        LI	    423	    -7
Lithuania	                立陶宛	            LT	    370	    -5
Luxembourg	                卢森堡	            LU	    352	    -7
Macao	                    澳门              	MO	    853	    0
Madagascar	                马达加斯加	        MG	    261	    -5
Malawi	                    马拉维	            MW	    265	    -6
Malaysia	                马来西亚	            MY	    60	    -0.5
Maldives	                马尔代夫	            MV	    960	    -7
Mali	                    马里              	ML	    223	    -8
Malta	                    马耳他	            MT	    356	    -7
Mariana Is	                马里亚那群岛	 	            1670    +1
Martinique	                马提尼克	 	                596	    -12
Mauritius	                毛里求斯	            MU	    230	    -4
Mexico	                    墨西哥	            MX	    52	    -15
Moldova Republic of	        摩尔多瓦	            MD	    373 	-5
Monaco	                    摩纳哥	            MC	    377	    -7
Mongolia	                蒙古	                MN	    976	    0
Montserrat Is	            蒙特塞拉特岛	        MS	    1664    -12
Morocco	                    摩洛哥	            MA	    212	    -6
Mozambique	                莫桑比克	            MZ	    258	    -6
Namibia	                    纳米比亚	            NA	    264	    -7
Nauru	                    瑙鲁              	NR	    674	    +4
Nepal	                    尼泊尔	            NP	    977	    -2.3
Netheriands Antilles	    荷属安的列斯	 	            599	    -12
Netherlands	                荷兰	                NL	    31	    -7
New Zealand	                新西兰	            NZ	    64	    +4
Nicaragua	                尼加拉瓜	            NI	    505	    -14
Niger	                    尼日尔	            NE	    227	    -8
Nigeria	                    尼日利亚	            NG	    234	    -7
North Korea	                朝鲜	                KP	    850	    +1
Norway	                    挪威	                NO	    47	    -7
Oman	                    阿曼	                OM	    968	    -4
Pakistan	                巴基斯坦	            PK	    92	    -2.3
Panama	                    巴拿马	            PA	    507	    -13
Papua New Cuinea	        巴布亚新几内亚	    PG	    675	    +2
Paraguay	                巴拉圭	            PY	    595	    -12
Peru	                    秘鲁	                PE	    51	    -13
Philippines	                菲律宾	            PH	    63	    0
Poland	                    波兰	                PL	    48	    -7
French Polynesia	        法属玻利尼西亚	    PF	    689	    +3
Portugal	                葡萄牙	            PT	    351	    -8
Puerto Rico	                波多黎各	            PR	    1787	-12
Qatar	                    卡塔尔	            QA	    974	    -5
Reunion	                    留尼旺	             	    262 	-4
Romania	                    罗马尼亚            	RO	    40	    -6
Russia	                    俄罗斯	            RU	    7	    -5
Saint Lueia	                圣卢西亚	            LC	    1758	-12
Saint Vincent	            圣文森特岛	        VC	    1784	-12
Samoa Eastern	            东萨摩亚(美)	 	            684 	-19
Samoa Western	            西萨摩亚	 	                685 	-19
San Marino	                圣马力诺	            SM	    378	    -7
Sao Tome and Principe	    圣多美和普林西比	    ST	    239	    -8
Saudi Arabia	            沙特阿拉伯	        SA	    966	    -5
Senegal	                    塞内加尔	            SN	    221 	-8
Seychelles	                塞舌尔	            SC	    248 	-4
Sierra Leone	            塞拉利昂	            SL	    232 	-8
Singapore	                新加坡	            SG	    65	    +0.3
Slovakia	                斯洛伐克	            SK	    421 	-7
Slovenia	                斯洛文尼亚	        SI	    386 	-7
Solomon Is	                所罗门群岛	        SB	    677	    +3
Somali	                    索马里	            SO	    252 	-5
South Africa	            南非	                ZA	    27	    -6
Spain	                    西班牙	            ES	    34	    -8
Sri Lanka	                斯里兰卡	            LK	    94	    0
Sudan	                    苏丹	                SD	    249	    -6
Suriname	                苏里南	            SR	    597	    -11.3
Swaziland	                斯威士兰	            SZ  	268 	-6
Sweden	                    瑞典	                SE	    46	    -7
Switzerland	                瑞士	                CH	    41	    -7
Syria	                    叙利亚	            SY	    963	    -6
Taiwan	                    台湾	                TW	    886	    0
Tajikstan	                塔吉克斯坦	        TJ	    992	    -5
Tanzania	                坦桑尼亚	            TZ	    255	    -5
Thailand	                泰国	                TH	    66	    -1
Togo	                    多哥	                TG	    228	    -8
Tonga	                    汤加	                TO	    676 	+4
Trinidad and Tobago	        特立尼达和多巴哥	    TT	    1809    -12
Tunisia	                    突尼斯	            TN	    216	    -7
Turkey	                    土耳其	            TR	    90	    -6
Turkmenistan	            土库曼斯坦	        TM	    993	    -5
Uganda	                    乌干达	            UG	    256	    -5
Ukraine	                    乌克兰	            UA	    380	    -5
United Arab Emirates	    阿拉伯联合酋长国	    AE	    971	    -4
United Kiongdom	            英国	                UK	    44	    -8
United States of America	美国	                US	    1	    -13
Uruguay	                    乌拉圭	            UY	    598	    -10.3
Uzbekistan	                乌兹别克斯坦	        UZ	    233 	-5
Venezuela	                委内瑞拉	            VE	    58	    -12.3
Vietnam	                    越南	                VN  	84	    -1
Yemen	                    也门              	YE	    967	    -5
Yugoslavia	                南斯拉夫	            YU  	381	    -7
Zimbabwe	                津巴布韦	            ZW	    263	    -6
Zaire	                    扎伊尔	            ZR	    243	    -7
Zambia	                    赞比亚	            ZM	    260	    -6

*/
package com.web.utils;
public class CountryInfo {
    private String phoneCode;
    private String englishName;
    private String chineseName;
    private String shortName;
    private String timeEquation;

    public String getPhoneCode() {
        return phoneCode;
    }
    public void setPhoneCode(String phoneCode) {
        this.phoneCode = phoneCode;
    }
    public String getTimeEquation() {
        return timeEquation;
    }
    public void setTimeEquation(String code) {
        this.timeEquation = code;
    }
    public String getEnglishName() {
        return englishName;
    }
    public void setEnglishName(String englishName) {
        this.englishName = englishName;
    }
    public String getChineseName() {
        return chineseName;
    }
    public void setChineseName(String chineseName) {
        this.chineseName = chineseName;
    }
    public String getShortName() {
        return shortName;
    }
    public void setShortName(String shortName) {
        this.shortName = shortName;
    }
    public CountryInfo() {
    }
    public CountryInfo( String englishName, String chineseName, String shortName,String phoneCode,String timeEquation) {
        this.phoneCode = phoneCode;
        this.englishName = englishName;
        this.chineseName = chineseName;
        this.shortName = shortName;
        this.timeEquation = timeEquation;
    }
}

 

银行卡信息查询

package com.hz.tgb.common;


/**
 * 银行卡工具类
 * 
 */
public class BankCardUtil {
	/*
	 * 当你输入信用卡号码的时候,有没有担心输错了而造成损失呢?其实可以不必这么担心,
	 * 因为并不是一个随便的信用卡号码都是合法的,它必须通过Luhn算法来验证通过。 该校验的过程:
	 * 1、从卡号最后一位数字开始,逆向将奇数位(1、3、5等等)相加。
	 * 2、从卡号最后一位数字开始,逆向将偶数位数字,先乘以2(如果乘积为两位数,则将其减去9),再求和。
	 * 3、将奇数位总和加上偶数位总和,结果应该可以被10整除。 例如,卡号是:5432123456788881
	 * 则奇数、偶数位(用红色标出)分布:5432123456788881 奇数位和=35 偶数位乘以2(有些要减去9)的结果:1 6 2 6 1 5 7
	 * 7,求和=35。 最后35+35=70 可以被10整除,认定校验通过。
	 * 请编写一个程序,从键盘输入卡号,然后判断是否校验通过。通过显示:“成功”,否则显示“失败”。 比如,用户输入:356827027232780
	 * 程序输出:成功
	 */


	public static void main(String[] args) {

		String[] cards = {
				"6228480402564890018",
				"6228480402637874213",
				"6228481552887309119",
				"6228480801416266113",
				"6228481698729890079",
				"621661280000447287",
				"6222081106004039591",
		};

		for (int i = 0; i < cards.length; i++) {
			System.out.println("银行卡号:" + cards[i] + "  check code: " + getBankCardCheckCode(cards[i].substring(0, cards[i].length() - 1))
					+ " 是否为银行卡: " + checkBankCard(cards[i]) + " 卡种:" + getNameOfBank(cards[i]));
		}
	}
	
	private BankCardUtil(){
		// 私有类构造方法
	}

	/**
	 * 校验银行卡卡号
	 * 
	 * @param cardId
	 *            银行卡号
	 * @return 银行卡号符合校验规则,false 银行卡号不符合校验规则
	 */
	public static boolean checkBankCard(String cardId) {
		
		if (cardId == null || cardId.length() < 16 || cardId.length() > 19) {
			return false;
		}
		
		char bit = getBankCardCheckCode(cardId
				.substring(0, cardId.length() - 1));
		if (bit == 'N') {
			return false;
		}
		return cardId.charAt(cardId.length() - 1) == bit;
	}

	/**
	 * 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位
	 * 
	 * @param nonCheckCodeCardId
	 *            不包含最后一位的银行卡号
	 * @return 银行卡号校验位
	 */
	private static char getBankCardCheckCode(String nonCheckCodeCardId) {
		if (nonCheckCodeCardId == null
				|| nonCheckCodeCardId.trim().length() == 0
				|| !nonCheckCodeCardId.matches("\\d+")) {
			// 如果传的不是数据返回N
			return 'N';
		}
		char[] chs = nonCheckCodeCardId.trim().toCharArray();
		int luhnSum = 0;
		for (int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
			int k = chs[i] - '0';
			if (j % 2 == 0) {
				k *= 2;
				k = k / 10 + k % 10;
			}
			luhnSum += k;
		}
		return (luhnSum % 10 == 0) ? '0' : (char) ((10 - luhnSum % 10) + '0');
	}

	/**
	 * 传入卡号 得到银行名称
	 * 
	 * @param cardId
	 * @return
	 */
	public static String getNameOfBank(String cardId) {
		int bin = 0, index = 0;

		if (cardId == null || cardId.length() < 16 || cardId.length() > 19) {
			return "银行卡号错误";
		}
		// 6位Bin号
		String cardBin = cardId.substring(0, 6);

		if (!isNumeric(cardBin)) {
			return "银行卡号前六位不是数字";
		}

		bin = Integer.valueOf(cardBin);
		index = binarySearch(bankBin, bin);
		if (index == -1 || index > bankName.length) {
			return "无法识别银行卡所属银行名称";
		}
		return bankName[index];

	}

	// 查找方法
	private static int binarySearch(int[] srcArray, int des) {
		int low = 0;
		int high = srcArray.length;
		while (low < high) {

			if (des == srcArray[low]) {
				return low;
			}
			low++;
		}
		return -1;
	}

	// 检验数字
	public static boolean isNumeric(String str) {
		if (str == null) {
			return false;
		}
		int sz = str.length();
		for (int i = 0; i < sz; i++) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	

	// BIN号
	// 银行卡是由”发卡行标识代码 + 自定义 + 校验码 “等部分组成的
	// 银联标准卡与以往发行的银行卡最直接的区别就是其卡号前6位数字的不同。
	// 银行卡卡号的前6位是用来表示发卡银行或机构的,称为“发卡行识别码”(Bank Identification Number,缩写为“BIN”)。
	// 银联标准卡是由国内各家商业银行(含邮储、信用社)共同发行、符合银联业务规范和技术标准、卡正面右下角带有“银联”标识(目前,新发行的银联标准卡一定带有国际化的银联新标识,新发的非银联标准卡使用旧的联网通用银联标识)、
	// 卡号前6位为622126至622925之一的银行卡,是中国银行卡产业共有的民族品牌。
	private static final int[] bankBin = { 102033, 103000, 185720, 303781,
			356827, 356828, 356833, 356835, 356837, 356838, 356839, 356840,
			356885, 356886, 356887, 356888, 356889, 356890, 370246, 370247,
			370248, 370249, 400360, 400937, 400938, 400939, 400940, 400941,
			400942, 402658, 402673, 402791, 403361, 403391, 404117, 404157,
			404171, 404172, 404173, 404174, 404738, 404739, 405512, 405512,
			406252, 406254, 406365, 407405, 409665, 409666, 409667, 409668,
			409669, 409670, 409671, 409672, 410062, 412962, 412963, 415599,
			421317, 421349, 421393, 421437, 421865, 421869, 421870, 421871,
			422160, 422161, 424106, 424107, 424108, 424109, 424110, 424111,
			424902, 425862, 427010, 427018, 427019, 427020, 427028, 427029,
			427038, 427039, 427062, 427064, 427571, 428911, 431502, 431502,
			433666, 433670, 433680, 434061, 434062, 435744, 435745, 436718,
			436728, 436738, 436742, 436745, 436748, 436768, 438088, 438125,
			438126, 438588, 438589, 438600, 439188, 439225, 439227, 442729,
			442730, 451289, 451291, 451804, 451804, 451810, 451810, 453242,
			456351, 456418, 458060, 458060, 458071, 458071, 458123, 458124,
			468203, 472067, 472068, 479228, 479229, 481699, 486466, 486493,
			486494, 486497, 487013, 489592, 489734, 489735, 489736, 491020,
			491020, 491031, 491032, 491040, 493427, 493878, 498451, 504923,
			510529, 512315, 512316, 512411, 512412, 512425, 512431, 512466,
			512695, 512732, 514906, 514957, 514958, 517636, 518212, 518364,
			518378, 518379, 518474, 518475, 518476, 518710, 518718, 519412,
			519498, 520082, 520108, 520131, 520152, 520169, 520194, 520382,
			521899, 522153, 523036, 524011, 524047, 524070, 524091, 524094,
			524864, 524865, 525498, 525745, 525746, 526410, 526855, 527414,
			528020, 528931, 528948, 530970, 530980, 530980, 530990, 532420,
			532430, 532450, 532458, 535910, 535910, 535918, 537830, 540297,
			540838, 541068, 541709, 543159, 544033, 545619, 545623, 545947,
			547628, 547648, 547766, 547766, 548259, 548844, 552245, 552288,
			552534, 552587, 552599, 552742, 552794, 552801, 552853, 553131,
			553242, 556610, 556617, 558360, 558730, 558808, 558809, 558868,
			558868, 558894, 558895, 558916, 566666, 584016, 601100, 601101,
			601121, 601122, 601123, 601124, 601125, 601126, 601127, 601128,
			601131, 601136, 601137, 601138, 601140, 601142, 601143, 601144,
			601145, 601146, 601147, 601148, 601149, 601174, 601177, 601178,
			601179, 601186, 601187, 601188, 601189, 601382, 601382, 601428,
			601428, 601428, 601428, 602907, 602907, 602969, 602969, 603128,
			603128, 603367, 603367, 603445, 603445, 603506, 603506, 603601,
			603601, 603601, 603601, 603601, 603601, 603602, 603602, 603694,
			603694, 603708, 603708, 621021, 621201, 621977, 621977, 622126,
			622126, 622127, 622127, 622127, 622127, 622128, 622128, 622129,
			622129, 622131, 622131, 622132, 622132, 622133, 622133, 622134,
			622134, 622135, 622135, 622136, 622136, 622137, 622137, 622138,
			622138, 622139, 622139, 622140, 622140, 622141, 622141, 622143,
			622143, 622146, 622146, 622147, 622147, 622148, 622148, 622149,
			622149, 622150, 622150, 622151, 622151, 622152, 622152, 622153,
			622153, 622154, 622154, 622155, 622155, 622156, 622156, 622165,
			622165, 622166, 622166, 622168, 622168, 622169, 622169, 622178,
			622178, 622179, 622179, 622184, 622184, 622188, 622188, 622199,
			622199, 622200, 622200, 622202, 622202, 622203, 622203, 622208,
			622208, 622210, 622210, 622211, 622211, 622212, 622212, 622213,
			622213, 622214, 622214, 622215, 622215, 622220, 622220, 622225,
			622225, 622230, 622230, 622235, 622235, 622240, 622240, 622245,
			622245, 622250, 622250, 622251, 622251, 622252, 622252, 622253,
			622253, 622254, 622254, 622258, 622258, 622259, 622259, 622260,
			622260, 622261, 622261, 622280, 622280, 622291, 622291, 622292,
			622292, 622301, 622301, 622302, 622302, 622303, 622303, 622305,
			622305, 622307, 622307, 622308, 622308, 622310, 622310, 622311,
			622311, 622312, 622312, 622316, 622316, 622318, 622318, 622319,
			622319, 622321, 622321, 622322, 622322, 622323, 622323, 622324,
			622324, 622325, 622325, 622327, 622327, 622328, 622328, 622329,
			622329, 622331, 622331, 622332, 622332, 622333, 622333, 622335,
			622335, 622336, 622336, 622337, 622337, 622338, 622338, 622339,
			622339, 622340, 622340, 622341, 622341, 622342, 622342, 622343,
			622343, 622345, 622345, 622346, 622346, 622347, 622347, 622348,
			622348, 622349, 622349, 622350, 622350, 622351, 622351, 622352,
			622352, 622353, 622353, 622355, 622355, 622358, 622358, 622359,
			622359, 622360, 622360, 622361, 622361, 622362, 622362, 622363,
			622363, 622365, 622365, 622366, 622366, 622367, 622367, 622368,
			622368, 622369, 622369, 622370, 622370, 622371, 622371, 622373,
			622373, 622375, 622375, 622376, 622376, 622377, 622377, 622378,
			622378, 622379, 622379, 622382, 622382, 622383, 622383, 622384,
			622384, 622385, 622385, 622386, 622386, 622387, 622387, 622388,
			622388, 622389, 622389, 622391, 622391, 622392, 622392, 622393,
			622393, 622394, 622394, 622395, 622395, 622396, 622396, 622397,
			622397, 622398, 622399, 622399, 622400, 622400, 622406, 622406,
			622407, 622407, 622411, 622411, 622412, 622412, 622413, 622413,
			622415, 622415, 622418, 622418, 622420, 622420, 622421, 622421,
			622422, 622422, 622423, 622423, 622425, 622425, 622426, 622426,
			622427, 622427, 622428, 622428, 622429, 622429, 622432, 622432,
			622434, 622434, 622435, 622435, 622436, 622436, 622439, 622439,
			622440, 622440, 622441, 622441, 622442, 622442, 622443, 622443,
			622447, 622447, 622448, 622448, 622449, 622449, 622450, 622450,
			622451, 622451, 622452, 622452, 622453, 622453, 622456, 622456,
			622459, 622459, 622462, 622462, 622463, 622463, 622466, 622466,
			622467, 622467, 622468, 622468, 622470, 622470, 622471, 622471,
			622472, 622472, 622476, 622476, 622477, 622477, 622478, 622478,
			622481, 622481, 622485, 622485, 622486, 622486, 622487, 622487,
			622487, 622487, 622488, 622488, 622489, 622489, 622490, 622490,
			622490, 622490, 622491, 622491, 622491, 622491, 622492, 622492,
			622492, 622492, 622493, 622493, 622495, 622495, 622496, 622496,
			622498, 622498, 622499, 622499, 622500, 622500, 622506, 622506,
			622509, 622509, 622510, 622510, 622516, 622516, 622517, 622517,
			622518, 622518, 622519, 622519, 622521, 622521, 622522, 622522,
			622523, 622523, 622525, 622525, 622526, 622526, 622538, 622538,
			622546, 622546, 622547, 622547, 622548, 622548, 622549, 622549,
			622550, 622550, 622561, 622561, 622562, 622562, 622563, 622563,
			622575, 622575, 622576, 622576, 622577, 622577, 622578, 622578,
			622579, 622579, 622580, 622580, 622581, 622581, 622582, 622582,
			622588, 622588, 622598, 622598, 622600, 622600, 622601, 622601,
			622602, 622602, 622603, 622603, 622615, 622615, 622617, 622617,
			622619, 622619, 622622, 622622, 622630, 622630, 622631, 622631,
			622632, 622632, 622633, 622633, 622650, 622650, 622655, 622655,
			622658, 622658, 622660, 622660, 622678, 622678, 622679, 622679,
			622680, 622680, 622681, 622681, 622682, 622682, 622684, 622684,
			622688, 622688, 622689, 622689, 622690, 622690, 622691, 622691,
			622692, 622692, 622696, 622696, 622698, 622698, 622700, 622700,
			622725, 622725, 622728, 622728, 622750, 622750, 622751, 622751,
			622752, 622752, 622753, 622753, 622754, 622755, 622755, 622756,
			622756, 622757, 622757, 622758, 622758, 622759, 622759, 622760,
			622760, 622761, 622761, 622762, 622762, 622763, 622763, 622770,
			622770, 622777, 622777, 622821, 622821, 622822, 622822, 622823,
			622823, 622824, 622824, 622825, 622825, 622826, 622826, 622827,
			622836, 622836, 622837, 622837, 622840, 622840, 622841, 622842,
			622843, 622844, 622844, 622845, 622845, 622846, 622846, 622847,
			622847, 622848, 622848, 622849, 622855, 622855, 622856, 622856,
			622857, 622857, 622858, 622858, 622859, 622859, 622860, 622860,
			622861, 622861, 622864, 622864, 622865, 622865, 622866, 622866,
			622867, 622867, 622869, 622869, 622870, 622870, 622871, 622871,
			622877, 622877, 622878, 622878, 622879, 622879, 622880, 622880,
			622881, 622881, 622882, 622882, 622884, 622884, 622885, 622885,
			622886, 622886, 622891, 622891, 622892, 622892, 622893, 622893,
			622895, 622895, 622897, 622897, 622898, 622898, 622900, 622900,
			622901, 622901, 622908, 622908, 622909, 622909, 622940, 622982,
			628218, 628288, 628366, 628368, 650600, 650600, 650700, 650700,
			650800, 650800, 650900, 650900, 682900, 682900, 683970, 683970,
			685800, 685800, 685800, 685800, 685800, 685800, 690755, 690755,
			690755, 690755, 694301, 694301, 695800, 695800, 843010, 843010,
			843360, 843360, 843420, 843420, 843610, 843610, 843730, 843730,
			843800, 843800, 843850, 843850, 843900, 843900, 870000, 870000,
			870100, 870100, 870300, 870300, 870400, 870400, 870500, 870500,
			888000, 888000, 940056, 955880, 955881, 955882, 955888, 984301,
			998800 };

	/**
	 * 发卡行.卡种名称
	 */
	private static final String[] bankName = { "广东发展银行.广发理财通", "农业银行.金穗借记卡",
			"昆明农联社.金碧卡", "中国光大银行.阳光爱心卡", "上海银行.双币种申卡贷记卡个人金卡",
			"上海银行.双币种申卡贷记卡个人普卡", "中国银行.中银JCB卡金卡", "中国银行.中银JCB卡普卡",
			"中国光大银行.阳光商旅信用卡", "中国光大银行.阳光商旅信用卡", "中国光大银行.阳光商旅信用卡",
			"中国光大银行.阳光商旅信用卡", "招商银行.招商银行银行信用卡", "招商银行.招商银行银行信用卡",
			"招商银行.招商银行银行信用卡", "招商银行.招商银行银行信用卡", "招商银行.招商银行银行信用卡",
			"招商银行.招商银行银行信用卡", "工商银行.牡丹运通卡金卡", "工商银行.牡丹运通卡普通卡",
			"中国工商银行.牡丹运通卡金卡", "中国工商银行.牡丹运通卡金卡", "中信实业银行.中信贷记卡",
			"中国银行.长城国际卡(美元卡)-商务普卡", "中国银行.长城国际卡(美元卡)-商务金卡",
			"中国银行.长城国际卡(港币卡)-商务普卡", "中国银行.长城国际卡(港币卡)-商务金卡",
			"中国银行.长城国际卡(美元卡)-个人普卡", "中国银行.长城国际卡(美元卡)-个人金卡", "招商银行.两地一卡通",
			"上海银行.申卡贷记卡", "工商银行.国际借记卡", "农业银行.金穗贷记卡", "中信实业银行.中信贷记卡",
			"农业银行.金穗贷记卡", "中信实业银行.中信贷记卡", "中信实业银行.中信贷记卡", "中信实业银行.中信贷记卡",
			"中信实业银行.中信贷记卡", "中信实业银行.中信贷记卡", "上海浦东发展银行.上海浦东发展银行信用卡VISA普通卡",
			"上海浦东发展银行.上海浦东发展银行信用卡VISA金卡", "交通银行.太平洋互连卡", "交通银行.太平洋互连卡",
			"中国光大银行.阳光信用卡", "中国光大银行.阳光信用卡", "广东发展银行.广发VISA信用卡", "民生银行.民生贷记卡",
			"中国银行.中银威士信用卡员工普卡", "中国银行.中银威士信用卡个人普卡", "中国银行.中银威士信用卡员工金卡",
			"中国银行.中银威士信用卡个人金卡", "中国银行.中银威士信用卡员工白金卡", "中国银行.中银威士信用卡个人白金卡",
			"中国银行.中银威士信用卡商务白金卡", "中国银行.长城公务卡", "招商银行银行.招商银行银行国际卡",
			"深圳发展银行.发展借记卡", "深圳发展银行.发展借记卡", "民生银行.民生借记卡", "北京银行.京卡双币种国际借记卡",
			"建设银行.乐当家银卡VISA", "民生银行.民生国际卡", "中信实业银行.中信国际借记卡", "民生银行.民生国际卡",
			"民生银行.民生贷记卡", "民生银行.民生贷记卡", "民生银行.民生贷记卡", "北京银行.京卡贵宾金卡",
			"北京银行.京卡贵宾白金卡", "中国银行.长城人民币信用卡-个人金卡", "中国银行.长城人民币信用卡-员工金卡",
			"中国银行.长城人民币信用卡-个人普卡", "中国银行.长城人民币信用卡-员工普卡", "中国银行.长城人民币信用卡-单位普卡",
			"中国银行.长城人民币信用卡-单位金卡", "中国银行.长城国际卡(美元卡)-白金卡", "中国光大银行.阳光商旅信用卡",
			"工商银行.牡丹VISA信用卡", "工商银行.牡丹VISA信用卡", "工商银行.牡丹VISA信用卡",
			"工商银行.牡丹VISA信用卡", "工商银行.国际借记卡", "工商银行.牡丹VISA信用卡", "工商银行.国际借记卡",
			"工商银行.牡丹VISA信用卡", "工商银行.牡丹VISA信用卡", "工商银行.牡丹VISA信用卡",
			"中国民生银行.民生国际借记卡", "广东发展银行.广发信用卡", "华夏.华夏卡", "华夏.华夏卡",
			"中信实业银行.中信贷记卡", "中信实业银行.中信借记卡", "中信实业银行.中信借记卡", "建设银行.乐当家金卡VISA",
			"建设银行.乐当家白金卡VISA", "深圳发展银行.沃尔玛百分卡", "深圳发展银行.沃尔玛百分卡",
			"建设银行.龙卡贷记卡公司卡金卡VISA", "建设银行.龙卡普通卡VISA", "建设银行.龙卡贷记卡公司卡普通卡VISA",
			"建设银行.龙卡储蓄卡", "建设银行.龙卡国际普通卡VISA", "建设银行.龙卡国际金卡VISA",
			"广东发展银行.广发信用卡", "中国银行.中银奥运信用卡个人卡", "工商银行.牡丹VISA信用卡",
			"中国工商银行.牡丹VISA白金卡", "兴业银行.兴业智能卡", "兴业银行.兴业智能卡", "上海银行.上海申卡IC",
			"招商银行.招商银行银行信用卡", "招商银行.VISA信用卡", "招商银行.VISA商务信用卡",
			"中信实业银行.中信国际借记卡", "中信实业银行.中信国际借记卡", "兴业银行.VISA信用卡",
			"中国银行.长城国际卡(欧元卡)-个人金卡", "工商银行.牡丹贷记卡", "工商银行.牡丹贷记卡", "工商银行.牡丹贷记卡",
			"工商银行.牡丹贷记卡", "建设银行.VISA准贷记卡", "中国银行.长城电子借记卡",
			"上海浦东发展银行.浦发银行VISA年青卡", "工商银行.牡丹信用卡", "工商银行.牡丹信用卡", "工商银行.牡丹贷记卡",
			"工商银行.牡丹贷记卡", "交通银行.太平洋双币贷记卡VISA", "交通银行.太平洋双币贷记卡VISA",
			"招商银行.招商银行银行国际卡", "民生银行.民生国际卡", "民生银行.民生国际卡", "招商银行.招商银行银行信用卡",
			"招商银行.招商银行银行信用卡", "中国光大银行.阳光白金信用卡", "上海银行.申卡贷记卡", "兴业银行.VISA商务普卡",
			"兴业银行.VISA商务金卡", "中国光大银行.阳光商旅信用卡", "广东发展银行.广发VISA信用卡",
			"中国建设银行.VISA白金/钻石信用卡", "中国工商银行.牡丹欧元卡", "中国工商银行.牡丹欧元卡",
			"中国工商银行.牡丹欧元卡", "农业银行.金穗信用卡", "农业银行.金穗信用卡", "建设银行.VISA准贷记金卡",
			"广东发展银行.广发信用卡", "交通银行.太平洋信用卡", "广东发展银行.广发信用卡",
			"中国银行.长城国际卡(港币卡)-个人金卡", "上海浦东发展银行.上海浦东发展银行信用卡VISA白金卡",
			"常州商业银行.月季卡", "工商银行.牡丹万事达国际借记卡", "中国银行.中银万事达信用卡员工普卡",
			"中国银行.中银万事达信用卡个人普卡", "中国银行.中银万事达信用卡员工金卡", "中国银行.中银万事达信用卡个人金卡",
			"招商银行.招商银行银行国际卡", "宁波市商业银行.汇通国际卡", "民生银行.民生贷记卡",
			"中国银行.长城国际卡(英镑卡)-个人普卡", "中国银行.长城国际卡(英镑卡)-个人金卡", "中信实业银行.中信贷记卡",
			"中国银行.中银万事达信用卡员工白金卡", "中国银行.中银万事达信用卡个人白金卡", "民生银行.民生贷记卡",
			"中信实业银行.中信贷记卡", "广东发展银行.广发信用卡", "中国银行.长城人民币信用卡-个人金卡",
			"中国银行.长城人民币信用卡-员工金卡", "中国银行.长城人民币信用卡-专用卡普卡", "中国银行.长城人民币信用卡-员工普卡",
			"中国银行.长城人民币信用卡-个人普卡", "招商银行.MASTER信用卡", "招商银行.MASTER信用金卡",
			"农业银行.金穗贷记卡", "上海银行.双币种申卡贷记卡普通卡", "农业银行.金穗贷记卡", "中信实业银行.中信贷记卡",
			"上海银行.双币种申卡贷记卡金卡", "广东发展银行.广发万事达信用卡", "交通银行.太平洋双币贷记卡MasterCard",
			"宁波市商业银行.汇通国际卡", "广东发展银行.广发万事达信用卡", "交通银行.太平洋双币贷记卡MasterCard",
			"中国银行.长城国际卡(欧元卡)-个人普卡", "兴业银行.万事达信用卡", "招商银行.招商银行银行国际卡",
			"工商银行.牡丹万事达白金卡", "兴业银行.万事达信用卡", "中国工商银行.牡丹海航信用卡个人金卡",
			"建设银行.乐当家金卡MASTER", "中国银行.长城信用卡", "中国银行.长城信用卡",
			"中国工商银行.牡丹海航信用卡个人普卡", "中国银行.长城信用卡", "中国银行.长城信用卡",
			"建设银行.乐当家银卡MASTER", "深圳市商业银行.深圳市商业银行信用卡", "兴业银行.加菲猫信用卡",
			"深圳市商业银行.深圳市商业银行信用卡", "广东发展银行.广发万事达信用卡", "民生银行.民生贷记卡",
			"工商银行.牡丹万事达信用卡", "工商银行.牡丹信用卡", "工商银行.牡丹信用卡", "工商银行.牡丹万事达信用卡",
			"建设银行.MASTER准贷记卡", "建设银行.龙卡普通卡MASTER", "建设银行.龙卡国际普通卡MASTER",
			"建设银行.龙卡国际金卡MASTER", "农业银行.金穗信用卡", "农业银行.金穗信用卡", "农业银行.金穗信用卡",
			"交通银行.太平洋信用卡", "中国银行.长城国际卡(港币卡)-个人普卡", "中国银行.长城国际卡(美元卡)-个人普卡",
			"中国银行.长城国际卡(美元卡)-个人金卡", "广东发展银行.广发信用卡", "中国光大银行.第十八届世界足球锦标赛纪念卡",
			"建设银行.MASTER准贷记金卡", "招商银行.万事达信用卡", "招商银行.万事达信用卡", "招商银行.万事达信用卡",
			"中国银行.长城国际卡(美元卡)-商务普卡", "中国银行.长城国际卡(港币卡)-商务普卡",
			"中国银行.长城人民币信用卡-单位普卡", "中国银行.长城万事达信用卡单位普卡", "工商银行.国际借记卡",
			"广东发展银行.广发信用卡", "建设银行.乐当家白金卡MASTER", "民生银行.民生贷记卡",
			"招商银行.招商银行银行信用卡", "招商银行.招商银行银行信用卡", "农业银行.金穗贷记卡", "中国银行.长城公务卡",
			"广东发展银行.广发万事达信用卡", "建设银行.龙卡贷记卡公司卡普通卡MASTER",
			"交通银行.太平洋双币贷记卡MasterCard", "中国银行.长城公务卡", "建设银行.龙卡信用卡",
			"民生银行.民生贷记卡", "中信实业银行.中信MASTERCARD人民币+美金双币贷记卡", "工商银行.牡丹万事达信用卡",
			"农业银行.金穗贷记卡", "中国银行.长城国际卡(港币卡)-商务金卡", "中国银行.长城国际卡(美元卡)-商务金卡",
			"中国银行.长城人民币信用卡-单位金卡", "中国银行.中银万事达信用卡单位金卡", "广东发展银行.广发万事达信用卡",
			"建设银行.龙卡贷记卡公司卡金卡MASTER", "中信实业银行.中信MASTERCARD人民币+美金双币贷记卡",
			"沈阳市商业银行.玫瑰卡", "深圳农联社.信通卡", "D.F.S.I(备注1).发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡", "D.F.S.I.发现卡",
			"D.F.S.I.发现卡", "中国银行.长城电子借记卡", "中国银行.长城电子借记卡", "交通银行.太平洋万事顺卡",
			"交通银行.太平洋万事顺卡", "交通银行.太平洋万事顺卡", "交通银行.太平洋万事顺卡", "深圳商业银行.万事顺卡",
			"深圳商业银行.万事顺卡", "北京银行.京卡", "北京银行.京卡", "南京市商业银行.梅花卡", "南京市商业银行.梅花卡",
			"杭州商业银行.西湖卡", "杭州商业银行.西湖卡", "广州市商业银行.羊城借记卡", "广州市商业银行.羊城借记卡",
			"苏州市商业银行.姑苏卡", "苏州市商业银行.姑苏卡", "徽商银行合肥分行.黄山卡", "徽商银行合肥分行.黄山卡",
			"徽商银行合肥分行.黄山卡", "徽商银行合肥分行.黄山卡", "徽商银行合肥分行.黄山卡", "徽商银行合肥分行.黄山卡",
			"绍兴商业银行.兰花卡", "绍兴商业银行.兰花卡", "常熟农村商业银行.粒金卡", "常熟农村商业银行.粒金卡",
			"大连商业银行.北方明珠卡", "大连商业银行.北方明珠卡", "河北省农村信用社.信通卡", "韩亚银行.",
			"温州商业银行.金鹿卡", "温州商业银行.金鹿卡", "阜新市商业银行.金通卡", "阜新市商业银行.金通卡",
			"福建省农村信用社联合社.万通", "厦门市农村信用合作社.万通卡", "福建省农村信用社联合社.万通",
			"厦门市农村信用合作社.万通卡", "深圳农信社.信通卡", "深圳农信社.信通卡", "深圳市农村信用合作社联合社.信通商务卡",
			"深圳市农村信用合作社联合社.信通商务卡", "淮安市商业银行.九州借记卡", "淮安市商业银行.九州借记卡",
			"嘉兴市商业银行.南湖借记卡", "嘉兴市商业银行.南湖借记卡", "贵阳市商业银行.甲秀银联借记卡",
			"贵阳市商业银行.甲秀银联借记卡", "重庆市商业银行.长江卡", "重庆市商业银行.长江卡", "成都商业银行.锦程卡",
			"成都商业银行.锦程卡", "西安市商业银行.福瑞卡", "西安市商业银行.福瑞卡", "徽商银行芜湖分行.黄山卡",
			"徽商银行芜湖分行.黄山卡", "北京农联社.信通卡", "北京农联社.信通卡", "兰州市商业银行.敦煌国际卡",
			"兰州市商业银行.敦煌国际卡", "廊坊市商业银行.银星卡", "廊坊市商业银行.银星卡", "泰隆城市信用社.泰隆卡",
			"泰隆城市信用社.泰隆卡", "乌鲁木齐市商业银行.雪莲借记卡", "乌鲁木齐市商业银行.雪莲借记卡", "青岛商行.金桥卡",
			"青岛商行.金桥卡", "呼市商业银行.百灵卡", "呼市商业银行.百灵卡", "上海银行.人民币申卡贷记卡金卡",
			"上海银行.人民币申卡贷记卡金卡", "上海银行.人民币申卡贷记卡普通卡", "上海银行.人民币申卡贷记卡普通卡",
			"国家邮政局.绿卡银联标准卡", "国家邮政局.绿卡银联标准卡", "国家邮政局.绿卡银联标准卡", "国家邮政局.绿卡银联标准卡",
			"成都市商业银行.锦程卡金卡", "成都市商业银行.锦程卡金卡", "成都市商业银行.锦程卡定活一卡通金卡",
			"成都市商业银行.锦程卡定活一卡通金卡", "成都市商业银行.锦程卡定活一卡通", "成都市商业银行.锦程卡定活一卡通",
			"深圳市商业银行.深圳市商业银行信用卡", "深圳市商业银行.深圳市商业银行信用卡", "深圳市商业银行.深圳市商业银行信用卡",
			"深圳市商业银行.深圳市商业银行信用卡", "包头市商业银行.包头市商业银行借记卡", "包头市商业银行.包头市商业银行借记卡",
			"中国建设银行.龙卡人民币信用卡", "中国建设银行.龙卡人民币信用卡", "中国建设银行.龙卡人民币信用金卡",
			"中国建设银行.龙卡人民币信用金卡", "湖南省农村信用社联合社.福祥借记卡", "湖南省农村信用社联合社.福祥借记卡",
			"吉林市商业银行.信用卡", "吉林市商业银行.信用卡", "吉林市商业银行.信用卡", "吉林市商业银行.信用卡",
			"福建省农村信用社联合社.万通", "福建省农村信用社联合社.万通", "国家邮政局.绿卡银联标准卡",
			"国家邮政局.绿卡银联标准卡", "国家邮政局.绿卡银联标准卡", "国家邮政局.绿卡银联标准卡", "中国工商银行.灵通卡",
			"中国工商银行.灵通卡", "中国工商银行.E时代卡", "中国工商银行.E时代卡", "中国工商银行.E时代卡",
			"中国工商银行.E时代卡", "中国工商银行.理财金卡", "中国工商银行.理财金卡", "中国工商银行.准贷记卡",
			"中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡",
			"中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡",
			"中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡",
			"中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.准贷记卡", "中国工商银行.贷记卡",
			"中国工商银行.贷记卡", "中国工商银行.贷记卡", "中国工商银行.贷记卡", "中国工商银行.贷记卡",
			"中国工商银行.贷记卡", "中国工商银行.贷记卡", "中国工商银行.贷记卡",
			"交通银行股份有限公司太平洋双币信用卡中心.太平洋人民币贷记卡", "交行太平洋卡中心.太平洋人民币贷记卡",
			"交通银行股份有限公司太平洋双币信用卡中心.太平洋人民币贷记卡", "交行太平洋卡中心.太平洋人民币贷记卡",
			"交通银行股份有限公司太平洋双币信用卡中心.太平洋人民币贷记卡", "交行太平洋卡中心.太平洋人民币贷记卡",
			"交通银行股份有限公司太平洋双币信用卡中心.太平洋人民币贷记卡", "交行太平洋卡中心.太平洋人民币贷记卡",
			"交通银行.太平洋人民币准贷记卡", "交通银行.太平洋人民币准贷记卡", "交通银行.太平洋人民币借记卡",
			"交通银行.太平洋人民币借记卡", "交通银行.太平洋人民币借记卡", "交通银行.太平洋人民币借记卡",
			"交通银行.太平洋人民币借记卡", "交通银行.太平洋人民币借记卡", "交通银行.太平洋人民币借记卡",
			"交通银行.太平洋人民币借记卡", "建设银行.622280银联储蓄卡", "建设银行.622280银联储蓄卡",
			"柳州市商业银行.龙城卡", "柳州市商业银行.龙城卡", "柳州市商业银行.龙城卡", "柳州市商业银行.龙城卡",
			"湖州市商业银行.百合卡", "湖州市商业银行.百合卡", "佛山市禅城区农村信用联社.信通卡",
			"佛山市禅城区农村信用联社.信通卡", "南京市商业银行.梅花贷记卡", "南京市商业银行.梅花贷记卡",
			"南京市商业银行.梅花借记卡", "南京市商业银行.梅花借记卡", "九江市商业银行.庐山卡", "九江市商业银行.庐山卡",
			"昆明商业银行.春城卡", "昆明商业银行.春城卡", "西宁市商业银行.三江银行卡", "西宁市商业银行.三江银行卡",
			"淄博市商业银行.金达借记卡", "淄博市商业银行.金达借记卡", "徐州市郊农村信用合作联社.信通卡",
			"徐州市郊农村信用合作联社.信通卡", "宁波市商业银行.汇通卡", "宁波市商业银行.汇通卡", "宁波市商业银行.汇通卡",
			"宁波市商业银行.汇通卡", "山东农村信用联合社.信通卡", "山东农村信用联合社.信通卡", "台州市商业银行.大唐贷记卡",
			"台州市商业银行.大唐贷记卡", "顺德农信社.恒通卡", "顺德农信社.恒通卡", "常熟农村商业银行.粒金借记卡",
			"常熟农村商业银行.粒金借记卡", "江苏农信.圆鼎卡", "江苏农信.圆鼎卡", "武汉市商业银行.九通卡",
			"武汉市商业银行.九通卡", "徽商银行马鞍山分行.黄山卡", "徽商银行马鞍山分行.黄山卡", "东莞农村信用合作社.信通卡",
			"东莞农村信用合作社.信通卡", "天津市农村信用社.信通借记卡", "天津市农村信用社.信通借记卡", "天津市商业银行.津卡",
			"天津市商业银行.津卡", "张家港市农村商业银行.一卡通", "张家港市农村商业银行.一卡通", "东莞市商业银行.万顺通卡",
			"东莞市商业银行.万顺通卡", "南宁市商业银行.桂花卡", "南宁市商业银行.桂花卡", "包头市商业银行.雄鹰卡",
			"包头市商业银行.雄鹰卡", "连云港市商业银行.金猴神通借记卡", "连云港市商业银行.金猴神通借记卡",
			"焦作市商业银行.月季借记卡", "焦作市商业银行.月季借记卡", "鄞州农村合作银行.蜜蜂借记卡",
			"鄞州农村合作银行.蜜蜂借记卡", "徽商银行淮北分行.黄山卡", "徽商银行淮北分行.黄山卡", "江阴农村商业银行.合作借记卡",
			"江阴农村商业银行.合作借记卡", "攀枝花市商业银行.攀枝花卡", "攀枝花市商业银行.攀枝花卡",
			"佛山市三水区农村信用合作社.信通卡", "佛山市三水区农村信用合作社.信通卡", "成都农信社.天府借记卡",
			"成都农信社.天府借记卡", "中国银行.人民币信用卡金卡", "中国银行.人民币信用卡金卡", "中国银行.人民币信用卡普通卡",
			"中国银行.人民币信用卡普通卡", "中国银行.中银卡", "中国银行.中银卡", "南洋商业银行.人民币信用卡金卡",
			"南洋商业银行.人民币信用卡金卡", "南洋商业银行.人民币信用卡普通卡", "南洋商业银行.人民币信用卡普通卡",
			"南洋商业银行.中银卡", "南洋商业银行.中银卡", "集友银行.人民币信用卡金卡", "集友银行.人民币信用卡金卡",
			"集友银行.人民币信用卡普通卡", "集友银行.人民币信用卡普通卡", "集友银行.中银卡", "集友银行.中银卡",
			"沧州农信社.信通卡", "沧州农信社.信通卡", "临沂市商业银行.沂蒙卡", "临沂市商业银行.沂蒙卡",
			"香港上海汇丰银行有限公司.人民币卡", "香港上海汇丰银行有限公司.人民币卡", "香港上海汇丰银行有限公司.人民币金卡",
			"香港上海汇丰银行有限公司.人民币金卡", "中山市农村信用合作社.信通卡", "中山市农村信用合作社.信通卡",
			"珠海市商业银行.万事顺卡", "珠海市商业银行.万事顺卡", "东亚银行有限公司.电子网络人民币卡",
			"东亚银行有限公司.电子网络人民币卡", "徽商银行安庆分行.黄山卡", "徽商银行安庆分行.黄山卡",
			"绵阳市商业银行.科技城卡", "绵阳市商业银行.科技城卡", "长沙市商业银行.芙蓉卡", "长沙市商业银行.芙蓉卡",
			"昆明市农村信用联社.金碧一卡通", "昆明市农村信用联社.金碧一卡通", "泉州市商业银行.海峡银联卡",
			"泉州市商业银行.海峡银联卡", "花旗银行有限公司.花旗人民币信用卡", "花旗银行有限公司.花旗人民币信用卡",
			"大新银行有限公司.大新人民币信用卡普通卡", "大新银行有限公司.大新人民币信用卡普通卡", "大新银行有限公司.人民币借记卡",
			"大新银行有限公司.人民币借记卡", "恒生银行有限公司.恒生人民币信用卡", "恒生银行有限公司.恒生人民币信用卡",
			"恒生银行有限公司.恒生人民币金卡", "恒生银行有限公司.恒生人民币金卡", "恒生银行有限公司.恒生人民币白金卡",
			"恒生银行有限公司.恒生人民币白金卡", "济南市商业银行.齐鲁卡", "济南市商业银行.齐鲁卡", "美国银行.人民币卡",
			"美国银行.人民币卡", "大连市商业银行.大连市商业银行贷记卡", "大连市商业银行.大连市商业银行贷记卡",
			"恒丰银行.九州借记卡", "恒丰银行.九州借记卡", "大连市商业银行.大连市商业银行贷记卡",
			"大连市商业银行.大连市商业银行贷记卡", "上海商业银行.人民币信用卡", "上海商业银行.人民币信用卡",
			"永隆银行有限公司.永隆人民币信用卡", "永隆银行有限公司.永隆人民币信用卡", "福州市商业银行.榕城卡",
			"福州市商业银行.榕城卡", "宁波鄞州农村合作银行.蜜蜂贷记卡", "宁波鄞州农村合作银行.蜜蜂贷记卡",
			"潍坊商业银行.鸢都卡", "潍坊商业银行.鸢都卡", "泸州市商业银行.酒城卡", "泸州市商业银行.酒城卡",
			"厦门市商业银行.银鹭借记卡", "厦门市商业银行.银鹭借记卡", "镇江市商业银行.金山灵通卡", "镇江市商业银行.金山灵通卡",
			"大同市商业银行.云冈卡", "大同市商业银行.云冈卡", "宜昌市商业银行.三峡卡", "宜昌市商业银行.三峡卡",
			"宜昌市商业银行.信用卡", "宜昌市商业银行.信用卡", "葫芦岛市商业银行.一通卡", "辽阳市商业银行.新兴卡",
			"辽阳市商业银行.新兴卡", "营口市商业银行.辽河一卡通", "营口市商业银行.辽河一卡通",
			"香港上海汇丰银行有限公司.ATM Card", "香港上海汇丰银行有限公司.ATM Card",
			"香港上海汇丰银行有限公司.ATM Card", "香港上海汇丰银行有限公司.ATM Card", "威海市商业银行.通达卡",
			"威海市商业银行.通达卡", "湖北农信社.信通卡", "湖北农信社.信通卡", "鞍山市商业银行.千山卡",
			"鞍山市商业银行.千山卡", "丹东商行.银杏卡", "丹东商行.银杏卡", "南通市商业银行.金桥卡",
			"南通市商业银行.金桥卡", "洛阳市商业银行.都市一卡通", "洛阳市商业银行.都市一卡通", "郑州商业银行.世纪一卡通",
			"郑州商业银行.世纪一卡通", "扬州市商业银行.绿扬卡", "扬州市商业银行.绿扬卡", "永隆银行有限公司.永隆人民币信用卡",
			"永隆银行有限公司.永隆人民币信用卡", "哈尔滨市商业银行.丁香借记卡", "哈尔滨市商业银行.丁香借记卡",
			"天津市商业银行.津卡贷记卡", "天津市商业银行.津卡贷记卡", "台州市商业银行.大唐卡", "台州市商业银行.大唐卡",
			"银川市商业银行.如意卡", "银川市商业银行.如意卡", "银川市商业银行.如意借记卡", "银川市商业银行.如意借记卡",
			"大西洋银行股份有限公司.澳门币卡", "大西洋银行股份有限公司.澳门币卡", "澳门国际银行.人民币卡",
			"澳门国际银行.人民币卡", "澳门国际银行.港币卡", "澳门国际银行.港币卡", "澳门国际银行.澳门币卡",
			"澳门国际银行.澳门币卡", "广州农村信用合作社联合社.麒麟储蓄卡", "广州农村信用合作社.麒麟储蓄卡",
			"吉林市商业银行.雾凇卡", "吉林市商业银行.雾凇卡", "三门峡市城市信用社.天鹅卡", "三门峡市城市信用社.天鹅卡",
			"抚顺市商业银行.绿叶卡", "抚顺市商业银行.绿叶卡", "昆山农村信用合作社联合社.江通卡",
			"昆山农村信用合作社联合社.江通卡", "常州商业银行.月季卡", "常州商业银行.月季卡", "湛江市商业银行.南珠卡",
			"湛江市商业银行.南珠卡", "金华市商业银行.双龙借记卡", "金华市商业银行.双龙借记卡", "金华市商业银行.双龙贷记卡",
			"金华市商业银行.双龙贷记卡", "大新银行有限公司.大新人民币信用卡金卡", "大新银行有限公司.大新人民币信用卡金卡",
			"江苏农信社.圆鼎卡", "江苏农信社.圆鼎卡", "中信嘉华银行有限公司.人民币信用卡金卡",
			"中信嘉华银行有限公司.人民币信用卡金卡", "中信嘉华银行有限公司.人民币信用卡普通卡",
			"中信嘉华银行有限公司.人民币信用卡普通卡", "中信嘉华银行有限公司.人民币借记卡", "中信嘉华银行有限公司.人民币借记卡",
			"常熟市农村商业银行.粒金贷记卡", "常熟市农村商业银行.粒金贷记卡", "廖创兴银行有限公司.港币借记卡",
			"廖创兴银行有限公司.港币借记卡", "沈阳市商业银行.玫瑰卡", "沈阳市商业银行.玫瑰卡", "广州市商业银行.羊城借记卡",
			"广州市商业银行.羊城借记卡", "上海银行.申卡", "上海银行.申卡", "江门市新会农信社.信通卡",
			"江门市新会农信社.信通卡", "东亚银行有限公司.人民币信用卡", "东亚银行有限公司.人民币信用卡",
			"东亚银行有限公司.人民币信用卡金卡", "东亚银行有限公司.人民币信用卡金卡", "乌鲁木齐市商业银行.雪莲贷记卡",
			"乌鲁木齐市商业银行.雪莲贷记卡", "高要市农村信用联社.信通卡", "高要市农村信用联社.信通卡",
			"上海市农村信用合作社联合社.如意卡", "上海市农村信用合作社联社.如意卡", "江阴市农村商业银行.合作贷记卡",
			"江阴市农村商业银行.合作贷记卡", "无锡市商业银行.太湖金保卡", "无锡市商业银行.太湖金保卡", "绍兴市商业银行.兰花卡",
			"绍兴市商业银行.兰花卡", "星展银行.银联人民币银行卡", "星展银行.银联人民币银行卡", "星展银行.银联人民币银行卡",
			"星展银行.银联人民币银行卡", "吴江农村商业银行.垂虹卡", "吴江农村商业银行.垂虹卡", "大新银行有限公司.借记卡",
			"大新银行有限公司.借记卡", "星展银行.银联人民币银行卡", "星展银行.银联人民币银行卡", "星展银行.银联人民币银行卡",
			"星展银行.银联人民币银行卡", "星展银行.银联银行卡", "星展银行.银联港币银行卡", "星展银行.银联港币银行卡",
			"星展银行.银联银行卡", "星展银行.银联银行卡", "星展银行.银联港币银行卡", "星展银行.银联港币银行卡",
			"星展银行.银联银行卡", "AEON信贷财务.AEON JUSCO银联卡", "AEON信贷财务.AEON JUSCO银联卡",
			"Travelex.Travelex港币卡", "Travelex.Travelex港币卡",
			"Travelex.Travelex美元卡", "Travelex.Travelex美元卡", "石家庄市商业银行.如意借记卡",
			"石家庄市商业银行.如意借记卡", "石家庄市商业银行.如意借记卡", "石家庄市商业银行.如意借记卡",
			"上海浦东发展银行.东方卡", "上海浦东发展银行.东方卡", "陕西省农村信用社联合社.陕西信合富泰卡",
			"陕西省农村信用社联合社.陕西信合富泰卡", "高要市农村信用合作社联合社.信通白金卡", "高要市农村信用合作社联社.信通白金卡",
			"高要市农村信用合作社联合社.信通金卡", "高要市农村信用合作社联社.信通金卡", "上海浦东发展银行.东方-轻松理财卡白金卡",
			"上海浦东发展银行.东方-轻松理财卡白金卡", "上海浦东发展银行.东方-轻松理财卡普卡",
			"上海浦东发展银行.东方-轻松理财卡普卡", "上海浦东发展银行.东方-轻松理财卡钻石卡",
			"上海浦东发展银行.东方-轻松理财卡钻石卡", "上海浦东发展银行.东方-新标准准贷记卡",
			"上海浦东发展银行.东方-新标准准贷记卡", "上海浦东发展银行.东方卡", "上海浦东发展银行.东方卡",
			"上海浦东发展银行.东方卡", "上海浦东发展银行.东方卡", "上海浦东发展银行.东方卡", "上海浦东发展银行.东方卡",
			"深圳发展银行.人民币信用卡金卡", "深圳发展银行.人民币信用卡金卡", "深圳发展银行.人民币信用卡普卡",
			"深圳发展银行.人民币信用卡普卡", "深圳发展银行.发展卡", "深圳发展银行.发展卡", "大丰银行有限公司.人民币借记卡",
			"大丰银行有限公司.人民币借记卡", "大丰银行有限公司.港币借记卡", "大丰银行有限公司.港币借记卡",
			"大丰银行有限公司.澳门币借记卡", "大丰银行有限公司.澳门币借记卡",
			"哈萨克斯坦国民储蓄银行.Halykbank Classic", "哈萨克斯坦国民储蓄银行.Halykbank Classic",
			"哈萨克斯坦国民储蓄银行.Halykbank Golden", "哈萨克斯坦国民储蓄银行.Halykbank Golden",
			"德阳市商业银行.锦程卡定活一卡通白金卡", "德阳市商业银行.锦程卡定活一卡通白金卡", "德阳市商业银行.锦程卡定活一卡通金卡",
			"德阳市商业银行.锦程卡定活一卡通金卡", "德阳市商业银行.锦程卡定活一卡通", "德阳市商业银行.锦程卡定活一卡通",
			"招商银行.招商银行信用卡", "招商银行银行.招商银行银行信用卡", "招商银行.招商银行信用卡",
			"招商银行银行.招商银行银行信用卡", "招商银行.招商银行信用卡", "招商银行银行.招商银行银行信用卡",
			"招商银行.招商银行信用卡", "招商银行银行.招商银行银行信用卡", "招商银行.招商银行信用卡",
			"招商银行银行.招商银行银行信用卡", "招商银行.一卡通", "招商银行银行.一卡通", "招商银行.招商银行信用卡",
			"招商银行银行.招商银行银行信用卡", "招商银行.招商银行信用卡", "招商银行银行.招商银行银行信用卡", "招商银行.一卡通",
			"招商银行银行.一卡通", "招商银行.公司卡", "招商银行银行.公司卡", "民生银行.民生信用卡", "民生银行.民生信用卡",
			"民生银行.民生信用卡", "民生银行.民生信用卡", "中国民生银行.民生银联白金信用卡", "中国民生银行.民生银联白金信用卡",
			"中国民生银行.民生银联商务信用卡", "中国民生银行.民生银联商务信用卡", "民生银行.民生借记卡", "民生银行.民生借记卡",
			"中国民生银行.民生借记卡", "中国民生银行.民生借记卡", "中国民生银行.民生借记卡", "中国民生银行.民生借记卡",
			"中国民生银行.民生借记卡", "中国民生银行.民生借记卡", "华夏银行.华夏卡", "华夏银行.华夏卡",
			"华夏银行.华夏至尊金卡", "华夏银行.华夏至尊金卡", "华夏银行.华夏丽人卡", "华夏银行.华夏丽人卡",
			"华夏银行.华夏万通卡", "华夏银行.华夏万通卡", "中国光大银行.炎黄卡普卡", "中国光大银行.炎黄卡普卡",
			"中国光大银行.炎黄卡白金卡", "中国光大银行.炎黄卡白金卡", "中国光大银行.炎黄卡金卡", "中国光大银行.炎黄卡金卡",
			"光大银行.阳光卡", "光大银行.阳光卡", "中信实业银行信用卡中心.中信银联标准贷记卡",
			"中信实业银行信用卡中心.中信银联标准贷记卡", "中信实业银行信用卡中心.中信银联标准贷记卡",
			"中信实业银行信用卡中心.中信银联标准贷记卡", "中信实业银行信用卡中心.中信银联标准贷记卡",
			"中信实业银行信用卡中心.中信银联标准贷记卡", "江西省农村信用社联合社.百福卡", "江西省农村信用社联合社.百福卡",
			"江西省农村信用社联合社.百福卡", "江西省农村信用社联合社.百福卡", "渤海银行.渤海银行公司借记卡",
			"渤海银行.渤海银行公司借记卡", "中信实业银行信用卡中心.中信银联标准贷记卡", "中信实业银行信用卡中心.中信银联标准贷记卡",
			"中信实业银行信用卡中心.中信银联标准贷记卡", "中信实业银行信用卡中心.中信银联标准贷记卡", "中信实业银行.中信借记卡",
			"中信实业银行.中信借记卡", "中信实业银行.中信借记卡", "中信实业银行.中信借记卡", "中信实业银行.中信贵宾卡",
			"中信实业银行.中信贵宾卡", "中信银行.中信理财宝金卡", "中信银行.中信理财宝金卡", "中信银行.中信理财宝白金卡",
			"中信银行.中信理财宝白金卡", "建设银行.龙卡储蓄卡", "中国建设银行.龙卡储蓄卡", "中国建设银行.龙卡准贷记卡",
			"中国建设银行.龙卡准贷记卡", "中国建设银行.龙卡准贷记卡金卡", "中国建设银行.龙卡准贷记卡金卡",
			"中国银行澳门分行.人民币信用卡", "中国银行澳门分行.人民币信用卡", "中国银行澳门分行.人民币信用卡",
			"中国银行澳门分行.人民币信用卡", "中国银行.长城人民币信用卡", "中国银行.长城人民币信用卡-个人普卡",
			"中国银行.长城人民币信用卡", "中国银行.长城人民币信用卡-个人金卡", "中国银行.长城人民币信用卡-专用卡普卡",
			"中国银行.长城人民币信用卡", "中国银行.长城人民币信用卡-员工金卡", "中国银行.长城人民币信用卡",
			"中国银行.长城人民币信用卡-员工金卡", "中国银行.长城人民币信用卡", "中国银行.长城人民币信用卡-员工金卡",
			"中国银行.长城人民币信用卡", "中国银行.长城人民币信用卡-单位普卡", "中国银行.长城信用卡",
			"中国银行.长城人民币信用卡-单位金卡", "中国银行.银联单币贷记卡", "中国银行.银联单币贷记卡", "中国银行.长城信用卡",
			"中国银行.长城信用卡", "中国银行.长城信用卡", "中国银行.长城信用卡", "中国银行.长城信用卡",
			"中国银行.长城信用卡", "中国银行澳门分行.中银卡", "中国银行澳门分行.中银卡", "曲靖市商业银行.珠江源卡",
			"曲靖市商业银行.珠江源卡", "农业银行.金穗校园卡", "农业银行.金穗校园卡", "农业银行.金穗星座卡",
			"农业银行.金穗星座卡", "农业银行.金穗社保卡", "农业银行.金穗社保卡", "农业银行.金穗旅游卡",
			"农业银行.金穗旅游卡", "农业银行.金穗青年卡", "农业银行.金穗青年卡", "农业银行.复合介质金穗通宝卡",
			"农业银行.复合介质金穗通宝卡", "农业银行.金穗海通卡", "农业银行.金穗贷记卡", "农业银行.金穗贷记卡",
			"农业银行.金穗贷记卡", "农业银行.金穗贷记卡", "农业银行.金穗通宝卡(暂未使用)", "农业银行.金穗通宝卡",
			"农业银行.金穗惠农卡", "农业银行.金穗通宝卡(暂未使用)", "农业银行.金穗通宝贵宾卡(银)",
			"农业银行.金穗通宝卡(暂未使用)", "农业银行.金穗通宝卡", "农业银行.金穗通宝贵宾卡(金)", "农业银行.金穗通宝卡",
			"农业银行.金穗通宝贵宾卡(白金)", "中国农业银行.金穗通宝卡", "农业银行.金穗通宝卡(单位卡)",
			"农业银行.金穗通宝卡", "农业银行.金穗通宝卡(个人普卡)", "农业银行.金穗通宝卡", "农业银行.金穗通宝贵宾卡(钻石)",
			"江苏东吴农村商业银行.新苏卡", "江苏东吴农村商业银行.新苏卡", "桂林市商业银行.漓江卡", "桂林市商业银行.漓江卡",
			"日照市商业银行.黄海卡", "日照市商业银行.黄海卡", "浙江省农村信用社联合社.丰收卡", "浙江省农村信用社联社.丰收卡",
			"珠海农村信用合作社联社.信通卡", "珠海农村信用合作联社.信通卡", "大庆市商业银行.玉兔卡", "大庆市商业银行.玉兔卡",
			"澳门永亨银行股份有限公司.人民币卡", "澳门永亨银行股份有限公司.人民币卡", "莱芜市商业银行.金凤卡",
			"莱芜市商业银行.金凤卡", "长春市商业银行.君子兰一卡通", "长春市商业银行.君子兰一卡通", "徐州市商业银行.彭城借记卡",
			"徐州市商业银行.彭城借记卡", "重庆市农村信用社联合社.信合平安卡", "重庆市农村信用社联合社.信合平安卡",
			"太仓农村商业银行.郑和卡", "太仓农村商业银行.郑和卡", "靖江市长江城市信用社.长江卡", "靖江市长江城市信用社.长江卡",
			"永亨银行.永亨尊贵理财卡", "永亨银行.永亨尊贵理财卡", "徽商银行.黄山卡", "徽商银行.黄山卡",
			"杭州市商业银行.西湖卡", "杭州市商业银行.西湖卡", "徽商银行.黄山卡", "徽商银行.黄山卡",
			"柳州市商业银行.龙城卡", "柳州市商业银行.龙城卡", "柳州市商业银行.龙城卡", "柳州市商业银行.龙城卡",
			"尧都区农村信用合作社联社.天河卡", "尧都区农村信用合作社联社.天河卡", "渤海银行.渤海银行借记卡",
			"渤海银行.渤海银行借记卡", "重庆市农村信用社联合社.信合希望卡", "重庆市农村信用社联合社.信合希望卡",
			"烟台市商业银行.金通卡", "烟台市商业银行.金通卡", "武进农村商业银行.阳湖卡", "武进农村商业银行.阳湖卡",
			"上海银行.申卡借记卡", "上海银行.申卡借记卡", "贵州省农村信用社联合社.信合卡", "贵州省农村信用社联合社.信合卡",
			"江苏锡州农村商业银行.金阿福", "江苏锡州农村商业银行.金阿福", "中外合资.南充市商业银行.熊猫团团卡",
			"中外合资.南充市商业银行.熊猫团团卡", "长沙市商业银行.芙蓉贷记卡", "长沙市商业银行.芙蓉贷记卡",
			"长沙市商业银行.芙蓉贷记卡", "长沙市商业银行.芙蓉贷记卡", "兴业银行.银联信用卡", "兴业银行.银联信用卡",
			"兴业银行.兴业自然人生理财卡", "兴业银行.兴业自然人生理财卡", "兴业银行.万能卡", "兴业银行.万能卡",
			"石嘴山城市信用社.麒麟卡", "张家口市商业银行.好运卡", "交通银行.太平洋卡", "中国工商银行.公务卡",
			"中国建设银行.公务卡", "大庆市商业银行.公务卡", "Discover Financial Services,Inc.发现卡",
			".发现卡", "Discover Financial Services,Inc.发现卡", ".发现卡",
			"Discover Financial Services,Inc.发现卡", ".发现卡",
			"Discover Financial Services,Inc.发现卡", ".发现卡", "上海银行.上海明珠卡",
			"上海银行.上海明珠卡", "泉州市商业银行.海峡储蓄卡", "泉州市商业银行.海峡储蓄卡", "广东发展银行.广发信用卡",
			"广东发展银行.广发VISA信用卡", "广东发展银行.广发理财通", "广东发展银行.广发VISA信用卡",
			"广东发展银行.广发理财通", "广东发展银行.广发信用卡", "招商.招行一卡通", "招商.招行一卡通",
			"招商银行.招商银行银行一卡通", "招商银行.招商银行银行一卡通", "长沙市商业银行.芙蓉卡", "长沙市商业银行.芙蓉卡",
			"南通商业银行.金桥卡", "南通商业银行.金桥卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡", "浦东发展银行.东方卡",
			"贵阳市商业银行.甲秀卡", "贵阳市商业银行.甲秀卡", "郑州市商业银行.世纪一卡通", "工商银行.牡丹银联灵通卡-个人普卡",
			"工商银行.牡丹银联灵通卡-个人普卡", "工商银行.牡丹银联灵通卡-个人金卡", "工商银行.牡丹银联理财金卡",
			"上海浦东发展银行.东方卡", "深圳发展银行.发展卡" };
}
  • 身份证工具类

package com.github.wxiaoqi.demo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 身份证工具类
 */
public class IDCardUtil {

    /**
     * 1、号码的结构 公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
     *
     * 2、地址码(前六位数) 表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行。
     *
     * 3、出生日期码(第七位至十四位) 表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日代码之间不用分隔符。
     *
     * 4、顺序码(第十五位至十七位) 表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配给女性。
     *
     * 5、校验码(第十八位数)
     * (1)十七位数字本体码加权求和公式 S = Sum(Ai * Wi), i = 0, ... , 16 ,先对前17位数字的权求和
     *      Ai:表示第i位置上的身份证号码数字值 Wi:表示第i位置上的加权因子 Wi: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
     * (2)计算模 Y = mod(S, 11)
     * (3)通过模得到对应的校验码 Y: 0 1 2 3 4 5 6 7 8 9 10 校验码: 1 0 X 9 8 7 6 5 4 3 2
     *
     */

    private IDCardUtil(){
        // 私有类构造方法
    }


    /** 中国公民身份证号码最小长度。 */
    private static final int CHINA_ID_MIN_LENGTH = 15;

    /** 中国公民身份证号码最大长度。 */
    private static final int CHINA_ID_MAX_LENGTH = 18;

    /** 省、直辖市代码表 */
    private static final 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 static final int power[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9,
            10, 5, 8, 4, 2 };

    /** 第18位校检码 */
    private static final String verifyCode[] = { "1", "0", "X", "9", "8", "7",
            "6", "5", "4", "3", "2" };
    /** 最低年限 */
    private static final int MIN = 1930;
    /** 大陆身份首两位数字对应省份 */
    private static Map cityCodes = new HashMap();
    /** 台湾身份首字母对应数字 */
    private static Map twFirstCode = new HashMap();
    /** 香港身份首字母对应数字 */
    private static Map hkFirstCode = new HashMap();

    static {
        cityCodes.put("11", "北京");
        cityCodes.put("12", "天津");
        cityCodes.put("13", "河北");
        cityCodes.put("14", "山西");
        cityCodes.put("15", "内蒙古");
        cityCodes.put("21", "辽宁");
        cityCodes.put("22", "吉林");
        cityCodes.put("23", "黑龙江");
        cityCodes.put("31", "上海");
        cityCodes.put("32", "江苏");
        cityCodes.put("33", "浙江");
        cityCodes.put("34", "安徽");
        cityCodes.put("35", "福建");
        cityCodes.put("36", "江西");
        cityCodes.put("37", "山东");
        cityCodes.put("41", "河南");
        cityCodes.put("42", "湖北");
        cityCodes.put("43", "湖南");
        cityCodes.put("44", "广东");
        cityCodes.put("45", "广西");
        cityCodes.put("46", "海南");
        cityCodes.put("50", "重庆");
        cityCodes.put("51", "四川");
        cityCodes.put("52", "贵州");
        cityCodes.put("53", "云南");
        cityCodes.put("54", "西藏");
        cityCodes.put("61", "陕西");
        cityCodes.put("62", "甘肃");
        cityCodes.put("63", "青海");
        cityCodes.put("64", "宁夏");
        cityCodes.put("65", "新疆");
        cityCodes.put("71", "台湾");
        cityCodes.put("81", "香港");
        cityCodes.put("82", "澳门");
        cityCodes.put("91", "国外");
        twFirstCode.put("A", 10);
        twFirstCode.put("B", 11);
        twFirstCode.put("C", 12);
        twFirstCode.put("D", 13);
        twFirstCode.put("E", 14);
        twFirstCode.put("F", 15);
        twFirstCode.put("G", 16);
        twFirstCode.put("H", 17);
        twFirstCode.put("J", 18);
        twFirstCode.put("K", 19);
        twFirstCode.put("L", 20);
        twFirstCode.put("M", 21);
        twFirstCode.put("N", 22);
        twFirstCode.put("P", 23);
        twFirstCode.put("Q", 24);
        twFirstCode.put("R", 25);
        twFirstCode.put("S", 26);
        twFirstCode.put("T", 27);
        twFirstCode.put("U", 28);
        twFirstCode.put("V", 29);
        twFirstCode.put("X", 30);
        twFirstCode.put("Y", 31);
        twFirstCode.put("W", 32);
        twFirstCode.put("Z", 33);
        twFirstCode.put("I", 34);
        twFirstCode.put("O", 35);
        hkFirstCode.put("A", 1);
        hkFirstCode.put("B", 2);
        hkFirstCode.put("C", 3);
        hkFirstCode.put("R", 18);
        hkFirstCode.put("U", 21);
        hkFirstCode.put("Z", 26);
        hkFirstCode.put("X", 24);
        hkFirstCode.put("W", 23);
        hkFirstCode.put("O", 15);
        hkFirstCode.put("N", 14);
    }

    /**
     * 将15位身份证号码转换为18位
     *
     * @param idCard
     *            15位身份编码
     * @return 18位身份编码
     */
    public static String conver15CardTo18(String idCard) {
        String idCard18 = "";
        if (idCard.length() != CHINA_ID_MIN_LENGTH) {
            return null;
        }
        if (isNum(idCard)) {
            // 获取出生年月日
            String birthday = idCard.substring(6, 12);
            Date birthDate = null;
            try {
                birthDate = new SimpleDateFormat("yyMMdd").parse(birthday);
            } catch (ParseException e) {
            }
            Calendar cal = Calendar.getInstance();
            if (birthDate != null) {
                cal.setTime(birthDate);
            }
            // 获取出生年(完全表现形式,如:2010)
            String sYear = String.valueOf(cal.get(Calendar.YEAR));
            idCard18 = idCard.substring(0, 6) + sYear + idCard.substring(8);
            // 转换字符数组
            char[] cArr = idCard18.toCharArray();
            if (cArr != null) {
                int[] iCard = converCharToInt(cArr);
                int iSum17 = getPowerSum(iCard);
                // 获取校验位
                String sVal = getCheckCode18(iSum17);
                if (sVal.length() > 0) {
                    idCard18 += sVal;
                } else {
                    return null;
                }
            }
        } else {
            return null;
        }
        return idCard18;
    }

    /**
     * 根据正则校验18位身份证
     * @param idCard 身份编码
     * @return
     */
    public static boolean validateIDCardByRegex(String idCard) {
        String curYear = "" + Calendar.getInstance().get(Calendar.YEAR);
        int y3 = Integer.valueOf(curYear.substring(2, 3));
        int y4 = Integer.valueOf(curYear.substring(3, 4));
        // 43 0103 1973 0 9 30 051 9
        return idCard.matches("^(1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|71|8[1-2])\\d{4}(19\\d{2}|20([0-" + (y3 - 1) + "][0-9]|" + y3 + "[0-" + y4
                + "]))(((0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])))\\d{3}([0-9]|x|X)$");
        // 44 1825 1988 0 7 1 3 003 4
    }


    /**
     * 验证身份证是否合法
     */
    public static boolean validateIdCard(String idCard) {
        String card = idCard.trim();
        if (validateIdCard18(card)) {
            return true;
        }
        if (validateIdCard15(card)) {
            return true;
        }
        String[] cardval = validateIdCard10(card);
        if (cardval != null) {
            if (cardval[2].equals("true")) {
                return true;
            }
        }
        return false;
    }

    /**
     * 验证18位身份编码是否合法
     *
     * @param idCard
     *            身份编码
     * @return 是否合法
     */
    public static boolean validateIdCard18(String idCard) {
        boolean bTrue = false;
        if (idCard.length() == CHINA_ID_MAX_LENGTH) {
            // 前17位
            String code17 = idCard.substring(0, 17);
            // 第18位
            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;
                        }
                    }
                }
            }
        }
        //校验通过 且 正则校验通过 且 可以获取到省份信息
        return bTrue && validateIDCardByRegex(idCard) && getProvinceByIdCard(idCard)!=null;
    }

    /**
     * 验证15位身份编码是否合法
     *
     * @param idCard
     *            身份编码
     * @return 是否合法
     */
    public static boolean validateIdCard15(String idCard) {
        if (idCard.length() != CHINA_ID_MIN_LENGTH) {
            return false;
        }
        if (isNum(idCard)) {
            String proCode = idCard.substring(0, 2);
            if (cityCodes.get(proCode) == null) {
                return false;
            }
            String birthCode = idCard.substring(6, 12);
            Date birthDate = null;
            try {
                birthDate = new SimpleDateFormat("yy").parse(birthCode
                        .substring(0, 2));
            } catch (ParseException e) {

            }
            Calendar cal = Calendar.getInstance();
            if (birthDate != null) {
                cal.setTime(birthDate);
            }
            if (!valiDate(cal.get(Calendar.YEAR),
                    Integer.valueOf(birthCode.substring(2, 4)),
                    Integer.valueOf(birthCode.substring(4, 6)))) {
                return false;
            }
        } else {
            return false;
        }
        return true;
    }

    /**
     * 验证10位身份编码是否合法
     *
     * @param idCard
     *            身份编码
     * @return 身份证信息数组
     *         

* [0] - 台湾、澳门、香港 [1] - 性别(男M,女F,未知N) [2] - 是否合法(合法true,不合法false) * 若不是身份证件号码则返回null *

*/ public static String[] validateIdCard10(String idCard) { String[] info = new String[3]; String card = idCard.replaceAll("[\\(|\\)]", ""); if (card.length() != 8 && card.length() != 9 && idCard.length() != 10) { return null; } if (idCard.matches("^[a-zA-Z][0-9]{9}{1}")) { // 台湾 info[0] = "台湾"; String char2 = idCard.substring(1, 2); if (char2.equals("1")) { info[1] = "M"; } else if (char2.equals("2")) { info[1] = "F"; } else { info[1] = "N"; info[2] = "false"; return info; } info[2] = validateTWCard(idCard) ? "true" : "false"; } else if (idCard.matches("^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?{1}")) { // 澳门 info[0] = "澳门"; info[1] = "N"; // TODO } else if (idCard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?{1}")) { // 香港 info[0] = "香港"; info[1] = "N"; info[2] = validateHKCard(idCard) ? "true" : "false"; } else { return null; } return info; } /** * 验证台湾身份证号码 * * @param idCard * 身份证号码 * @return 验证码是否符合 */ public static boolean validateTWCard(String idCard) { String start = idCard.substring(0, 1); String mid = idCard.substring(1, 9); String end = idCard.substring(9, 10); Integer iStart = twFirstCode.get(start); Integer sum = iStart / 10 + (iStart % 10) * 9; char[] chars = mid.toCharArray(); Integer iflag = 8; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end) ? true : false; } /** * 验证香港身份证号码(存在Bug,部份特殊身份证无法检查) *

* 身份证前2位为英文字符,如果只出现一个英文字符则表示第一位是空格,对应数字58 前2位英文字符A-Z分别对应数字10-35 * 最后一位校验码为0-9的数字加上字符"A","A"代表10 *

*

* 将身份证号码全部转换为数字,分别对应乘9-1相加的总和,整除11则证件号码有效 *

* * @param idCard * 身份证号码 * @return 验证码是否符合 */ public static boolean validateHKCard(String idCard) { String card = idCard.replaceAll("[\\(|\\)]", ""); Integer sum = 0; if (card.length() == 9) { sum = (Integer.valueOf(card.substring(0, 1).toUpperCase() .toCharArray()[0]) - 55) * 9 + (Integer.valueOf(card.substring(1, 2).toUpperCase() .toCharArray()[0]) - 55) * 8; card = card.substring(1, 9); } else { sum = 522 + (Integer.valueOf(card.substring(0, 1).toUpperCase() .toCharArray()[0]) - 55) * 8; } String mid = card.substring(1, 7); String end = card.substring(7, 8); char[] chars = mid.toCharArray(); Integer iflag = 7; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } if (end.toUpperCase().equals("A")) { sum = sum + 10; } else { sum = sum + Integer.valueOf(end); } return (sum % 11 == 0) ? true : false; } /** * 将字符数组转换成数字数组 * * @param ca * 字符数组 * @return 数字数组 */ private static int[] converCharToInt(char[] ca) { int len = ca.length; int[] iArr = new int[len]; try { for (int i = 0; i < len; i++) { iArr[i] = Integer.parseInt(String.valueOf(ca[i])); } } catch (NumberFormatException e) { } return iArr; } /** * 数字验证 * * @param val * @return 提取的数字。 */ private static boolean isNum(String val) { return val == null || "".equals(val) ? false : val .matches("^[0-9]*{1}"); } /** * 验证小于当前日期 是否有效 * * @param iYear * 待验证日期(年) * @param iMonth * 待验证日期(月 1-12) * @param iDate * 待验证日期(日) * @return 是否有效 */ private static boolean valiDate(int iYear, int iMonth, int iDate) { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int datePerMonth; if (iYear < MIN || iYear >= year) { return false; } if (iMonth < 1 || iMonth > 12) { return false; } switch (iMonth) { case 4: case 6: case 9: case 11: datePerMonth = 30; break; case 2: boolean dm = ((iYear % 4 == 0 && iYear % 100 != 0) || (iYear % 400 == 0)) && (iYear > MIN && iYear < year); datePerMonth = dm ? 29 : 28; break; default: datePerMonth = 31; } return (iDate >= 1) && (iDate <= datePerMonth); } /** * 将身份证的每位和对应位的加权因子相乘之后,再得到和值 * * @param iArr * @return 身份证编码。 */ private static int getPowerSum(int[] iArr) { int iSum = 0; if (power.length == iArr.length) { for (int i = 0; i < iArr.length; i++) { for (int j = 0; j < power.length; j++) { if (i == j) { iSum = iSum + iArr[i] * power[j]; } } } } return iSum; } /** * 将power和值与11取模获得余数进行校验码判断 * * @param iSum * @return 校验位 */ private static String getCheckCode18(int iSum) { int modValue = iSum % 11; String sCode = verifyCode[modValue]; return sCode; } /** * 根据身份编号获取年龄 * * @param idNo 身份编号 * * @return 年龄 */ public static int getAgeByIdCard(String idNo) { try { Calendar currentDate = Calendar.getInstance(); int bornYear = Integer.valueOf(idNo.substring(6, 10)); int bornMonth = Integer.valueOf(idNo.substring(10, 12)); int bornDay = Integer.valueOf(idNo.substring(12, 14)); int currentYear = currentDate.get(Calendar.YEAR); int currentMonth = currentDate.get(Calendar.MONTH) + 1; int currentDay = currentDate.get(Calendar.DATE); int age = currentYear - bornYear; if (bornMonth > currentMonth || (bornMonth == currentMonth && bornDay > currentDay)) { age--; } return age; } catch (Throwable e) { String errMsg = String.format("年龄计算失败, idNo:%s", idNo); throw new RuntimeException(errMsg, e); } } /** * 根据身份编号获取生日 * * @param idCard * 身份编号 * @return 生日(yyyyMMdd) */ public static String getBirthByIdCard(String idCard) { Integer len = idCard.length(); if (len < CHINA_ID_MIN_LENGTH) { return null; } else if (len == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } return idCard.substring(6, 14); } /** * 根据身份编号获取生日 * * @param idCard * 身份编号 * @return 生日(yyyy-MM-dd) */ public static String getBirthFormatByIdCard(String idCard) { Integer len = idCard.length(); if (len < CHINA_ID_MIN_LENGTH) { return null; } else if (len == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } return idCard.substring(6, 10)+"-"+idCard.substring(10, 12)+"-"+idCard.substring(12, 14); } /** * 根据身份编号获取生日年 * * @param idCard * 身份编号 * @return 生日(yyyy) */ public static Short getYearByIdCard(String idCard) { Integer len = idCard.length(); if (len < CHINA_ID_MIN_LENGTH) { return null; } else if (len == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } return Short.valueOf(idCard.substring(6, 10)); } /** * 根据身份编号获取生日月 * * @param idCard * 身份编号 * @return 生日(MM) */ public static Short getMonthByIdCard(String idCard) { Integer len = idCard.length(); if (len < CHINA_ID_MIN_LENGTH) { return null; } else if (len == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } return Short.valueOf(idCard.substring(10, 12)); } /** * 根据身份编号获取生日天 * * @param idCard * 身份编号 * @return 生日(dd) */ public static Short getDateByIdCard(String idCard) { Integer len = idCard.length(); if (len < CHINA_ID_MIN_LENGTH) { return null; } else if (len == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } return Short.valueOf(idCard.substring(12, 14)); } /** * 根据身份编号获取性别 * * @param idCard * 身份编号 * @return 性别(M-男,F-女,N-未知) */ public static String getGenderByIdCard(String idCard) { String sGender = "N"; if (idCard.length() == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } String sCardNum = idCard.substring(16, 17); if (Integer.parseInt(sCardNum) % 2 != 0) { sGender = "M"; } else { sGender = "F"; } return sGender; } /** * 根据身份编号获取户籍省份 * * @param idCard * 身份编码 * @return 省级编码。 */ public static String getProvinceByIdCard(String idCard) { int len = idCard.length(); String sProvince = null; String sProvinNum = ""; if (len == CHINA_ID_MIN_LENGTH || len == CHINA_ID_MAX_LENGTH) { sProvinNum = idCard.substring(0, 2); } sProvince = cityCodes.get(sProvinNum); return sProvince; } /** *根据身份证号,自动获取对应的星座 * * @param idCard * 身份证号码 * @return 星座 */ public static String getConstellationById(String idCard) { if (!validateIdCard(idCard)) { return ""; } int month = IDCardUtil.getMonthByIdCard(idCard); int day = IDCardUtil.getDateByIdCard(idCard); String strValue = ""; if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) { strValue = "水瓶座"; } else if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) { strValue = "双鱼座"; } else if ((month == 3 && day > 20) || (month == 4 && day <= 19)) { strValue = "白羊座"; } else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) { strValue = "金牛座"; } else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) { strValue = "双子座"; } else if ((month == 6 && day > 21) || (month == 7 && day <= 22)) { strValue = "巨蟹座"; } else if ((month == 7 && day > 22) || (month == 8 && day <= 22)) { strValue = "狮子座"; } else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) { strValue = "处女座"; } else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) { strValue = "天秤座"; } else if ((month == 10 && day > 23) || (month == 11 && day <= 22)) { strValue = "天蝎座"; } else if ((month == 11 && day > 22) || (month == 12 && day <= 21)) { strValue = "射手座"; } else if ((month == 12 && day > 21) || (month == 1 && day <= 19)) { strValue = "魔羯座"; } return strValue; } /** *根据身份证号,自动获取对应的生肖 * * @param idCard * 身份证号码 * @return 生肖 */ public static String getZodiacById(String idCard) { // 根据身份证号,自动返回对应的生肖 if (!validateIdCard(idCard)) { return ""; } String sSX[] = { "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗" }; int year = IDCardUtil.getYearByIdCard(idCard); int end = 3; int x = (year - end) % 12; String retValue = ""; retValue = sSX[x]; return retValue; } /** *根据身份证号,自动获取对应的天干地支 * * @param idCard * 身份证号码 * @return 天干地支 */ public static String getChineseEraById(String idCard) { // 根据身份证号,自动返回对应的生肖 if (!validateIdCard(idCard)) { return ""; } String sTG[] = { "癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "任" }; String sDZ[] = { "亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌" }; int year = IDCardUtil.getYearByIdCard(idCard); int i = (year - 3) % 10; int j = (year - 3) % 12; String retValue = ""; retValue = sTG[i] + sDZ[j]; return retValue; } public static void main(String[] args) { String idCard = "**************************"; System.out.println(IDCardUtil.validateIdCard(idCard)); System.out.println(IDCardUtil.getGenderByIdCard(idCard)); System.out.println(IDCardUtil.getAgeByIdCard(idCard)); System.out.println(IDCardUtil.getBirthByIdCard(idCard)); System.out.println(IDCardUtil.getBirthFormatByIdCard(idCard)); System.out.println(IDCardUtil.getMonthByIdCard(idCard)); System.out.println(IDCardUtil.getDateByIdCard(idCard)); System.out.println(IDCardUtil.getConstellationById(idCard)); System.out.println(IDCardUtil.getZodiacById(idCard)); System.out.println(IDCardUtil.getChineseEraById(idCard)); System.out.println(IDCardUtil.getProvinceByIdCard(idCard)); } }
  • 物流公司工具类

package com.github.wxiaoqi.demo;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 物流公司工具
 */
public class ExpressCompanyUtil {

    /** 物流公司列表 */
    private static final Map COMPANY = new HashMap<>(50);

    static {
        initialCountryMap();
    }

    /**
     * 初始化国家信息键值对
     */
    private static void initialCountryMap() {
        COMPANY.put("SF", "顺丰速运");
        COMPANY.put("HTKY", "百世快递");
        COMPANY.put("ZTO", "中通快递");
        COMPANY.put("STO", "申通快递");
        COMPANY.put("YTO", "圆通速递");
        COMPANY.put("YD", "韵达速递");
        COMPANY.put("YZPY", "邮政快递包裹");
        COMPANY.put("EMS", "EMS");
        COMPANY.put("HHTT", "天天快递");
        COMPANY.put("JD", "京东物流");
        COMPANY.put("UC", "优速快递");
        COMPANY.put("DBL", "德邦快递");
        COMPANY.put("FAST", "快捷快递");
        COMPANY.put("ZJS", "宅急送");
        COMPANY.put("ANE", "安能物流");
        COMPANY.put("BTWL", "百世快运");
        COMPANY.put("GTO", "国通快递");
        COMPANY.put("KYSY", "跨越速运");
        COMPANY.put("KYWL", "跨越物流");
        COMPANY.put("QFKD", "全峰快递");
        COMPANY.put("RFD", "如风达");
        COMPANY.put("RRS", "日日顺物流");
        COMPANY.put("ZTKY", "中铁快运");
        COMPANY.put("ZTWL", "中铁物流");
        COMPANY.put("ZYWL", "中邮物流");
        COMPANY.put("ZTOKY", "中通快运");
        COMPANY.put("ZYKD", "中邮快递");
    }

    /**
     * 获取快递公司名称,如不存在返回code
     * @param code
     * @return
     */
    public static String getExpressCompanyName(String code) {
        if (StringUtils.isBlank(code)){
            return "";
        }
        if (COMPANY.containsKey(code)) {
            return COMPANY.get(code);
        }
        return code;
    }

    public static void main(String[] args) {
        String companyName = ExpressCompanyUtil.getExpressCompanyName("JD");
        System.out.println(companyName);
    }
}


// 来自快递鸟官网:http://www.kdniao.com/api-track
/*
快递公司     编码    轨迹查询
顺丰速运	    SF	   "支持(注:仅支持通过快递鸟下单接口<1007/1001>返回的顺丰单号查询)"
百世快递	    HTKY	支持(注:仅支持物流跟踪接口<1008/8008>查询)
中通快递	    ZTO	    支持
申通快递	    STO	    支持(注:仅支持付费开通的在途监控接口<8001/8008>查询)
圆通速递	    YTO    	支持
韵达速递	    YD	    支持
邮政快递包裹 	YZPY	支持
EMS	        EMS    	支持
天天快递	    HHTT	支持(注:仅支持付费开通的在途监控接口<8001/8008>查询)
京东物流    	JD	    支持
优速快递	    UC    	支持
德邦快递    	DBL	    支持
快捷快递	    FAST	支持
宅急送	    ZJS	    支持
安能物流	    ANE	    支持
百世快运    	BTWL	支持
国通快递    	GTO	    支持
跨越速运	    KYSY	支持
跨越物流	    KYWL	支持
全峰快递	    QFKD	支持
如风达	    RFD	    支持
日日顺物流	RRS	    支持
中铁快运    	ZTKY	支持
中铁物流    	ZTWL	支持
中邮物流	    ZYWL	支持
中通快运	    ZTOKY	支持
中邮快递    	ZYKD	支持

*/

随机工具类

  • 随机数序列

package com.github.wxiaoqi.demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 在指定的范围内,生成不重复的随机数序列
 */
public class UnrepeatRandomNumber {
	private int min;
	private int max;
	public UnrepeatRandomNumber(){
		this.min = 0;
		this.max = 10;
	}
	public UnrepeatRandomNumber(int min, int max){
		this();
		if (max >= min){
			this.min = min;
			this.max = max;
		} else {
			System.out.println("max比min小,按缺省值生成UnrepeatRandomNumber对象!");
		}
	}
	/**
	 * 第一种方法:排除法。随机生成数字,如果是新生成的数字,则放到结果列表种
	 * 否则是已经生成过的,则不加入结果列表,继续随机生成。
	 * @param length	结果列表的长度
	 * @return
	 */
	public Integer[] getRandomMethodA(int length) {
		if (length <= 0) {
			return new Integer[0];
		} else if (length > (this.max - this.min)) {
			System.out.println("结果列表长度不能达到:" + length + ", 结果长度只能是:"
					+ (this.max - this.min));
			length = this.max - this.min;
		}
		Random rd = new Random();//用于生成随机结果
		List resultList = new ArrayList();
		while (resultList.size() < length) {
			//将[min, max]区间等价于min + [0, max - min + 1) 
			Integer randnum = new Integer(this.min + rd.nextInt(this.max - this.min + 1));
			if (!resultList.contains(randnum)){
				resultList.add(randnum);
			}
		}
		//使用toArray方法将List转换成对象数组返回
		return (Integer[])resultList.toArray(new Integer[0]);
	}
	
	/**
	 * 第二种方法:筛选法。将所有可能被生成的数字放到一个候选列表中。
	 * 然后生成随机数,作为下标,将候选列表中相应下标的数字放到放到结果列表中,
	 * 同时,把它在候选列表中删除。
	 * @param length	结果列表的长度
	 * @return
	 */
	public Integer[] getRandomMethodB(int length) {
		if (length <= 0) {
			return new Integer[0];
		} else if (length > (this.max - this.min)) {
			System.out.println("结果列表长度不能达到:" + length + ", 结果长度只能是:"
					+ (this.max - this.min));
			length = this.max - this.min;
		}
		//初始化候选列表,列表长度为 max -min + 1
		int candidateLength = this.max - this.min + 1;
		List candidateList = new ArrayList();
		for (int i=this.min; i<= this.max; i++){
			candidateList.add(new Integer(i));
		}
		
		Random rd = new Random();//用于生成随机下标
		List resultList = new ArrayList();
		while (resultList.size() < length) {
			//生成下标,在[0,candidateLength)范围内
			int index = rd.nextInt(candidateLength);
			//将候选队列中下标为index的数字对象放入结果队列中
			resultList.add(candidateList.get(index));
			//将下标为index的数字对象从候选队列中删除
			candidateList.remove(index);
			//候选队列长度减去1
			candidateLength --;
		}
		//使用toArray方法将List转换成对象数组返回
		return (Integer[])resultList.toArray(new Integer[0]);
	}
	
	public static void outputArray(Integer[] array){
		if (array != null){
			for (int i=0; i
  • 根据时间生产唯一id序列

package com.github.wxiaoqi.demo;

import java.text.*;
import java.util.Calendar;

/**
 * 根据时间生成唯一序列ID
* 时间精确到秒,ID最大值为99999且循环使用 * */ public class GenerateSequenceUtil { private static final FieldPosition HELPER_POSITION = new FieldPosition(0); /** 时间:精确到秒 */ private final static Format dateFormat = new SimpleDateFormat("YYYYMMddHHmmss"); private final static NumberFormat numberFormat = new DecimalFormat("00000"); private static int seq = 0; private static final int MAX = 99999; public static synchronized String generateSequenceNo() { Calendar rightNow = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION); numberFormat.format(seq, sb, HELPER_POSITION); if (seq == MAX) { seq = 0; } else { seq++; } return sb.toString(); } }
  • 其他随机方法

//###########################################################获取随机颜色#################################################

    /**
     * 生成随机颜色
     */
    public static Color getRandomColor() {
        int r = (int) (Math.random() * 256);
        int g = (int) (Math.random() * 256);
        int b = (int) (Math.random() * 256);
        return new Color(r, g, b);
    }

//###########################################################获取流水号#################################################
	
    /**
     * 获取系统流水号
     * 
* 若欲指定返回值的长度or是否全由数字组成等,you can call { TradePortalUtil#getSysJournalNo(int, boolean)} * * @return 长度为20的全数字 */ public static String getSysJournalNo() { return getSysJournalNo(20, true); } /** * 获取系统流水号 * * @param length 指定流水号长度 * @param isNumber 指定流水号是否全由数字组成 */ public static String getSysJournalNo(int length, boolean isNumber) { //replaceAll()之后返回的是一个由十六进制形式组成的且长度为32的字符串 String uuid = UUID.randomUUID().toString().replaceAll("-", ""); if (uuid.length() > length) { uuid = uuid.substring(0, length); } else if (uuid.length() < length) { for (int i = 0; i < length - uuid.length(); i++) { uuid = uuid + Math.round(Math.random() * 9); } } if (isNumber) { return uuid.replaceAll("a", "1").replaceAll("b", "2").replaceAll("c", "3").replaceAll("d", "4").replaceAll("e", "5").replaceAll("f", "6"); } else { return uuid; } }

 

未完待续!!(有其他需求可留言)

你可能感兴趣的:(工具类,字符串,StringUtils的,常用工具类)