31 lines
		
	
	
		
			848 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			848 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package common
 | |
| 
 | |
| import (
 | |
| 	v1 "management/internal/erpserver/service/v1"
 | |
| 
 | |
| 	"github.com/mojocn/base64Captcha"
 | |
| )
 | |
| 
 | |
| type captchaService struct {
 | |
| 	store base64Captcha.Store
 | |
| }
 | |
| 
 | |
| func NewCaptchaService() v1.CaptchaService {
 | |
| 	return &captchaService{
 | |
| 		store: base64Captcha.DefaultMemStore,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (b *captchaService) 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, b.store)
 | |
| 	return cp.Generate()
 | |
| }
 | |
| 
 | |
| func (b *captchaService) Verify(id, answer string, clear bool) bool {
 | |
| 	return b.store.Verify(id, answer, clear)
 | |
| }
 |