v2
This commit is contained in:
36
internal/erpserver/biz/v1/common/captcha.go
Normal file
36
internal/erpserver/biz/v1/common/captcha.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/mojocn/base64Captcha"
|
||||
)
|
||||
|
||||
// CaptchaBiz 定义处理验证码请求所需的方法.
|
||||
type CaptchaBiz interface {
|
||||
Generate(height int, width int, length int, maxSkew float64, dotCount int) (id, b64s, answer string, err error)
|
||||
Verify(id, answer string, clear bool) bool
|
||||
}
|
||||
|
||||
// captchaBiz 是 CaptchaBiz 接口的实现.
|
||||
type captchaBiz struct{}
|
||||
|
||||
// 确保 captchaBiz 实现了 CaptchaBiz 接口.
|
||||
var _ CaptchaBiz = (*captchaBiz)(nil)
|
||||
|
||||
func NewCaptcha() *captchaBiz {
|
||||
return &captchaBiz{}
|
||||
}
|
||||
|
||||
var captchaStore base64Captcha.Store = base64Captcha.DefaultMemStore
|
||||
|
||||
func (b *captchaBiz) Generate(height int, width int, length int, maxSkew float64, dotCount int) (id, b64s, answer string, err error) {
|
||||
driver := base64Captcha.NewDriverDigit(height, width, length, maxSkew, dotCount)
|
||||
// driver := base64Captcha.NewDriverString(config.File.Captcha.ImgHeight,
|
||||
// config.File.Captcha.ImgWidth,
|
||||
// 6, 1, keyLong, source, nil, nil, nil)
|
||||
cp := base64Captcha.NewCaptcha(driver, captchaStore)
|
||||
return cp.Generate()
|
||||
}
|
||||
|
||||
func (b *captchaBiz) Verify(id, answer string, clear bool) bool {
|
||||
return captchaStore.Verify(id, answer, clear)
|
||||
}
|
||||
17
internal/erpserver/biz/v1/common/common.go
Normal file
17
internal/erpserver/biz/v1/common/common.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package common
|
||||
|
||||
type CommonBiz interface {
|
||||
CaptchaBiz() CaptchaBiz
|
||||
}
|
||||
|
||||
type commonBiz struct{}
|
||||
|
||||
var _ CommonBiz = (*commonBiz)(nil)
|
||||
|
||||
func New() *commonBiz {
|
||||
return &commonBiz{}
|
||||
}
|
||||
|
||||
func (b *commonBiz) CaptchaBiz() CaptchaBiz {
|
||||
return NewCaptcha()
|
||||
}
|
||||
Reference in New Issue
Block a user