github.com/SupenBysz/gf-admin-community@v0.7.4/sys_controller/captcha.go (about) 1 package sys_controller 2 3 import ( 4 "context" 5 "fmt" 6 "github.com/SupenBysz/gf-admin-community/api_v1" 7 "github.com/SupenBysz/gf-admin-community/api_v1/sys_api" 8 "github.com/SupenBysz/gf-admin-community/sys_service" 9 "github.com/kysion/sms-library/api/sms_api" 10 "github.com/kysion/sms-library/sms_controller" 11 "github.com/kysion/sms-library/sms_global" 12 "github.com/kysion/sms-library/sms_model" 13 ) 14 15 // Captcha 验证码 16 var Captcha = cCaptcha{} 17 18 type cCaptcha struct{} 19 20 // Index 获取默认的图形验证码 21 func (c *cCaptcha) Index(ctx context.Context, _ *sys_api.CaptchaIndexReq) (res *sys_api.CaptchaIndexRes, err error) { 22 err = sys_service.Captcha().MakeCaptcha(ctx) 23 return 24 } 25 26 // SendCaptchaBySms 发送短信验证码 27 func (c *cCaptcha) SendCaptchaBySms(ctx context.Context, req *sys_api.SendCaptchaBySmsReq) (api_v1.BoolRes, error) { 28 //smsType := base_enum.Captcha.Type.New(req.CaptchaType, "") 29 //g.DB().GetCache().Set(ctx, smsType.Description()+"_"+req.Mobile, "666666", time.Minute*5) 30 // 31 //return true, nil 32 33 sendReq := sms_api.SendSmsReq{ 34 CaptchaType: req.CaptchaType, 35 SmsSendMessageReq: sms_model.SmsSendMessageReq{ 36 Phones: []string{req.Mobile}, 37 CaptchaType: req.CaptchaType, 38 }, 39 } 40 41 fmt.Println(sendReq) 42 modules := sms_global.Global.Modules 43 res, err := sms_controller.Sms(modules).SendSms(ctx, &sendReq) 44 45 return res.SmsSendStatus[0].Code == "OK", err 46 } 47 48 // SendCaptchaByMail 发送邮箱验证码 49 func (c *cCaptcha) SendCaptchaByMail(ctx context.Context, req *sys_api.SendCaptchaByMailReq) (api_v1.BoolRes, error) { 50 51 ret, err := sys_service.SysMails().SendCaptcha(ctx, req.Mail, req.CaptchaType) // TODO 加上类型 52 53 return ret == true, err 54 }