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 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
''' 随机银行卡 ''' import copy import json import math import random
import requests
VISA_PREFIX_LIST = [ "4539", "4556", "4916", "4532", "4929", "40240071", "4485", "4716", "4" ]
MASTERCARD_PREFIX_LIST = ["51", "52", "53", "54", "55"]
AMEX_PREFIX_LIST = ["34", "37"]
DISCOVER_PREFIX_LIST = ["6011"]
DINERS_PREFIX_LIST = ["300", "301", "302", "303", "36", "38"]
ENROUTE_PREFIX_LIST = ["2014", "2149"]
JCB_PREFIX_LIST = ["35"]
VOYAGER_PREFIX_LIST = ["8699"]
China_UnionPay_PREFIX_LIST = ["62"]
CUP_PREFIX_LIST = { '622220': '中国工商银行', '622258': '中国交通银行', '622707': '中国建设银行', '622580': '中国招商银行', '622150': '中国邮政储蓄银行', '622273': '中国银行', '623058': '平安银行' } BANK_CODE_LIST = { 'CCB': '中国建设银行', 'ABC': '中国农业银行', 'ICBC': '中国工商银行', 'CDB': '国家开发银行', 'BCCB': '北京市商业银行', 'HSBC': '汇丰银行', 'PBC': '中国人民银行', 'BOC': '中国银行', 'CMBC': '中国民生银行', 'CMB': '招商银行', 'CIB': '兴业银行', 'BCM': '交通银行', 'CEB': '中国光大银行', 'GDB': '广东发展银行', 'SPABANK': '平安银行' } CARD_TYPE_LIST = {'DC': "储蓄卡", 'CC': "信用卡", 'SCC': "准贷记卡", 'PC': "预付费卡"}
def completed_number(ccnumber, length): while len(ccnumber) < (length - 1): digit = str(random.randint(0, 9)) ccnumber = ccnumber + digit sum = 0 pos = 0 reversed_ccnumber = [] reversed_ccnumber.extend(ccnumber) reversed_ccnumber.reverse() while pos < length - 1: odd = int(reversed_ccnumber[pos]) * 2 if odd > 9: odd -= 9 sum += odd if pos != (length - 2): sum += int(reversed_ccnumber[pos + 1]) pos += 2 checkdigit = int(((math.floor(sum / 10) + 1) * 10 - sum) % 10) ccnumber = str(ccnumber) + str(checkdigit) return ccnumber
def get_bank_number(prefixList=None, length=None): if prefixList is None: prefixList = list(CUP_PREFIX_LIST.keys()) if length is None: length = 16 ccnumber = copy.copy(random.choice(prefixList)) ccnumber = '622707' bank_number = completed_number(ccnumber, length) return bank_number
def is_bank_number(bank_number): try: url = 'https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?\ _input_charset=utf-8&cardNo=%s&cardBinCheck=true' % bank_number r = requests.get(url) data = r.text data = json.loads(data) validated = data['validated'] cardType = None bank = None if validated is True: cardType = CARD_TYPE_LIST[data['cardType']] bank = BANK_CODE_LIST[data['bank']] print(cardType, bank) return validated, cardType, bank except Exception as e: if isinstance(bank_number, int): bank_number = str(bank_number) mod10Count = 0 reversed_ccnumber = list(reversed(bank_number))
for i in range(0, len(bank_number) - 1): augend = reversed_ccnumber[i] if ((i + 1) % 2) == 0: productString = str(augend * 2) augend = 0 for j in range(0, len(productString)): augend += int(productString[j]) mod10Count += int(augend) digits = [int(x) for x in reversed(str(bank_number))] check_sum = sum(digits[::2]) + sum( (dig // 10 + dig % 10) for dig in [2 * el for el in digits[1::2]]) print(check_sum, mod10Count) return (mod10Count % 10) == 0
if __name__ == "__main__": bank_number = '6217000010104124329' bank_number = get_bank_number() print(bank_number) print(is_bank_number(bank_number))
|