java 随机生成6位由字母和数字组成的验证码

 1     private static  String GetBindNum(){
 2         String[] beforeShuffle = new String[] {
 3                 "0","1", "2", "3", "4", "5", "6", "7", "8", "9", 
 4                 "a","b", "d", "c", "e", "f", "g", "h", "i", "j",
 5                 "0","1", "2", "3", "4", "5", "6", "7", "8", "9", 
 6                 "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", 
 7                 "u", "v","w", "x", "y", "z" };
 8         List list = Arrays.asList(beforeShuffle);
 9         Collections.shuffle(list);
10         StringBuilder sb = new StringBuilder();
11         for (int i = 0; i < list.size(); i++) {
12             sb.append(list.get(i));
13         }
14         String afterShuffle = sb.toString();
15         String result = afterShuffle.substring(3, 9);
16         return result;
17     }

生成的验证码如下:

4czry2 基本够用了,原理就是数字和字符数组,然后用Collections随机排序,再取出子串。

很多时候都是要将这个验证码发到用户手机,

目前我用的这个网址:http://sms.webchinese.cn 

先注册,然后打开 短信API接口,就知道了。测试的时候感觉还是很慢,大概要2分钟左右手机才能收到。

posted on 2014-01-10 12:59  爱上珍珠的贝壳  阅读(2847)  评论(0编辑  收藏  举报

导航