aaaaa
This commit is contained in:
parent
fe6d1b5d44
commit
f423f8b57f
155
QUICKSTART.md
Normal file
155
QUICKSTART.md
Normal file
@ -0,0 +1,155 @@
|
||||
# 快速开始指南
|
||||
|
||||
## 🚀 5分钟上手
|
||||
|
||||
### 1. 基本使用
|
||||
|
||||
生成一张银联卡(默认):
|
||||
```bash
|
||||
node src/cli.js card
|
||||
```
|
||||
|
||||
输出:
|
||||
```
|
||||
6228367546245545|08|29|783
|
||||
```
|
||||
|
||||
### 2. 常用命令
|
||||
|
||||
```bash
|
||||
# 生成Visa卡
|
||||
node src/cli.js card -t visa
|
||||
|
||||
# 批量生成10张银联卡
|
||||
node src/cli.js card -n 10
|
||||
|
||||
# JSON格式输出
|
||||
node src/cli.js card -f json
|
||||
|
||||
# 美化格式
|
||||
node src/cli.js card -f pretty
|
||||
|
||||
# 查看支持的卡类型
|
||||
node src/cli.js card list-types
|
||||
|
||||
# 查看帮助
|
||||
node src/cli.js --help
|
||||
```
|
||||
|
||||
### 3. 便捷脚本
|
||||
|
||||
也可以使用 npm scripts:
|
||||
|
||||
```bash
|
||||
# 生成一张卡
|
||||
npm run card
|
||||
|
||||
# 使用自定义参数(需要加 -- )
|
||||
npm run card -- -t visa -n 5
|
||||
```
|
||||
|
||||
### 4. 批量生成并保存
|
||||
|
||||
```bash
|
||||
# 生成100张银联卡并保存
|
||||
node src/cli.js card -n 100 > cards.txt
|
||||
|
||||
# 生成CSV格式
|
||||
node src/cli.js card -n 50 -f csv > cards.csv
|
||||
|
||||
# 生成JSON格式(每行一个JSON对象)
|
||||
node src/cli.js card -n 20 -f json > cards.json
|
||||
```
|
||||
|
||||
### 5. 编程使用
|
||||
|
||||
创建脚本 `test.js`:
|
||||
|
||||
```javascript
|
||||
const CardGenerator = require('./src/tools/card-generator/generator');
|
||||
const generator = new CardGenerator();
|
||||
|
||||
// 生成单张卡
|
||||
const card = generator.generate('unionpay');
|
||||
console.log(card);
|
||||
|
||||
// 批量生成
|
||||
const cards = generator.generateBatch(10, 'visa');
|
||||
console.log(cards);
|
||||
```
|
||||
|
||||
运行:
|
||||
```bash
|
||||
node test.js
|
||||
```
|
||||
|
||||
## 📊 输出格式对比
|
||||
|
||||
| 格式 | 命令 | 输出示例 |
|
||||
|------|------|---------|
|
||||
| **Pipe** | `node src/cli.js card` | `6228367546245545\|08\|29\|783` |
|
||||
| **JSON** | `node src/cli.js card -f json` | `{"number":"6228367546245545","month":"08","year":"29","cvv":"783","type":"中国银联 (UnionPay)"}` |
|
||||
| **CSV** | `node src/cli.js card -f csv` | `6228367546245545,08,29,783` |
|
||||
| **Pretty** | `node src/cli.js card -f pretty` | 多行美化格式 |
|
||||
|
||||
## 🎯 常见使用场景
|
||||
|
||||
### 测试场景1: 支付系统测试
|
||||
|
||||
```bash
|
||||
# 生成各种卡类型用于测试
|
||||
node src/cli.js card -t visa -n 5
|
||||
node src/cli.js card -t mastercard -n 5
|
||||
node src/cli.js card -t amex -n 5
|
||||
```
|
||||
|
||||
### 测试场景2: 前端表单测试
|
||||
|
||||
```bash
|
||||
# 生成JSON格式用于mock数据
|
||||
node src/cli.js card -n 20 -f json > mock-cards.json
|
||||
```
|
||||
|
||||
### 测试场景3: 数据库填充
|
||||
|
||||
```bash
|
||||
# 生成CSV格式导入数据库
|
||||
node src/cli.js card -t unionpay -n 1000 -f csv > import.csv
|
||||
```
|
||||
|
||||
## 🔧 运行示例代码
|
||||
|
||||
查看完整示例:
|
||||
```bash
|
||||
node examples/basic-usage.js
|
||||
```
|
||||
|
||||
## ⚡ 性能提示
|
||||
|
||||
- 单次生成推荐不超过 10000 张卡
|
||||
- 大批量生成建议分批进行
|
||||
- 使用 pipe 格式性能最优
|
||||
|
||||
## ❓ 遇到问题?
|
||||
|
||||
1. 查看完整文档:`README.md`
|
||||
2. 查看工具文档:`docs/tools/card-generator.md`
|
||||
3. 运行示例:`node examples/basic-usage.js`
|
||||
|
||||
## 📝 输出格式说明
|
||||
|
||||
**Pipe格式** (默认):`卡号|月|年|CVV`
|
||||
- 适合:文本处理、批量导入
|
||||
- 分隔符:`|`
|
||||
|
||||
**JSON格式**:完整JSON对象
|
||||
- 适合:API测试、前端mock
|
||||
- 包含:卡号、有效期、CVV、卡类型
|
||||
|
||||
**CSV格式**:逗号分隔
|
||||
- 适合:Excel、数据库导入
|
||||
- 分隔符:`,`
|
||||
|
||||
**Pretty格式**:美化显示
|
||||
- 适合:人工阅读、展示
|
||||
- 多行格式化输出
|
||||
98
analyze-pattern.js
Normal file
98
analyze-pattern.js
Normal file
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 分析原始卡号规律
|
||||
*/
|
||||
|
||||
const { luhnCheck } = require('./src/shared/utils');
|
||||
|
||||
// 原始样本数据
|
||||
const samples = [
|
||||
'6228367546781457|11|27|792',
|
||||
'6228367542738949|06|28|510',
|
||||
'6228367542602400|09|28|574',
|
||||
'6228367548575105|06|27|838',
|
||||
'6228367546496080|09|26|918',
|
||||
'6228367540057649|10|26|244',
|
||||
'6228367549574719|04|26|751',
|
||||
'6228367548435128|11|28|897',
|
||||
'6228367542797374|01|26|837',
|
||||
'6228367545956423|10|30|516',
|
||||
'6228367547237848|08|30|391',
|
||||
'6228367540385107|10|27|364',
|
||||
'6228367544252006|03|27|342',
|
||||
'6228367547562054|12|29|870'
|
||||
];
|
||||
|
||||
console.log('=== 原始卡号规律分析 ===\n');
|
||||
|
||||
// 解析数据
|
||||
const cards = samples.map(line => {
|
||||
const [number, month, year, cvv] = line.split('|');
|
||||
return { number, month, year, cvv };
|
||||
});
|
||||
|
||||
// 1. 分析卡号结构
|
||||
console.log('1. 卡号结构分析:');
|
||||
console.log(` 总数量: ${cards.length}`);
|
||||
console.log(` 卡号长度: ${cards[0].number.length} 位`);
|
||||
|
||||
// 检查前缀
|
||||
const prefixes = cards.map(c => c.number.substring(0, 9));
|
||||
const uniquePrefixes = [...new Set(prefixes)];
|
||||
console.log(` 共同前缀: ${uniquePrefixes[0]}`);
|
||||
console.log(` 前缀一致性: ${uniquePrefixes.length === 1 ? '✓ 是' : '✗ 否'}`);
|
||||
|
||||
// 2. 检查Luhn算法
|
||||
console.log('\n2. Luhn算法校验:');
|
||||
let luhnValid = 0;
|
||||
cards.forEach((card, i) => {
|
||||
const isValid = luhnCheck(card.number);
|
||||
if (isValid) luhnValid++;
|
||||
console.log(` 卡${i + 1}: ${card.number} - ${isValid ? '✓ 通过' : '✗ 不通过'}`);
|
||||
});
|
||||
console.log(` 总结: ${luhnValid}/${cards.length} 通过Luhn校验`);
|
||||
|
||||
// 3. 分析有效期
|
||||
console.log('\n3. 有效期分析:');
|
||||
const months = cards.map(c => parseInt(c.month));
|
||||
const years = cards.map(c => parseInt(c.year));
|
||||
console.log(` 月份范围: ${Math.min(...months)} - ${Math.max(...months)}`);
|
||||
console.log(` 年份范围: ${Math.min(...years)} - ${Math.max(...years)}`);
|
||||
|
||||
// 4. 分析CVV
|
||||
console.log('\n4. CVV分析:');
|
||||
const cvvs = cards.map(c => parseInt(c.cvv));
|
||||
console.log(` CVV长度: ${cards[0].cvv.length} 位`);
|
||||
console.log(` CVV范围: ${Math.min(...cvvs)} - ${Math.max(...cvvs)}`);
|
||||
|
||||
// 5. 分析后7位数字
|
||||
console.log('\n5. 后7位数字分析:');
|
||||
const suffixes = cards.map(c => c.number.substring(9));
|
||||
console.log(` 示例后7位:`);
|
||||
suffixes.slice(0, 5).forEach((suffix, i) => {
|
||||
console.log(` ${i + 1}. ${suffix}`);
|
||||
});
|
||||
|
||||
// 6. 检查是否有数字模式
|
||||
console.log('\n6. 数字分布分析:');
|
||||
const allDigits = suffixes.join('').split('').map(d => parseInt(d));
|
||||
const digitCounts = {};
|
||||
for (let i = 0; i <= 9; i++) {
|
||||
digitCounts[i] = allDigits.filter(d => d === i).length;
|
||||
}
|
||||
console.log(' 各数字出现次数:');
|
||||
for (let i = 0; i <= 9; i++) {
|
||||
const bar = '█'.repeat(Math.floor(digitCounts[i] / 2));
|
||||
console.log(` ${i}: ${bar} (${digitCounts[i]})`);
|
||||
}
|
||||
|
||||
console.log('\n=== 结论 ===');
|
||||
if (luhnValid === cards.length) {
|
||||
console.log('✓ 所有卡号都通过Luhn算法校验');
|
||||
console.log('✓ 建议: 启用Luhn算法生成');
|
||||
} else if (luhnValid === 0) {
|
||||
console.log('✗ 没有卡号通过Luhn算法校验');
|
||||
console.log('✓ 建议: 使用纯随机生成(当前实现)');
|
||||
} else {
|
||||
console.log('⚠ 部分卡号通过Luhn算法校验');
|
||||
console.log('⚠ 需要进一步分析规律');
|
||||
}
|
||||
54
final-verification.js
Normal file
54
final-verification.js
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 最终验证 - 确认生成的卡号符合所有规律
|
||||
*/
|
||||
|
||||
const { luhnCheck } = require('./src/shared/utils');
|
||||
|
||||
// 刚才生成的5张卡
|
||||
const newCards = [
|
||||
'6228367543886341|02|28|859',
|
||||
'6228367547515052|03|26|649',
|
||||
'6228367546095387|07|30|930',
|
||||
'6228367544299692|04|30|852',
|
||||
'6228367546840634|01|26|197'
|
||||
];
|
||||
|
||||
console.log('=== 最终验证 ===\n');
|
||||
console.log('验证新生成的5张卡:\n');
|
||||
|
||||
let allValid = true;
|
||||
newCards.forEach((cardStr, index) => {
|
||||
const [number, month, year, cvv] = cardStr.split('|');
|
||||
const isValid = luhnCheck(number);
|
||||
|
||||
// 检查各项规律
|
||||
const prefixOk = number.startsWith('622836754');
|
||||
const lengthOk = number.length === 16;
|
||||
const monthOk = parseInt(month) >= 1 && parseInt(month) <= 12;
|
||||
const yearOk = parseInt(year) >= 26 && parseInt(year) <= 30;
|
||||
const cvvOk = cvv.length === 3;
|
||||
|
||||
const allChecks = prefixOk && lengthOk && monthOk && yearOk && cvvOk && isValid;
|
||||
allValid = allValid && allChecks;
|
||||
|
||||
console.log(`卡 ${index + 1}: ${cardStr}`);
|
||||
console.log(` ├─ 前缀 622836754: ${prefixOk ? '✓' : '✗'}`);
|
||||
console.log(` ├─ 长度 16位: ${lengthOk ? '✓' : '✗'}`);
|
||||
console.log(` ├─ 月份 01-12: ${monthOk ? '✓' : '✗'}`);
|
||||
console.log(` ├─ 年份 26-30: ${yearOk ? '✓' : '✗'}`);
|
||||
console.log(` ├─ CVV 3位: ${cvvOk ? '✓' : '✗'}`);
|
||||
console.log(` └─ Luhn校验: ${isValid ? '✓' : '✗'}\n`);
|
||||
});
|
||||
|
||||
console.log('=== 结论 ===');
|
||||
if (allValid) {
|
||||
console.log('✓ 所有卡号完全符合规律!');
|
||||
console.log('✓ 工具已正确实现,可以使用!\n');
|
||||
|
||||
console.log('推荐测试卡号(任选一张):\n');
|
||||
newCards.forEach((card, i) => {
|
||||
console.log(`${i + 1}. ${card}`);
|
||||
});
|
||||
} else {
|
||||
console.log('✗ 存在不符合规律的卡号,需要修复');
|
||||
}
|
||||
@ -9,7 +9,7 @@ const CARD_TYPES = {
|
||||
prefix: '622836754',
|
||||
length: 16,
|
||||
cvvLength: 3,
|
||||
useLuhn: false // 可选:是否使用Luhn算法
|
||||
useLuhn: true // 使用Luhn算法校验
|
||||
},
|
||||
visa: {
|
||||
name: 'Visa',
|
||||
|
||||
48
verify-generation.js
Normal file
48
verify-generation.js
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 验证生成的卡号是否符合规律
|
||||
*/
|
||||
|
||||
const CardGenerator = require('./src/tools/card-generator/generator');
|
||||
const Formatter = require('./src/tools/card-generator/formatter');
|
||||
const { luhnCheck } = require('./src/shared/utils');
|
||||
|
||||
const generator = new CardGenerator();
|
||||
const formatter = new Formatter();
|
||||
|
||||
console.log('=== 生成卡号验证 ===\n');
|
||||
|
||||
// 生成10张银联卡
|
||||
console.log('生成10张银联卡进行验证:\n');
|
||||
|
||||
const cards = generator.generateBatch(10, 'unionpay');
|
||||
|
||||
cards.forEach((card, index) => {
|
||||
const isValid = luhnCheck(card.number);
|
||||
const status = isValid ? '✓' : '✗';
|
||||
const formatted = formatter.format(card, 'pipe');
|
||||
console.log(`${index + 1}. ${formatted} ${status}`);
|
||||
});
|
||||
|
||||
console.log('\n=== 验证结果 ===');
|
||||
const validCount = cards.filter(card => luhnCheck(card.number)).length;
|
||||
console.log(`Luhn校验: ${validCount}/${cards.length} 通过`);
|
||||
|
||||
if (validCount === cards.length) {
|
||||
console.log('✓ 所有卡号都通过Luhn校验,符合规律!');
|
||||
console.log('\n=== 提供测试卡号 ===');
|
||||
const testCard = cards[0];
|
||||
console.log('\n请使用以下卡号进行测试:');
|
||||
console.log(`\n${formatter.format(testCard, 'pipe')}\n`);
|
||||
console.log('详细信息:');
|
||||
console.log(formatter.format(testCard, 'pretty'));
|
||||
} else {
|
||||
console.log('✗ 部分卡号未通过校验,需要修复');
|
||||
}
|
||||
|
||||
// 对比格式
|
||||
console.log('\n=== 格式对比 ===');
|
||||
console.log('原始样本格式:');
|
||||
console.log(' 6228367546781457|11|27|792');
|
||||
console.log('\n生成的卡号格式:');
|
||||
console.log(` ${formatter.format(cards[0], 'pipe')}`);
|
||||
console.log('\n格式一致性: ✓');
|
||||
Loading…
Reference in New Issue
Block a user