中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

苞米豆 — 谷歌驗(yàn)證碼快速啟動(dòng)器 1.1.0 發(fā)布

2018-07-20    來源:oschina

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用

https://gitee.com/baomidou/kaptcha-spring-boot-starter

修復(fù)了一個(gè)重復(fù)校驗(yàn)引起的Np bug

支持了jdk 1.7

簡介

kaptcha-spring-boot-starter 基于 springBoot 和 Google Kaptcha 驗(yàn)證碼組件,支持jdk1.7+,kaptcha-spring-boot-starter可以很方便的集成驗(yàn)證碼到你的系統(tǒng)中。

如何使用

  1. 引入 kaptcha-datasource-spring-boot-starter。

<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>kaptcha-spring-boot-starter</artifactId>
  <version>1.1.0</version>
</dependency>
  1. 在Controller使用Kaptcha。

@RestController
@RequestMapping("/kaptcha")
public class KaptchaController {

  @Autowired
  private Kaptcha kaptcha;

  @GetMapping("/render")
  public void render() {
    kaptcha.render();
  }

  @PostMapping("/valid")
  public void validDefaultTime(@RequestParam String code) {
    //default timeout 900 seconds
    kaptcha.validate(code);
  }

  @PostMapping("/validTime")
  public void validWithTime(@RequestParam String code) {
    kaptcha.validate(code, 60);
  }

}
  1. 發(fā)生錯(cuò)誤會(huì)拋出異常,建議使用全局異常來處理。

KaptchaException  //super Exception

KaptchaIncorrectException

KaptchaNotFoundException

KaptchaTimeoutException

KaptchaRenderException //If something is wrong then Image.write when render.
import com.baomidou.kaptcha.exception.KaptchaException;
import com.baomidou.kaptcha.exception.KaptchaIncorrectException;
import com.baomidou.kaptcha.exception.KaptchaNotFoundException;
import com.baomidou.kaptcha.exception.KaptchaTimeoutException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

  @ExceptionHandler(value = KaptchaException.class)
  public String kaptchaExceptionHandler(KaptchaException kaptchaException) {
    if (kaptchaException instanceof KaptchaIncorrectException) {
      return "驗(yàn)證碼不正確";
    } else if (kaptchaException instanceof KaptchaNotFoundException) {
      return "驗(yàn)證碼未找到";
    } else if (kaptchaException instanceof KaptchaTimeoutException) {
      return "驗(yàn)證碼過期";
    } else {
      return "驗(yàn)證碼渲染失敗";
    }

  }

}
  1. 自定義驗(yàn)證碼參數(shù),以下為默認(rèn)配置。

kaptcha:
  height: 50
  width: 200
  content:
    length: 4
    source: abcdefghjklmnopqrstuvwxyz23456789
    space: 2
  font:
    color: black
    name: Arial
    size: 40
  background-color:
    from: lightGray
    to: white
  border:
    enabled: true
    color: black
    thickness: 1

標(biāo)簽: Google

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:NAS4Free 更名為 XigmaNAS,并發(fā)布 11.2.0.4.5762 版本

下一篇:Jboot v1.6.3 發(fā)布,修復(fù)分布式 session 等若干問題