• 银行卡信息生成


    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>银行卡 | 身份证 | 生成</title>
        <script>
            //获取银行卡号不包括LunmCode
            function getBankCardWithoutLunmCode(bank_no) {
                // bank_no 银行代码
                //控制位数. 19位的银行卡 cardinalNumber=12. 16位的银行卡 cardinalNumber=9
                var cardinalNumber = 12;
                var prefix = "";
                switch (bank_no) {
                    case "102":
                        prefix = "622202";
                        break;
                    case "103":
                        prefix = "622848";
                        break;
                    case "105":
                        prefix = "622700";
                        break;
                    case "301":
                        prefix = "622262";
                        break;
                    case "104":
                        prefix = "621661";
                        break;
                    case "303":
                        prefix = "622666";
                        cardinalNumber = 9;
                        break;
                    case "305":
                        prefix = "622622";
                        break;
                    case "306":
                        prefix = "622556";
                        break;
                    case "308":
                        prefix = "622588";
                        cardinalNumber = 9;
                        break;
                    case "410":
                        prefix = "622155";
                        break;
                    case "302":
                        prefix = "622689";
                        break;
                    case "304":
                        prefix = "622630";
                        break;
                    case "309":
                        prefix = "622908";
                        break;
                    case "310":
                        prefix = "621717";
                        break;
                    case "315":
                        prefix = "622323";
                        break;
                    case "316":
                        prefix = "622309";
                        break;
                    default:
                        return '';
                }
    
                //生成不包括Luhm校验码的银行卡号
                var bankCardWithoutLunmCode = prefix;
                for (var j = 0; j < cardinalNumber; j++) {
                    bankCardWithoutLunmCode += Math.floor(Math.random() * 10);
                }
    
                console.log(prefix);
                console.log(bankCardWithoutLunmCode);
    
                return bankCardWithoutLunmCode;
            }
    
    
            // 获取Luhn Code
            function getLuhnCode(bankCardWithoutLunmCode) {
                if (bankCardWithoutLunmCode == '') return '';
                var no = bankCardWithoutLunmCode.split('').reverse().join('');
    
                // 定义奇数/偶数数据
                var addArr = new Array();
                var evenArr = new Array();
    
                // 奇数/偶数数组分开
                for (var i = 0; i < no.length; i++) {
                    if (i % 2 == 0) {
                        addArr[i / 2] = no[i];
                    } else {
                        evenArr[(i - 1) / 2] = no[i];
                    }
                }
    
                //奇数数组内容x2
                // 如果乘以2得到的数字是两位,把这两位相加得到一位数字.
                // 如果相加后的内容时两位数,减去9.
                for (var i = 0; i < addArr.length; i++) {
                    var temp = parseInt(addArr[i]) * 2;
                    if (temp > 9) {
                        temp = parseInt(String(temp).charAt(0)) + parseInt(String(temp).charAt(1));
                        if (temp > 9) {
                            temp = temp - 9;
                        }
                    }
                    addArr[i] = temp;
                }
    
    
                //两个数组合并
                var arr = addArr.concat(evenArr);
                var oddEvenCount = 0;
    
                for (var i = 0; i < arr.length; i++) {
                    oddEvenCount += parseInt(arr[i]);
                }
    
                console.log(oddEvenCount);
    
                //生成Lnhn code
    
                var LuhnCode = oddEvenCount % 10 == 0 ? 0 : (10 - oddEvenCount % 10);
    
                console.log(LuhnCode);
    
                return LuhnCode;
    
            }
    
            function getBankCard(bank_no) {
                var bankCardWithoutLunmCode = getBankCardWithoutLunmCode(bank_no);
                var bankCard = bankCardWithoutLunmCode + getLuhnCode(bankCardWithoutLunmCode) + "";
    
                console.log("银行卡号:", bankCard);
    
                return bankCard;
    
            }
            // 随机生成姓名
            function getName() {
                var familyNames = new Array(
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", "",
                    "", "", "", "", "", "", "", "", "", ""
                );
                var givenNames = new Array(
                    "子璇", "", "国栋", "夫子", "瑞堂", "", "", "", "国贤", "贺祥", "晨涛",
                    "昊轩", "易轩", "益辰", "益帆", "益冉", "瑾春", "瑾昆", "春齐", "", "文昊",
                    "东东", "雄霖", "浩晨", "熙涵", "溶溶", "冰枫", "欣欣", "宜豪", "欣慧", "建政",
                    "美欣", "淑慧", "文轩", "文杰", "欣源", "忠林", "榕润", "欣汝", "慧嘉", "新建",
                    "建林", "亦菲", "", "冰洁", "佳欣", "涵涵", "禹辰", "淳美", "泽惠", "伟洋",
                    "涵越", "润丽", "", "淑华", "晶莹", "凌晶", "苒溪", "雨涵", "嘉怡", "佳毅",
                    "子辰", "佳琪", "紫轩", "瑞辰", "昕蕊", "", "明远", "欣宜", "泽远", "欣怡",
                    "佳怡", "佳惠", "晨茜", "晨璐", "运昊", "汝鑫", "淑君", "晶滢", "润莎", "榕汕",
                    "佳钰", "佳玉", "晓庆", "一鸣", "语晨", "添池", "添昊", "雨泽", "雅晗", "雅涵",
                    "清妍", "诗悦", "嘉乐", "晨涵", "天赫", "玥傲", "佳昊", "天昊", "萌萌", "若萌"
                );
                var i = parseInt(Math.random() * 100);
                var familyName = familyNames[i];
                var j = parseInt(Math.random() * 100);
                var givenName = givenNames[i];
                var name = familyName + givenName;
                console.log("姓名", name);
                return name;
            }
            // 生成随机身份证号
            function getId_no() {
                var coefficientArray = ["7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"]; // 加权因子
                var lastNumberArray = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]; // 校验码
                var address = "420101"; // 住址
                var birthday = "19810101"; // 生日
                var s = Math.floor(Math.random() * 10).toString() + Math.floor(Math.random() * 10).toString() + Math.floor(Math.random() * 10).toString();
                var array = (address + birthday + s).split("");
                var total = 0;
                for (i in array) {
                    total = total + parseInt(array[i]) * parseInt(coefficientArray[i]);
                }
                var lastNumber = lastNumberArray[parseInt(total % 11)];
                var id_no_String = address + birthday + s + lastNumber;
                console.log("身份证", id_no_String);
                return id_no_String;
            }
            window.onload = function() {
                // 获取select的选中项
                var checkedBankNo = document.getElementsByName("bank_no")[0].value;
                // 获取生成卡号的按钮
                var generateBankcard = document.getElementById("generateBankcard");
                generateBankcard.onclick = function() {
                    // 获取卡号文本框
                    var bankcard = document.getElementById("bankcard");
                    // 获取select的选中项
                    var checkedBankNo = document.getElementsByName("bank_no")[0].value;
                    bankcard.value = getBankCard(checkedBankNo);
                }
    
                // 生成身份证号码
                var generateIdentity = document.getElementById("generateIdentity");
    
                generateIdentity.onclick = function() {
                    var identity = document.getElementById("identity");
                    identity.value = getId_no();
                }
    
                // 生成随机姓名
                var generateName = document.getElementById("generateName");
    
                generateName.onclick = function() {
                    var name = document.getElementById("name");
                    name.value = getName();
                }
    
            }
        </script>
    </head>
    
    <body>
        <div id="bankInfo">
            <p>
                <span>选择银行</span>
                <select name="bank_no" id="">
                    <option value="104">中国银行</option>
                    <option value="103">农业银行</option>
                    <option value="102">工商银行</option>
                    <option value="105">建设银行</option>
                    <option value="301">交通银行</option>
                    <option value="100">中国邮政储蓄银行</option>
                    <option value="308">招商银行</option>
                    <option value="310">浦发银行</option>
                    <option value="309">兴业银行</option>
                    <option value="303">光大银行</option>
                    <option value="306">广发银行</option>
                    <!-- <option value="308">平安银行</option> -->
                    <option value="304">华夏银行</option>
                    <option value="305">民生银行</option>
                    <option value="302">中信银行</option>
                    <!-- <option value="308">上海银行</option> -->
                    <!-- <option value="308">鄂尔多斯银行</option> -->
                </select>
                <input id="generateBankcard" type="button" value="生成卡号">
                <input id="bankcard" type="text" placeholder="银行卡号">
            </p>
        </div>
        <div id="identityInfo">
            <p>
                <span>身份证号码</span>
                <input id="generateIdentity" type="button" value="生成身份证号码">
                <input id="identity" type="text" placeholder="随机身份证号码..">
            </p>
        </div>
        <div id="nameInfo">
            <p>
                <span>名字</span>
                <input id="generateName" type="button" value="生成名字">
                <input id="name" type="text" placeholder="随机姓名..">
            </p>
        </div>
    </body>
    
    </html>
  • 相关阅读:
    在UI上使用BackgroundWorker
    洛谷训练新手村之“洛谷的第一个任务”题解
    洛谷训练新手村之“循环!循环!循环!”题解
    洛谷训练新手村之“BOSS战入门综合练习1”题解
    洛谷训练新手村之“过程函数与递归”题解
    洛谷P1720 月落乌啼算钱 题解 斐波那契数列/特征方程求解
    洛谷训练新手村之“顺序与分支”题解
    洛谷训练新手村之“数组”题解
    [转]特征方程
    洛谷训练新手村之“简单字符串”题解
  • 原文地址:https://www.cnblogs.com/vscss/p/8608230.html
Copyright © 2020-2023  润新知