生成随机银行卡号
测试一个功能需要随机的银行卡号,找了找发现没啥好用的,就自己搞了个轮子,勉强能用吧
References:
- https://zh.wikipedia.org/wiki/%E5%8F%91%E5%8D%A1%E8%A1%8C%E8%AF%86%E5%88%AB%E7%A0%81 发卡行识别码
- https://zh.wikipedia.org/wiki/Luhn%E7%AE%97%E6%B3%95 Luhn算法
- https://wiki.mbalib.com/wiki/%E5%87%86%E8%B4%B7%E8%AE%B0%E5%8D%A1 准贷记卡
- https://baike.baidu.com/item/%E5%87%86%E8%B4%B7%E8%AE%B0%E5%8D%A1
- https://www.zhihu.com/question/35536279 银联卡BIN
银行卡号是有规则的,不是随便生成了一串数字就能用的。
发卡行识别码(英语:Bank card number或Bank Identification Number,简称BIN),通常是指银行卡卡号前6位、用来表示发卡银行或机构的一套银行卡卡号编码。根据ISO/IEC 7812标准的规定,9字头BIN号由一国国内的标准组织分配,不适用于全球通用。
就是俗称的卡BIN。卡号的前六位数字(包括起始的MII码)被称为发行者识别号码(Issuer Identification Number,缩写为IIN)。这些数字可以让持卡者识别出银行卡的发行机构。剩下的数字由发行机构分配。银行卡由发行者通过发行网络发行。卡号的“长度”指其含有的数字的位数。许多信用卡发行机构在他们的卡片上浮雕数字下方打印IIN的前四位数字,作为额外的安全措施。之后是账户号码和校验码。
卡号最长19位,包括:
- 6位发行者识别号码(IIN)
- 最长12位的账户号码(Primary Account Number, PAN)
- 1位校验码,以Luhn算法计算
信用卡通常是16位,即是账户号码长9位。
以上摘录自维基百科,说的已经非常清楚了,此外再了解下国内常见的三种卡类型:
- 借记卡:借记卡是指持卡人在发卡银行先存款,后进行交易的银行卡。即常说的储蓄卡。
- 贷记卡:贷记卡是指发卡银行给予持卡人一定的信用额度,持卡人可在信用额度内先消费、后还款的银行卡。即常说的信用卡。
- 准贷记卡:先存款、后消费、可以透支。整合了借记卡和贷记卡的优势,准贷记卡是一种具有中国特色的信用卡种类,国外并没有这种类型的信用卡。
了解了银行卡的一些常见知识再看代码应该就很容易了, 一段生成随机卡号的代码, 生成的卡号都能通过Luhn校验。但是卡BIN只有很少的一部分,由于卡BIN属于比较敏感的信息,需要一定的权限才能获得,而且还会定期更新,所以没点东西是真的搞不定这个,当然测试用就随便搞几个就够用了:
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
/**
* 假数据生成
*
* @author racecoder
*/
public final class PseudoDataUtil {
private PseudoDataUtil() {
}
/**
* 生成指定数量随机银行随机卡号
*
* @param num 数量
*/
public static Queue<PseudoBankCard> getBankCardNumber(int num) {
if (num <= 0)
return new LinkedList<>();
Set<PseudoBankCard> cardSet = new HashSet<>(num);
do {
cardSet.add(getBankCardNumber());
} while (cardSet.size() < num);
return new LinkedList<>(cardSet);
}
/**
* 生成指定数量指定银行随机卡号
*
* @param num 数量
*/
public static Queue<PseudoBankCard> getBankCardNumber(int num, BankCardInfo bankCardInfo) {
if (num <= 0)
return new LinkedList<>();
Set<PseudoBankCard> cardSet = new HashSet<>(num);
do {
cardSet.add(getBankCardNumber(bankCardInfo));
} while (cardSet.size() < num);
return new LinkedList<>(cardSet);
}
/**
* 生成一个随机银行随机卡号
*/
public static PseudoBankCard getBankCardNumber() {
return getBankCardNumber(BankCardInfo.randomInfo());
}
/**
* 生成一个指定银行随机卡号
*/
public static PseudoBankCard getBankCardNumber(BankCardInfo bankCardInfo) {
// 需要生成的随机位长度, 长度不足补0
int randomLength = bankCardInfo.getNumberLength() - bankCardInfo.getBin().length() - 1;
int randomMax = (int) Math.pow(10, randomLength);
String randomNumber = String.valueOf(ThreadLocalRandom.current().nextInt(randomMax));
String bardNo = bankCardInfo.getBin() + org.apache.commons.lang3.StringUtils.leftPad(randomNumber, randomLength, "0");
return appendCheckCode(bankCardInfo, bardNo);
}
/**
* 生成卡号的校验位
*/
private static PseudoBankCard appendCheckCode(BankCardInfo cardInfo, String cardWithoutCheckSum) {
// 生成校验码
int luhnSum = getLuhnChecksum(cardWithoutCheckSum.trim().toCharArray());
char checkCode = luhnSum % 10 == 0 ? '0' : (char) (10 - luhnSum % 10 + '0');
return new PseudoBankCard(cardWithoutCheckSum + checkCode, cardInfo);
}
public enum CardType {
/**
* 借记卡
*/
DEBIT,
/**
* 贷记卡
*/
CREDIT,
/**
* 准贷记卡
*/
SEMI_CREDIT
}
/**
* 从不含校验位的银行卡卡号获得校验位, 校验码为银行卡号最后一位
* 采用Luhn校验算法, 亦称模10算法. 计算方法如下:
* <ol>
* <li>从右边第1个数字开始每隔一位乘以2</li>
* <li>从卡号最后一位数字开始, 逆向将偶数位数字, 先乘以2(如果乘积为两位数,则将其减去9), 再求和</li>
* <li>将奇数位总和加上偶数位总和, 结果应该可以被10整除</li>
* </ol>
*/
private static int getLuhnChecksum(char[] chs) {
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;
}
public enum BankCardInfo {
ABC_2("491020", "中国农业银行", "金穗信用卡", 16, CardType.SEMI_CREDIT),
ABC_3("519412", "中国农业银行", "金穗贷记卡", 16, CardType.CREDIT),
ABC_4("520082", "中国农业银行", "金穗贷记卡", 16, CardType.CREDIT),
ABC_6("535910", "中国农业银行", "金穗信用卡", 16, CardType.SEMI_CREDIT),
ABC_7("535918", "中国农业银行", "金穗信用卡", 16, CardType.SEMI_CREDIT),
ABC_8("552599", "中国农业银行", "金穗贷记卡", 16, CardType.CREDIT),
ABC_9("558730", "中国农业银行", "金穗贷记卡", 16, CardType.CREDIT),
ABC_10("103000", "中国农业银行", "金穗借记卡", 19, CardType.DEBIT),
ABC_11("403361", "中国农业银行", "金穗贷记卡", 16, CardType.CREDIT),
ABC_12("404117", "中国农业银行", "金穗贷记卡", 16, CardType.CREDIT),
BOC_1("438088", "中国银行", "中银奥运信用卡个人卡", 16, CardType.CREDIT),
BOC_2("451291", "中国银行", "长城国际卡(欧元卡)-个人金卡", 16, CardType.CREDIT),
BOC_3("456351", "中国银行", "长城电子借记卡", 19, CardType.DEBIT),
BOC_4("493878", "中国银行", "长城国际卡(港币卡)-个人金卡", 16, CardType.CREDIT),
BOC_5("512315", "中国银行", "中银万事达信用卡员工普卡", 16, CardType.CREDIT),
BOC_6("512316", "中国银行", "中银万事达信用卡个人普卡", 16, CardType.CREDIT),
BOC_7("512411", "中国银行", "中银万事达信用卡员工金卡", 16, CardType.CREDIT),
BOC_8("512412", "中国银行", "中银万事达信用卡个人金卡", 16, CardType.CREDIT),
BOC_9("512695", "中国银行", "长城国际卡(英镑卡)-个人普卡", 16, CardType.CREDIT),
BOC_10("512732", "中国银行", "长城国际卡(英镑卡)-个人金卡", 16, CardType.CREDIT),
BOC_11("514957", "中国银行", "中银万事达信用卡员工白金卡", 16, CardType.CREDIT),
BOC_12("514958", "中国银行", "中银万事达信用卡个人白金卡", 16, CardType.CREDIT),
BOC_14("522153", "中国银行", "长城国际卡(欧元卡)-个人普卡", 16, CardType.CREDIT),
BOC_15("518378", "中国银行", "长城人民币信用卡-个人金卡", 16, CardType.SEMI_CREDIT),
BOC_16("518379", "中国银行", "长城人民币信用卡-员工金卡", 16, CardType.SEMI_CREDIT),
BOC_17("518474", "中国银行", "长城人民币信用卡-专用卡普卡", 16, CardType.SEMI_CREDIT),
BOC_18("518475", "中国银行", "长城人民币信用卡-员工普卡", 16, CardType.SEMI_CREDIT),
BOC_19("518476", "中国银行", "长城人民币信用卡-个人普卡", 16, CardType.SEMI_CREDIT),
BOC_20("524864", "中国银行", "长城信用卡", 16, CardType.SEMI_CREDIT),
BOC_21("524865", "中国银行", "长城信用卡", 16, CardType.SEMI_CREDIT),
BOC_22("525745", "中国银行", "长城信用卡", 16, CardType.SEMI_CREDIT),
BOC_23("525746", "中国银行", "长城信用卡", 16, CardType.SEMI_CREDIT),
BOC_24("540297", "中国银行", "长城国际卡(港币卡)-个人普卡", 16, CardType.CREDIT),
BOC_25("540838", "中国银行", "长城国际卡(美元卡)-个人普卡", 16, CardType.CREDIT),
BOC_26("541068", "中国银行", "长城国际卡(美元卡)-个人金卡", 16, CardType.CREDIT),
BOC_27("547628", "中国银行", "长城国际卡(美元卡)-商务普卡", 16, CardType.CREDIT),
BOC_28("547648", "中国银行", "长城国际卡(港币卡)-商务普卡", 16, CardType.CREDIT),
BOC_29("547766", "中国银行", "长城人民币信用卡-单位普卡", 16, CardType.SEMI_CREDIT),
BOC_30("547766", "中国银行", "长城万事达信用卡单位普卡", 16, CardType.SEMI_CREDIT),
BOC_31("553131", "中国银行", "长城公务卡", 16, CardType.CREDIT),
BOC_32("552742", "中国银行", "长城公务卡", 16, CardType.CREDIT),
BOC_33("558808", "中国银行", "长城国际卡(港币卡)-商务金卡", 16, CardType.CREDIT),
BOC_34("558809", "中国银行", "长城国际卡(美元卡)-商务金卡", 16, CardType.CREDIT),
BOC_35("558868", "中国银行", "长城人民币信用卡-单位金卡", 16, CardType.SEMI_CREDIT),
BOC_36("558868", "中国银行", "中银万事达信用卡单位金卡", 16, CardType.SEMI_CREDIT),
BOC_37("622346", "中国银行", "人民币信用卡金卡", 16, CardType.CREDIT),
BOC_38("622347", "中国银行", "人民币信用卡普通卡", 16, CardType.CREDIT),
BOC_39("622348", "中国银行", "中银卡", 16, CardType.DEBIT),
BOC_40("400937", "中国银行", "长城国际卡(美元卡)-商务普卡", 16, CardType.CREDIT),
BOC_41("400938", "中国银行", "长城国际卡(美元卡)-商务金卡", 16, CardType.CREDIT),
BOC_42("400939", "中国银行", "长城国际卡(港币卡)-商务普卡", 16, CardType.CREDIT),
BOC_43("400940", "中国银行", "长城国际卡(港币卡)-商务金卡", 16, CardType.CREDIT),
BOC_44("400941", "中国银行", "长城国际卡(美元卡)-个人普卡", 16, CardType.CREDIT),
BOC_45("400942", "中国银行", "长城国际卡(美元卡)-个人金卡", 16, CardType.CREDIT),
BOC_46("409665", "中国银行", "中银威士信用卡员工普卡", 16, CardType.CREDIT),
BOC_47("409666", "中国银行", "中银威士信用卡个人普卡", 16, CardType.CREDIT),
BOC_48("424109", "中国银行", "长城人民币信用卡-员工普卡", 16, CardType.SEMI_CREDIT),
BOC_49("424110", "中国银行", "长城人民币信用卡-单位普卡", 16, CardType.SEMI_CREDIT),
BOC_50("424111", "中国银行", "长城人民币信用卡-单位金卡", 16, CardType.SEMI_CREDIT),
BOC_51("424902", "中国银行", "长城国际卡(美元卡)-白金卡", 16, CardType.CREDIT),
CCB_1("436718", "中国建设银行", "龙卡贷记卡公司卡金卡VISA", 16, CardType.DEBIT),
CCB_2("436718", "中国建设银行", "龙卡贷记卡公司卡金卡VISA", 16, CardType.CREDIT),
CCB_3("436728", "中国建设银行", "龙卡普通卡VISA", 16, CardType.SEMI_CREDIT),
CCB_4("436738", "中国建设银行", "龙卡贷记卡公司卡普通卡VISA", 16, CardType.CREDIT),
CCB_5("436742", "中国建设银行", "龙卡储蓄卡", 19, CardType.DEBIT),
CCB_6("436745", "中国建设银行", "龙卡国际普通卡VISA", 16, CardType.CREDIT),
CCB_7("436748", "中国建设银行", "龙卡国际金卡VISA", 16, CardType.CREDIT),
CCB_8("453242", "中国建设银行", "VISA准贷记卡", 16, CardType.SEMI_CREDIT),
CCB_9("491031", "中国建设银行", "VISA准贷记金卡", 16, CardType.SEMI_CREDIT),
CCB_10("434061", "中国建设银行", "乐当家金卡VISA", 16, CardType.DEBIT),
CCB_11("434062", "中国建设银行", "乐当家白金卡VISA", 16, CardType.DEBIT),
CCB_12("489592", "中国建设银行", "VISA白金/钻石信用卡", 16, CardType.CREDIT),
CCB_13("524094", "中国建设银行", "乐当家金卡MASTER", 16, CardType.DEBIT),
CCB_14("526410", "中国建设银行", "乐当家银卡MASTER", 16, CardType.DEBIT),
CCB_15("532420", "中国建设银行", "MASTER准贷记卡", 16, CardType.SEMI_CREDIT),
CCB_16("532430", "中国建设银行", "龙卡普通卡MASTER", 16, CardType.SEMI_CREDIT),
CCB_17("532450", "中国建设银行", "龙卡国际普通卡MASTER", 16, CardType.CREDIT),
CCB_18("532458", "中国建设银行", "龙卡国际金卡MASTER", 16, CardType.CREDIT),
CCB_19("544033", "中国建设银行", "MASTER准贷记金卡", 16, CardType.SEMI_CREDIT),
CCB_20("552245", "中国建设银行", "乐当家白金卡MASTER", 16, CardType.DEBIT),
CCB_21("552801", "中国建设银行", "龙卡贷记卡公司卡普通卡MASTER", 16, CardType.CREDIT),
CCB_22("553242", "中国建设银行", "龙卡信用卡", 18, CardType.CREDIT),
CCB_23("622280", "中国建设银行", "银联储蓄卡", 19, CardType.DEBIT),
CCB_24("622700", "中国建设银行", "龙卡储蓄卡", 19, CardType.DEBIT),
CCB_25("622725", "中国建设银行", "龙卡准贷记卡", 16, CardType.SEMI_CREDIT),
CCB_26("622728", "中国建设银行", "龙卡准贷记卡金卡", 16, CardType.SEMI_CREDIT),
ICBC_1("438125", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_2("451804", "中国工商银行", "牡丹贷记卡", 16, CardType.CREDIT),
ICBC_3("451804", "中国工商银行", "牡丹贷记卡", 16, CardType.CREDIT),
ICBC_4("451810", "中国工商银行", "牡丹贷记卡", 16, CardType.CREDIT),
ICBC_5("451810", "中国工商银行", "牡丹贷记卡", 16, CardType.CREDIT),
ICBC_6("458060", "中国工商银行", "牡丹信用卡", 16, CardType.CREDIT),
ICBC_7("458060", "中国工商银行", "牡丹信用卡", 16, CardType.CREDIT),
ICBC_8("458071", "中国工商银行", "牡丹贷记卡", 16, CardType.CREDIT),
ICBC_9("458071", "中国工商银行", "牡丹贷记卡", 16, CardType.CREDIT),
ICBC_10("510529", "中国工商银行", "牡丹万事达国际借记卡", 16, CardType.CREDIT),
ICBC_11("524047", "中国工商银行", "牡丹万事达白金卡", 16, CardType.CREDIT),
ICBC_12("530970", "中国工商银行", "牡丹万事达信用卡", 16, CardType.CREDIT),
ICBC_13("530980", "中国工商银行", "牡丹信用卡", 16, CardType.CREDIT),
ICBC_14("530980", "中国工商银行", "牡丹信用卡", 16, CardType.CREDIT),
ICBC_15("530990", "中国工商银行", "牡丹万事达信用卡", 16, CardType.CREDIT),
ICBC_16("548259", "中国工商银行", "国际借记卡", 16, CardType.CREDIT),
ICBC_17("558360", "中国工商银行", "牡丹万事达信用卡", 16, CardType.CREDIT),
ICBC_18("427010", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_19("427018", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_20("427019", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_21("427020", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_22("427028", "中国工商银行", "国际借记卡", 16, CardType.CREDIT),
ICBC_23("427029", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_24("427038", "中国工商银行", "国际借记卡", 16, CardType.CREDIT),
ICBC_25("427039", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_26("427062", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_27("427064", "中国工商银行", "牡丹VISA信用卡", 16, CardType.CREDIT),
ICBC_28("955880", "中国工商银行", "牡丹银联灵通卡-个人普卡", 16, CardType.DEBIT),
ICBC_29("955881", "中国工商银行", "牡丹银联灵通卡-个人普卡", 16, CardType.DEBIT),
ICBC_30("955882", "中国工商银行", "牡丹银联灵通卡-个人金卡", 16, CardType.DEBIT),
ICBC_31("955888", "中国工商银行", "牡丹银联理财金卡", 16, CardType.DEBIT),
ICBC_32("402791", "中国工商银行", "国际借记卡", 16, CardType.CREDIT),
ICBC_33("622211", "中国工商银行", "准贷记卡(个普)", 16, CardType.SEMI_CREDIT),
ICBC_34("622212", "中国工商银行", "准贷记卡(个普)", 16, CardType.SEMI_CREDIT),
ICBC_35("622213", "中国工商银行", "准贷记卡(个普)", 16, CardType.SEMI_CREDIT),
ICBC_36("622214", "中国工商银行", "准贷记卡(个普)", 16, CardType.SEMI_CREDIT),
ICBC_37("622215", "中国工商银行", "准贷记卡(个金)", 16, CardType.SEMI_CREDIT),
ICBC_38("622220", "中国工商银行", "准贷记卡(商普)", 16, CardType.SEMI_CREDIT),
ICBC_39("622225", "中国工商银行", "准贷记卡(商金)", 16, CardType.SEMI_CREDIT),
ICBC_40("622230", "中国工商银行", "贷记卡(个普)", 16, CardType.CREDIT),
ICBC_41("622235", "中国工商银行", "贷记卡(个金)", 16, CardType.CREDIT),
ICBC_42("622240", "中国工商银行", "贷记卡(商普)", 16, CardType.CREDIT),
ICBC_43("622245", "中国工商银行", "贷记卡(商金)", 16, CardType.CREDIT),
ICBC_44("438126", "中国工商银行", "牡丹VISA白金卡", 16, CardType.CREDIT),
ICBC_45("489734", "中国工商银行", "牡丹欧元卡", 16, CardType.CREDIT),
ICBC_46("489735", "中国工商银行", "牡丹欧元卡", 16, CardType.CREDIT),
ICBC_47("489736", "中国工商银行", "牡丹欧元卡", 16, CardType.CREDIT),
ICBC_48("524091", "中国工商银行", "牡丹海航信用卡个人金卡", 16, CardType.CREDIT),
ICBC_49("525498", "中国工商银行", "牡丹海航信用卡个人普卡", 16, CardType.CREDIT),
CMB_1("356888", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_2("356889", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_3("356890", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_4("402658", "招商银行", "两地一卡通", 16, CardType.DEBIT),
CMB_5("439188", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_6("439225", "招商银行", "VISA信用卡", 16, CardType.CREDIT),
CMB_7("439227", "招商银行", "VISA商务信用卡", 16, CardType.CREDIT),
CMB_8("468203", "招商银行", "招商银行银行国际卡", 16, CardType.DEBIT),
CMB_9("479228", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_10("479229", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_11("512425", "招商银行", "招商银行银行国际卡", 16, CardType.DEBIT),
CMB_12("545619", "招商银行", "万事达信用卡", 16, CardType.CREDIT),
CMB_13("545623", "招商银行", "万事达信用卡", 16, CardType.CREDIT),
CMB_14("545947", "招商银行", "万事达信用卡", 16, CardType.CREDIT),
CMB_15("552534", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_16("552587", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_17("518710", "招商银行", "MASTER信用卡", 16, CardType.CREDIT),
CMB_18("518718", "招商银行", "MASTER信用金卡", 16, CardType.CREDIT),
CMB_19("524011", "招商银行", "招商银行银行国际卡", 16, CardType.DEBIT),
CMB_20("622579", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_21("622580", "招商银行", "一卡通", 16, CardType.DEBIT),
CMB_22("622581", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_23("622582", "招商银行", "招商银行银行信用卡", 16, CardType.CREDIT),
CMB_24("622588", "招商银行", "一卡通", 16, CardType.DEBIT),
CMB_25("622598", "招商银行", "公司卡", 16, CardType.DEBIT),
CITICIB_1("442729", "中信银行", "中信国际借记卡", 16, CardType.DEBIT),
CITICIB_2("442730", "中信银行", "中信国际借记卡", 16, CardType.DEBIT),
CITICIB_3("556617", "中信银行", "中信MASTERCARD人民币+美金双币贷记卡", 16, CardType.CREDIT),
CITICIB_4("622690", "中信银行", "中信借记卡", 16, CardType.DEBIT),
CITICIB_5("622691", "中信银行", "中信借记卡", 16, CardType.DEBIT),
CITICIB_6("622692", "中信银行", "中信贵宾卡", 16, CardType.DEBIT),
CITICIB_7("514906", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_8("520108", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_9("518212", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_10("400360", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_11("403391", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_12("404157", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_13("404171", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_14("404172", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_15("404173", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_16("404174", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_17("433666", "中信银行", "中信贷记卡", 16, CardType.CREDIT),
CITICIB_18("433670", "中信银行", "中信借记卡", 16, CardType.DEBIT),
CITICIB_19("433680", "中信银行", "中信借记卡", 16, CardType.DEBIT),
CITICIB_20("622678", "中信银行", "中信银联标准贷记卡", 16, CardType.CREDIT),
CITICIB_21("622679", "中信银行", "中信银联标准贷记卡", 16, CardType.CREDIT),
CITICIB_22("622680", "中信银行", "中信银联标准贷记卡", 16, CardType.CREDIT),
CITICIB_23("622688", "中信银行", "中信银联标准贷记卡", 16, CardType.CREDIT),
CITICIB_24("622689", "中信银行", "中信银联标准贷记卡", 16, CardType.CREDIT),
CITICIB_25("622696", "中信银行", "中信理财宝金卡", 16, CardType.DEBIT),
CITICIB_26("622698", "中信银行", "中信理财宝白金卡", 16, CardType.DEBIT),
SPDB_1("870100", "浦发银行", "东方卡", 16, CardType.DEBIT),
SPDB_2("870300", "浦发银行", "东方卡", 16, CardType.DEBIT),
SPDB_3("870400", "浦发银行", "东方卡", 16, CardType.DEBIT),
SPDB_4("870500", "浦发银行", "东方卡", 16, CardType.DEBIT),
SPDB_9("622500", "浦发银行", "东方卡", 16, CardType.CREDIT),
SPDB_5("456418", "浦发银行", "信用卡VISA年青卡", 16, CardType.CREDIT),
SPDB_6("498451", "浦发银行", "信用卡VISA白金卡", 16, CardType.CREDIT),
SPDB_7("404738", "浦发银行", "信用卡VISA普通卡", 16, CardType.CREDIT),
SPDB_8("404739", "浦发银行", "信用卡VISA金卡", 16, CardType.CREDIT),
SPDB_10("622516", "浦发银行", "东方-轻松理财卡白金卡", 16, CardType.CREDIT),
SPDB_11("622517", "浦发银行", "东方-轻松理财卡普卡", 16, CardType.CREDIT),
SPDB_12("622518", "浦发银行", "东方-轻松理财卡钻石卡", 16, CardType.CREDIT),
SPDB_13("622519", "浦发银行", "东方-新标准准贷记卡", 16, CardType.SEMI_CREDIT),
SPDB_14("984301", "浦发银行", "东方卡", 16, CardType.DEBIT),
CEB_1("622650", "中国光大银行", "炎黄卡普卡", 16, CardType.CREDIT),
CEB_2("622655", "中国光大银行", "炎黄卡白金卡", 16, CardType.CREDIT),
CEB_3("622658", "中国光大银行", "炎黄卡金卡", 16, CardType.CREDIT),
CEB_4("543159", "中国光大银行", "第十八届世界足球锦标赛纪念卡", 16, CardType.CREDIT),
CEB_5("481699", "中国光大银行", "阳光白金信用卡", 16, CardType.CREDIT),
CEB_6("486497", "中国光大银行", "阳光商旅信用卡", 16, CardType.CREDIT),
CEB_7("303781", "中国光大银行", "阳光爱心卡", 16, CardType.CREDIT),
CEB_8("406252", "中国光大银行", "阳光信用卡", 16, CardType.CREDIT),
CEB_9("406254", "中国光大银行", "阳光信用卡", 16, CardType.CREDIT),
CEB_10("425862", "中国光大银行", "阳光商旅信用卡", 16, CardType.CREDIT),
CEB_11("622660", "中国光大银行", "阳光卡", 16, CardType.DEBIT),
CGB_1("436768", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_3("406365", "广发银行", "广发VISA信用卡", 16, CardType.CREDIT),
CGB_4("428911", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_5("541709", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_6("528931", "广发银行", "广发万事达信用卡", 16, CardType.CREDIT),
CGB_7("548844", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_8("552794", "广发银行", "广发万事达信用卡", 16, CardType.CREDIT),
CGB_9("558894", "广发银行", "广发万事达信用卡", 16, CardType.CREDIT),
CGB_10("487013", "广发银行", "广发VISA信用卡", 16, CardType.CREDIT),
CGB_11("491032", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_12("493427", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_13("518364", "广发银行", "广发信用卡", 16, CardType.CREDIT),
CGB_14("520152", "广发银行", "广发万事达信用卡", 16, CardType.CREDIT),
CGB_15("520382", "广发银行", "广发万事达信用卡", 16, CardType.CREDIT),
CIB_1("438588", "兴业银行", "兴业智能卡", 18, CardType.DEBIT),
CIB_2("438589", "兴业银行", "兴业智能卡", 18, CardType.DEBIT),
CIB_3("451289", "兴业银行", "VISA信用卡", 16, CardType.CREDIT),
CIB_4("486493", "兴业银行", "VISA商务普卡", 16, CardType.CREDIT),
CIB_5("486494", "兴业银行", "VISA商务金卡", 16, CardType.CREDIT),
CIB_6("523036", "兴业银行", "万事达信用卡", 16, CardType.CREDIT),
CIB_7("524070", "兴业银行", "万事达信用卡", 16, CardType.CREDIT),
CIB_8("527414", "兴业银行", "加菲猫信用卡", 16, CardType.CREDIT),
CMBC_1("472067", "中国民生银行", "民生国际卡", 16, CardType.DEBIT),
CMBC_2("472068", "中国民生银行", "民生国际卡", 16, CardType.DEBIT),
CMBC_3("512466", "中国民生银行", "民生贷记卡", 16, CardType.CREDIT),
CMBC_4("517636", "中国民生银行", "民生贷记卡", 16, CardType.CREDIT),
CMBC_5("528948", "中国民生银行", "民生贷记卡", 16, CardType.CREDIT),
CMBC_6("552288", "中国民生银行", "民生贷记卡", 16, CardType.CREDIT),
CMBC_7("556610", "中国民生银行", "民生贷记卡", 16, CardType.CREDIT),
CMBC_8("407405", "中国民生银行", "民生贷记卡", 16, CardType.CREDIT),
CMBC_9("622600", "中国民生银行", "民生信用卡", 16, CardType.CREDIT),
CMBC_10("622601", "中国民生银行", "民生信用卡", 16, CardType.CREDIT),
CMBC_11("622615", "中国民生银行", "民生借记卡", 16, CardType.DEBIT),
CMBC_12("427570", "中国民生银行", "民生国际借记卡", 16, CardType.DEBIT),
CMBC_14("427571", "中国民生银行", "民生国际借记卡", 16, CardType.DEBIT),
CMBC_15("622602", "中国民生银行", "民生银联白金信用卡", 16, CardType.CREDIT),
CMBC_16("622603", "中国民生银行", "民生银联商务信用卡", 16, CardType.CREDIT),
CMBC_17("622617", "中国民生银行", "民生借记卡", 16, CardType.DEBIT),
CMBC_18("622619", "中国民生银行", "民生借记卡", 16, CardType.DEBIT),
CMBC_19("622622", "中国民生银行", "民生借记卡", 16, CardType.DEBIT),
BCM_1("458123", "交通银行", "太平洋双币贷记卡VISA", 16, CardType.CREDIT),
BCM_2("458124", "交通银行", "太平洋双币贷记卡VISA", 16, CardType.CREDIT),
BCM_4("405512", "交通银行", "太平洋互连卡", 17, CardType.DEBIT),
BCM_5("405512", "交通银行", "太平洋互连卡", 17, CardType.DEBIT),
BCM_6("491040", "交通银行", "太平洋信用卡", 16, CardType.CREDIT),
BCM_7("520169", "交通银行", "太平洋双币贷记卡MasterCard", 16, CardType.CREDIT),
BCM_8("521899", "交通银行", "太平洋双币贷记卡MasterCard", 16, CardType.CREDIT),
BCM_9("537830", "交通银行", "太平洋信用卡", 16, CardType.CREDIT),
BCM_10("552853", "交通银行", "太平洋双币贷记卡MasterCard", 16, CardType.CREDIT),
BCM_11("622254", "交通银行", "太平洋人民币准贷记卡", 16, CardType.SEMI_CREDIT),
BCM_12("622258", "交通银行", "太平洋人民币借记卡", 17, CardType.DEBIT),
BCM_14("622259", "交通银行", "太平洋人民币借记卡", 17, CardType.DEBIT),
BCM_15("622260", "交通银行", "太平洋人民币借记卡", 19, CardType.DEBIT),
BCM_16("622261", "交通银行", "太平洋人民币借记卡", 19, CardType.DEBIT),
BCM_17("622250", "交通银行", "太平洋人民币贷记卡", 16, CardType.CREDIT),
BCM_18("622251", "交通银行", "太平洋人民币贷记卡", 16, CardType.CREDIT),
BCM_19("622252", "交通银行", "太平洋人民币贷记卡", 16, CardType.CREDIT),
BCM_20("622253", "交通银行", "太平洋人民币贷记卡", 16, CardType.CREDIT),
HXB_1("622630", "华夏银行", "华夏卡", 16, CardType.DEBIT),
HXB_2("622631", "华夏银行", "华夏至尊金卡", 16, CardType.DEBIT),
HXB_3("622632", "华夏银行", "华夏丽人卡", 16, CardType.DEBIT),
HXB_4("622633", "华夏银行", "华夏万通卡", 16, CardType.DEBIT),
HXB_5("431502", "华夏银行", "华夏卡", 16, CardType.DEBIT),
OTHER_BANK_1("622303", "南京银行", "梅花贷记卡", 16, CardType.CREDIT),
OTHER_BANK_2("622305", "南京银行", "梅花借记卡", 16, CardType.DEBIT),
OTHER_BANK_3("622127", "福建省农村信用社联合社", "万通卡", 19, CardType.DEBIT),
OTHER_BANK_4("622301", "湖州市商业银行", "百合卡", 19, CardType.DEBIT),
OTHER_BANK_5("622302", "广东省农村信用社联合社", "信通卡", 16, CardType.DEBIT),
OTHER_BANK_6("622307", "九江银行", "庐山卡", 19, CardType.DEBIT),
OTHER_BANK_7("622308", "昆明商业银行", "春城卡", 17, CardType.DEBIT),
OTHER_BANK_8("622310", "西宁市商业银行", "三江银行卡", 17, CardType.DEBIT),
OTHER_BANK_9("622311", "齐商银行", "金达借记卡", 17, CardType.DEBIT),
OTHER_BANK_10("622312", "徐州市郊农村信用合作联社", "信通卡", 16, CardType.DEBIT),
OTHER_BANK_11("622319", "山东省农村信用社联合社", "泰山如意IC卡", 16, CardType.DEBIT),
OTHER_BANK_12("622321", "台州银行", "大唐贷记卡", 16, CardType.CREDIT),
OTHER_BANK_13("622322", "广东顺德农村商业银行", "恒通卡", 16, CardType.DEBIT),
OTHER_BANK_14("622323", "常熟农村商业银行", "粒金借记卡", 19, CardType.DEBIT),
OTHER_BANK_15("622324", "江苏省农村信用社联合社", "圆鼎卡", 19, CardType.DEBIT),
OTHER_BANK_16("622325", "汉口银行", "九通卡", 16, CardType.DEBIT),
OTHER_BANK_17("622327", "徽商银行", "黄山卡", 17, CardType.DEBIT),
OTHER_BANK_18("622328", "东莞农村商业银行", "信通卡", 19, CardType.DEBIT),
OTHER_BANK_19("622329", "天津农村商业银行", "信通借记卡", 19, CardType.DEBIT),
OTHER_BANK_20("622331", "天津银行", "津卡", 18, CardType.DEBIT),
OTHER_BANK_21("622332", "张家港农村商业银行", "一卡通", 17, CardType.DEBIT),
OTHER_BANK_22("622333", "东莞农村商业银行", "万顺通卡", 16, CardType.DEBIT),
OTHER_BANK_23("622335", "南宁市商业银行", "桂花卡", 16, CardType.DEBIT),
OTHER_BANK_24("622336", "包商银行", "雄鹰卡", 17, CardType.DEBIT),
OTHER_BANK_25("622337", "连云港市商业银行", "金猴神通借记卡", 16, CardType.DEBIT),
OTHER_BANK_26("622338", "焦作中旅银行", "月季借记卡", 19, CardType.DEBIT),
OTHER_BANK_27("622339", "宁波鄞州农村商业银行", "蜜蜂借记卡", 16, CardType.DEBIT),
OTHER_BANK_28("622340", "徽商银行", "黄山卡", 17, CardType.DEBIT),
OTHER_BANK_29("622341", "江阴农村商业银行", "合作借记卡", 16, CardType.DEBIT),
OTHER_BANK_30("622342", "攀枝花市商业银行", "攀枝花卡", 19, CardType.DEBIT),
OTHER_BANK_31("622343", "佛山市三水区农村信用合作社", "信通卡", 19, CardType.DEBIT),
OTHER_BANK_32("622345", "成都农村商业银行", "天府借记卡", 19, CardType.DEBIT),
OTHER_BANK_33("622349", "南洋商业银行", "人民币信用卡金卡", 16, CardType.CREDIT),
OTHER_BANK_34("622350", "南洋商业银行", "人民币信用卡普通卡", 16, CardType.CREDIT),
OTHER_BANK_35("185720", "云南省农村信用社联合社", "金碧卡", 16, CardType.DEBIT),
OTHER_BANK_36("622498", "河北银行", "如意借记卡", 19, CardType.DEBIT),
OTHER_BANK_37("622499", "河北银行", "如意借记卡", 19, CardType.DEBIT),
OTHER_BANK_38("622506", "陕西省农村信用社联合社", "陕西信合富泰卡", 19, CardType.DEBIT),
OTHER_BANK_39("622509", "广东省农村信用社联合社", "信通白金卡", 19, CardType.DEBIT),
OTHER_BANK_40("622510", "广东省农村信用社联合社", "信通金卡", 19, CardType.DEBIT),
OTHER_BANK_41("622681", "江西省农村信用社联合社", "百福卡", 19, CardType.DEBIT),
OTHER_BANK_42("622682", "江西省农村信用社联合社", "百福卡", 19, CardType.DEBIT),
OTHER_BANK_43("622684", "渤海银行", "渤海银行公司借记卡", 16, CardType.DEBIT),
OTHER_BANK_44("888000", "贵阳银行", "甲秀卡", 16, CardType.DEBIT),
OTHER_BANK_45("940056", "郑州银行", "世纪一卡通", 17, CardType.DEBIT),
OTHER_BANK_46("622291", "柳州银行", "龙城卡", 18, CardType.DEBIT),
OTHER_BANK_47("622292", "柳州银行", "龙城卡", 18, CardType.DEBIT),
OTHER_BANK_48("512431", "宁波银行", "汇通国际卡银联双币卡", 16, CardType.CREDIT),
OTHER_BANK_49("520194", "宁波银行", "汇通国际卡银联双币卡", 16, CardType.CREDIT),
OTHER_BANK_50("622316", "宁波银行", "汇通卡", 16, CardType.DEBIT),
OTHER_BANK_51("622318", "宁波银行", "汇通贷记卡(IC)", 16, CardType.CREDIT),
OTHER_BANK_52("435744", "平安银行", "沃尔玛百分卡", 16, CardType.CREDIT),
OTHER_BANK_53("435745", "平安银行", "沃尔玛百分卡", 16, CardType.CREDIT),
OTHER_BANK_54("998800", "平安银行", "发展借记卡", 16, CardType.DEBIT),
OTHER_BANK_55("526855", "平安银行", "平安银行信用卡", 16, CardType.CREDIT),
OTHER_BANK_56("528020", "平安银行", "平安银行信用卡", 16, CardType.CREDIT),
OTHER_BANK_57("438600", "上海银行", "上海申卡IC", 16, CardType.DEBIT),
OTHER_BANK_58("486466", "上海银行", "申卡贷记卡", 16, CardType.CREDIT),
OTHER_BANK_59("519498", "上海银行", "双币种申卡贷记卡普通卡", 16, CardType.CREDIT),
OTHER_BANK_60("520131", "上海银行", "双币种申卡贷记卡金卡", 16, CardType.CREDIT),
OTHER_BANK_61("402673", "上海银行", "申卡贷记卡", 16, CardType.CREDIT);
BankCardInfo(String bin, String bankName, String cardSeries, int numberLength, CardType cardType) {
this.bin = bin;
this.bankName = bankName;
this.cardSeries = cardSeries;
this.numberLength = numberLength;
this.cardType = cardType;
}
private String bin; // Bank Identification Number
private String bankName;
private String cardSeries;
private int numberLength; // card number length
private CardType cardType;
private static final ImmutableList<BankCardInfo> CARD_INFO_LIST = ImmutableList.copyOf(Arrays.asList(values()));
/**
* 随机获取一个银行卡BIN信息
*/
public static BankCardInfo randomInfo() {
int index = ThreadLocalRandom.current().nextInt(CARD_INFO_LIST.size());
return CARD_INFO_LIST.get(index);
}
public String getBin() {
return bin;
}
public void setBin(String bin) {
this.bin = bin;
}
public String getBankName() {
return bankName;
}
public void setBankName(String bankName) {
this.bankName = bankName;
}
public String getCardSeries() {
return cardSeries;
}
public void setCardSeries(String cardSeries) {
this.cardSeries = cardSeries;
}
public int getNumberLength() {
return numberLength;
}
public void setNumberLength(int numberLength) {
this.numberLength = numberLength;
}
public CardType getCardType() {
return cardType;
}
public void setCardType(CardType cardType) {
this.cardType = cardType;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("bin", bin)
.add("bankName", bankName)
.add("cardSeries", cardSeries)
.add("numberLength", numberLength)
.add("cardType", cardType)
.toString();
}
}
public static class PseudoBankCard {
private String cardNumber;
private BankCardInfo cardInfo;
public PseudoBankCard(String cardNumber, BankCardInfo cardInfo) {
this.cardNumber = cardNumber;
this.cardInfo = cardInfo;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
public BankCardInfo getCardInfo() {
return cardInfo;
}
public void setCardInfo(BankCardInfo cardInfo) {
this.cardInfo = cardInfo;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("cardNumber", cardNumber)
.add("cardInfo", cardInfo)
.toString();
}
}
}
使用前需要有guava和Apache commons-lang3的包,使用方法如下
public static void main(String[] args) {
// 随机获取20个银行卡号
Queue<PseudoBankCard> bankCardNumber = PseudoDataUtil.getBankCardNumber(20);
bankCardNumber.forEach(System.out::println);
}
// 运行一次的结果如下, 供参考:
PseudoBankCard{cardNumber='6226151723904906', cardInfo=BankCardInfo{bin='622615', bankName='中国民生银行', cardSeries='民生借记卡', numberLength=16, cardType=DEBIT}}
PseudoBankCard{cardNumber='4033911585925143', cardInfo=BankCardInfo{bin='403391', bankName='中信银行', cardSeries='中信贷记卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='6225090010399456273', cardInfo=BankCardInfo{bin='622509', bankName='广东省农村信用社联合社', cardSeries='信通白金卡', numberLength=19, cardType=DEBIT}}
PseudoBankCard{cardNumber='94005617086918918', cardInfo=BankCardInfo{bin='940056', bankName='郑州银行', cardSeries='世纪一卡通', numberLength=17, cardType=DEBIT}}
PseudoBankCard{cardNumber='6223353738910356', cardInfo=BankCardInfo{bin='622335', bankName='南宁市商业银行', cardSeries='桂花卡', numberLength=16, cardType=DEBIT}}
PseudoBankCard{cardNumber='4792291727514191', cardInfo=BankCardInfo{bin='479229', bankName='招商银行', cardSeries='招商银行银行信用卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='5280207477817028', cardInfo=BankCardInfo{bin='528020', bankName='平安银行', cardSeries='平安银行信用卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='5324508888750866', cardInfo=BankCardInfo{bin='532450', bankName='中国建设银行', cardSeries='龙卡国际普通卡MASTER', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='6224990007447359172', cardInfo=BankCardInfo{bin='622499', bankName='河北银行', cardSeries='如意借记卡', numberLength=19, cardType=DEBIT}}
PseudoBankCard{cardNumber='5257468237185846', cardInfo=BankCardInfo{bin='525746', bankName='中国银行', cardSeries='长城信用卡', numberLength=16, cardType=SEMI_CREDIT}}
PseudoBankCard{cardNumber='4864930489017520', cardInfo=BankCardInfo{bin='486493', bankName='兴业银行', cardSeries='VISA商务普卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='5410686167406916', cardInfo=BankCardInfo{bin='541068', bankName='中国银行', cardSeries='长城国际卡(美元卡)-个人金卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='6223070017977454132', cardInfo=BankCardInfo{bin='622307', bankName='九江银行', cardSeries='庐山卡', numberLength=19, cardType=DEBIT}}
PseudoBankCard{cardNumber='6225005071266360', cardInfo=BankCardInfo{bin='622500', bankName='浦发银行', cardSeries='东方卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='62225819414214405', cardInfo=BankCardInfo{bin='622258', bankName='交通银行', cardSeries='太平洋人民币借记卡', numberLength=17, cardType=DEBIT}}
PseudoBankCard{cardNumber='5105296227231492', cardInfo=BankCardInfo{bin='510529', bankName='中国工商银行', cardSeries='牡丹万事达国际借记卡', numberLength=16, cardType=CREDIT}}
PseudoBankCard{cardNumber='6222119869732419', cardInfo=BankCardInfo{bin='622211', bankName='中国工商银行', cardSeries='准贷记卡(个普)', numberLength=16, cardType=SEMI_CREDIT}}
PseudoBankCard{cardNumber='6225804654040386', cardInfo=BankCardInfo{bin='622580', bankName='招商银行', cardSeries='一卡通', numberLength=16, cardType=DEBIT}}
PseudoBankCard{cardNumber='6223163878780505', cardInfo=BankCardInfo{bin='622316', bankName='宁波银行', cardSeries='汇通卡', numberLength=16, cardType=DEBIT}}
PseudoBankCard{cardNumber='5201314100018432', cardInfo=BankCardInfo{bin='520131', bankName='上海银行', cardSeries='双币种申卡贷记卡金卡', numberLength=16, cardType=CREDIT}}