|
|
@@ -0,0 +1,89 @@
|
|
|
+// Package service
|
|
|
+/**
|
|
|
+ * @ File: verifyCode
|
|
|
+ * @ Date: 2021/5/12 10:15
|
|
|
+ * @ Author: JYQ
|
|
|
+ * @ Description: 图片验证码相关
|
|
|
+ */
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ "sportfitness/base/assembly/base/repository/redis"
|
|
|
+ "sportfitness/base/errors"
|
|
|
+
|
|
|
+ "github.com/mojocn/base64Captcha"
|
|
|
+)
|
|
|
+
|
|
|
+type VerifyCode struct {
|
|
|
+ base
|
|
|
+}
|
|
|
+
|
|
|
+func (VerifyCode) GenImage(height, width int) (id, pic string) {
|
|
|
+ if height == 0 {
|
|
|
+ height = 80
|
|
|
+ }
|
|
|
+
|
|
|
+ if width == 0 {
|
|
|
+ width = 240
|
|
|
+ }
|
|
|
+
|
|
|
+ if height < 80 || width < 80 {
|
|
|
+ panic(errors.ParamError("height or width", "小于80"))
|
|
|
+ }
|
|
|
+
|
|
|
+ captcha := base64Captcha.NewCaptcha(
|
|
|
+ base64Captcha.NewDriverDigit(
|
|
|
+ height,
|
|
|
+ width,
|
|
|
+ 4,
|
|
|
+ 0.7,
|
|
|
+ 20,
|
|
|
+ ),
|
|
|
+ redis.CaptchaStore{})
|
|
|
+
|
|
|
+ id, pic, err := captcha.Generate()
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+//func (v VerifyCode) GetPhoneVFCode(sysToken, account, ip, code, templateCode string, verifyType im.VerifyType, expireDuration time.Duration) {
|
|
|
+// sysId := model.SysInfoThisId
|
|
|
+// if sysToken != "" {
|
|
|
+// sysId = v.getSysIdBySysToken(sysToken)
|
|
|
+// }
|
|
|
+// now := time.Now()
|
|
|
+// vf := &model.VerifyCode{
|
|
|
+// SysId: sysId,
|
|
|
+// Account: account,
|
|
|
+// SendType: model.VFCodeTypePhone,
|
|
|
+// CodeType: verifyType,
|
|
|
+// Code: code,
|
|
|
+// Ip: ip,
|
|
|
+// CreateAt: now,
|
|
|
+// ExpireAt: now.Add(expireDuration),
|
|
|
+// }
|
|
|
+//
|
|
|
+// postgre.VerifyCode{}.Create(vf)
|
|
|
+// http.PhoneCode{}.SendCode(vf, templateCode)
|
|
|
+//}
|
|
|
+//
|
|
|
+//func (v VerifyCode) CheckPhoneVFCode(sysToken, account, code string, verifyType im.VerifyType) {
|
|
|
+// sysId := model.SysInfoThisId
|
|
|
+// if sysToken != "" {
|
|
|
+// sysId = v.getSysIdBySysToken(sysToken)
|
|
|
+// }
|
|
|
+//
|
|
|
+// vf := &model.VerifyCode{
|
|
|
+// SysId: sysId,
|
|
|
+// Account: account,
|
|
|
+// SendType: model.VFCodeTypePhone,
|
|
|
+// CodeType: verifyType,
|
|
|
+// Code: code,
|
|
|
+// }
|
|
|
+//
|
|
|
+// postgre.VerifyCode{}.Check(vf)
|
|
|
+//}
|