You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
package cc.bnblogs.springsecurity.validate.imagecode; |
|
|
|
import lombok.Data; |
|
|
|
import java.awt.image.BufferedImage; |
|
import java.time.LocalDateTime; |
|
|
|
@Data |
|
public class ImageCode { |
|
|
|
private BufferedImage image; // 图片 |
|
|
|
private String code; // 验证码 |
|
|
|
private LocalDateTime expireTime; // 过期时间 |
|
|
|
/** |
|
* 生成指定过期时间秒数的验证码 |
|
* @param image |
|
* @param code |
|
* @param expireIn |
|
*/ |
|
public ImageCode(BufferedImage image, String code, int expireIn) { |
|
this.image = image; |
|
this.code = code; |
|
this.expireTime = LocalDateTime.now().plusSeconds(expireIn); |
|
} |
|
|
|
/** |
|
* 过期时间为LocalDateTime类型 |
|
* @param image |
|
* @param code |
|
* @param expireTime |
|
*/ |
|
|
|
public ImageCode(BufferedImage image, String code, LocalDateTime expireTime) { |
|
this.image = image; |
|
this.code = code; |
|
this.expireTime = expireTime; |
|
} |
|
|
|
/** |
|
* 验证码是否过期 |
|
* @return |
|
*/ |
|
public boolean isExpire() { |
|
return LocalDateTime.now().isAfter(expireTime); |
|
} |
|
} |