...
代码块 | ||
---|---|---|
| ||
// 自定义实现类,需要实现验证码的生成、存储、发送、校验等逻辑 public class CustomSmsCaptchaCodeService implements ICaptchaCodeService { public boolean sendCaptchaCode(CaptchaCodeSendReq req) { // 具体实现参考产品内 SmartbiSmsCaptchaCodeService.sendCaptchaCode 方法的实现 } public CaptchaCodeValidResp validateCaptchaCode(CaptchaCodeValidReq req) { // 具体实现参考产品内 SmartbiSmsCaptchaCodeService.validateCaptchaCode 方法的实现 } } public class CustomEmailCaptchaCodeService implements AbstractCaptchaCodeService { public boolean sendCaptchaCode(CaptchaCodeSendReq req) { // 具体实现参考产品内 SmartbiEmailCaptchaCodeService.sendCaptchaCode 方法的实现 } public CaptchaCodeValidResp validateCaptchaCode(CaptchaCodeValidReq req) { // 具体实现参考产品内 SmartbiEmailCaptchaCodeService.validateCaptchaCode 方法的实现 } } // 设置自定义实现 UserManagerModule.getInstance().setSmsCaptchaCodeService(new CustomSmsCaptchaCodeService()); UserManagerModule.getInstance().setEmailCaptchaCodeService(new CustomEmailCaptchaCodeService()); |
也可以继承 smartbi.usermanager.service.AbstractCaptchaCodeService 类,该类提供了一些公共方法,例如生成验证码的方法 generateCaptchaCode。
注意:验证码应当限制发送频率、校验次数,避免恶意请求频繁发送验证码造成经济损失、频繁校验验证码导致被枚举。
...