package com.rootcloud.asset.utils; import org.apache.commons.lang3.StringUtils; import java.security.SecureRandom; import java.util.Random; /** * 生成验证码 * Created by Administrator on 2017/7/4. */ public class NumberCharProduct { private static final int DEFAULT_LENGTH = 4; private static final char[] DEFAULT_CHARS = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'k', 'u', 'n', 'p', 'r', 'w', 'x', 'y', '2', '3', '4', '5', '6', '7', '8', '9'}; private static final Random RAND = new SecureRandom(); private String text = null; public NumberCharProduct() { } public NumberCharProduct(String text) { this.text = text; } public String getText() { if (StringUtils.isNotBlank(text)) { return text; } String capText = ""; for (int i = 0; i < DEFAULT_LENGTH; ++i) { capText = capText + DEFAULT_CHARS[RAND.nextInt(DEFAULT_CHARS.length)]; } return capText; } public void setText(String text) { this.text = text; } }
生成验证码
最新推荐文章于 2024-06-20 15:06:48 发布