base64Captcha
介绍
可以生成多种验证码的工具,通常用于人机验证环节,并且干扰度以及难度都是可以通过配置可控的。
- 数字验证码

- 算术(加减乘除)验证码

- 语音验证码(这个很厉害,还支持国际化)

下载.wav使用
关于使用方法github里很详细,这里再简单啰嗦下。
我们就可以看到go get -u github.com/mojocn/base64Captchacd $GOPATH/src/github.com/mojocn/base64Captcha/_examplesgo run main.goGo to http://localhost:8777

小症结
- 通过源码我们看到它生成的验证码保存在内部的
memoryStore,在分布式环境下无法实现数据共享,假设我们现在想把结果保存在redis。 - 如果接口以
base64返回验证码,这将大出1/3的体积,我们直降将二进制数据流返回前端,这里采用gin的web框架,其他大同小异。
它也带了demo来解决以上问题 $GOPATH/src/github.com/mojocn/base64Captcha/_examples_redis
我们这里也给出一个demo
package handlersimport ("github.com/gin-gonic/gin""github.com/mojocn/base64Captcha")func captcha(c *gin.Context) {conf := base64Captcha.ConfigCharacter{Height: 55,Width: 240,IsShowHollowLine: true,IsShowNoiseDot: true,IsShowNoiseText: false,IsShowSineLine: false,IsShowSlimeLine: true,IsUseSimpleFont: true,Mode: 2,BgColor: &color.RGBA{R:45,G:95,B:70,A:105,},}char := base64Captcha.EngineCharCreate(conf)var captchaInstance base64Captcha.CaptchaInterface = charbinaryData := captchaInstance.BinaryEncoding() // 二进制// redisStore codeing//fmt.Println("问题:",char.Content,"答案:",char.VerifyValue)c.Data(200,"image/GIF",binaryData)}
Go Captcha
介绍
点击图片的验证码
