效果:
逻辑:生成数字随机数,再改为中文表示,返给前端。人为输入阿拉伯数字。(后端缓存中存入用户信息和随机数。做校验。)
主要测试code:
Random rm = new Random(); String strcode = Integer.toString(rm.nextInt(900000) + 100000); System.out.println("生成的随机数是: "+strcode); String[] code_ch_arr = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "零"}; String code_ch = ""; for (int x = 0; x < strcode.length(); x++) { switch (String.valueOf(strcode.charAt(x))) { case "1": code_ch += code_ch_arr[0]; break; case "2": code_ch += code_ch_arr[1]; break; case "3": code_ch += code_ch_arr[2]; break; case "4": code_ch += code_ch_arr[3]; break; case "5": code_ch += code_ch_arr[4]; break; case "6": code_ch += code_ch_arr[5]; break; case "7": code_ch += code_ch_arr[6]; break; case "8": code_ch += code_ch_arr[7]; break; case "9": code_ch += code_ch_arr[8]; break; case "0": code_ch += code_ch_arr[9]; break; default: break; } } System.out.println("中文表示的随机数是: " + code_ch);
标签:case,arr,code,验证码,break,ch,图形,解析 From: https://www.cnblogs.com/liuguiqing/p/17722366.html