verifyCode.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Package service
  2. /**
  3. * @ File: verifyCode
  4. * @ Date: 2021/5/12 10:15
  5. * @ Author: JYQ
  6. * @ Description: 图片验证码相关
  7. */
  8. package service
  9. import (
  10. "sportfitness/base/assembly/base/repository/redis"
  11. "sportfitness/base/errors"
  12. "github.com/mojocn/base64Captcha"
  13. )
  14. type VerifyCode struct {
  15. base
  16. }
  17. func (VerifyCode) GenImage(height, width int) (id, pic string) {
  18. if height == 0 {
  19. height = 80
  20. }
  21. if width == 0 {
  22. width = 240
  23. }
  24. if height < 80 || width < 80 {
  25. panic(errors.ParamError("height or width", "小于80"))
  26. }
  27. captcha := base64Captcha.NewCaptcha(
  28. base64Captcha.NewDriverDigit(
  29. height,
  30. width,
  31. 4,
  32. 0.7,
  33. 20,
  34. ),
  35. redis.CaptchaStore{})
  36. id, pic, err := captcha.Generate()
  37. if err != nil {
  38. panic(err)
  39. }
  40. return
  41. }
  42. //
  43. //func (v VerifyCode) GetPhoneVFCode(sysToken, account, ip, code, templateCode string, verifyType im.VerifyType, expireDuration time.Duration) {
  44. // sysId := model.SysInfoThisId
  45. // if sysToken != "" {
  46. // sysId = v.getSysIdBySysToken(sysToken)
  47. // }
  48. // now := time.Now()
  49. // vf := &model.VerifyCode{
  50. // SysId: sysId,
  51. // Account: account,
  52. // SendType: model.VFCodeTypePhone,
  53. // CodeType: verifyType,
  54. // Code: code,
  55. // Ip: ip,
  56. // CreateAt: now,
  57. // ExpireAt: now.Add(expireDuration),
  58. // }
  59. //
  60. // postgre.VerifyCode{}.Create(vf)
  61. // http.PhoneCode{}.SendCode(vf, templateCode)
  62. //}
  63. //
  64. //func (v VerifyCode) CheckPhoneVFCode(sysToken, account, code string, verifyType im.VerifyType) {
  65. // sysId := model.SysInfoThisId
  66. // if sysToken != "" {
  67. // sysId = v.getSysIdBySysToken(sysToken)
  68. // }
  69. //
  70. // vf := &model.VerifyCode{
  71. // SysId: sysId,
  72. // Account: account,
  73. // SendType: model.VFCodeTypePhone,
  74. // CodeType: verifyType,
  75. // Code: code,
  76. // }
  77. //
  78. // postgre.VerifyCode{}.Check(vf)
  79. //}