driver_audio.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2017 Eric Zhou. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package base64Captcha
  5. //DriverAudio captcha config for captcha-engine-audio.
  6. type DriverAudio struct {
  7. // Length Default number of digits in captcha solution.
  8. Length int
  9. // Language possible values for lang are "en", "ja", "ru", "zh".
  10. Language string
  11. }
  12. //DefaultDriverAudio is a default audio driver
  13. var DefaultDriverAudio = NewDriverAudio(6, "en")
  14. //NewDriverAudio creates a driver of audio
  15. func NewDriverAudio(length int, language string) *DriverAudio {
  16. return &DriverAudio{Length: length, Language: language}
  17. }
  18. //DrawCaptcha creates audio captcha item
  19. func (d *DriverAudio) DrawCaptcha(content string) (item Item, err error) {
  20. digits := stringToFakeByte(content)
  21. audio := newAudio("", digits, d.Language)
  22. return audio, nil
  23. }
  24. //GenerateIdQuestionAnswer creates id,captcha content and answer
  25. func (d *DriverAudio) GenerateIdQuestionAnswer() (id, q, a string) {
  26. id = RandomId()
  27. digits := randomDigits(d.Length)
  28. a = parseDigitsToString(digits)
  29. return id, a, a
  30. }