第一步 下载第三方组件
go get -u github.com/mojocn/base64Captcha
下载过程中可能出错,主要原因还是go get golang.org/x/image 失败
解决方法:①cd $GOPATH/src/golang.org/x
② git clone https://github.com/golang/image
第二歩 设置CaptchaConfig类
type CaptchaConfig struct {
Id string
CaptchaType string
VerifyValue string
ConfigAudio base64Captcha.ConfigAudio
ConfigCharacter base64Captcha.ConfigCharacter
ConfigDigit base64Captcha.ConfigDigit
}
第三歩 创建CaptchaConfig类实例
var (
captchaConfig *CaptchaConfig
captchaConfigOnce sync.Once
)
// 获取base64验证码基本配置
func GetCaptchaConfig() *CaptchaConfig {
captchaConfigOnce.Do(func() {
captchaConfig = &CaptchaConfig{
Id: "",
CaptchaType: "character",
VerifyValue: "",