From e267ab21b12d6be0ec019e73ea6166bb3f209950 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 17 Dec 2024 17:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hdl/hdl_login.go | 4 ++++ app/svc/svc_sms.go | 30 ++++++++++++++++++++++++++++++ go.mod | 3 ++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/hdl/hdl_login.go b/app/hdl/hdl_login.go index 5fb80ed..7f50256 100644 --- a/app/hdl/hdl_login.go +++ b/app/hdl/hdl_login.go @@ -81,6 +81,10 @@ func SmsSend(c *gin.Context) { //} err = svc.CommSmsSend(c, req.Mobile, req.Type) if err != nil { + if err.Error() == "请1分钟后再试" { + e.OutErr(c, 400, e.NewErr(400, "请1分钟后再试")) + return + } e.OutErr(c, 400, e.NewErr(400, "发送失败")) return } diff --git a/app/svc/svc_sms.go b/app/svc/svc_sms.go index fa9e77d..653c63d 100644 --- a/app/svc/svc_sms.go +++ b/app/svc/svc_sms.go @@ -2,13 +2,20 @@ package svc import ( "applet/app/e" + "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" "code.fnuoos.com/EggPlanet/egg_system_rules.git/mob" "errors" "fmt" "github.com/gin-gonic/gin" + "math/rand" + "time" ) +func createCaptcha() string { + return fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)) +} + func CommSmsSend(c *gin.Context, mobile, types string) error { smsPlatform := GetSysCfgStr("sms_platform") var err error @@ -18,6 +25,23 @@ func CommSmsSend(c *gin.Context, mobile, types string) error { fmt.Println("短信错误:" + err.Error()) return err } + } else if smsPlatform == "aliyun_own" { + data := AliyunSmsBase(c, types) + captcha := createCaptcha() + // 2、加锁 防止并发提取 + mutexKey := fmt.Sprintf("sms_check:%s", mobile) + withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 60, "NX") + if err != nil { + return e.NewErr(400000, "请1分钟后再试") + } + if withdrawAvailable != "OK" { + return e.NewErr(400000, "请1分钟后再试") + } + err = aliyun.AliyunSendSmsOwn(data["aliyun_sms_id"], data["aliyun_sms_secret"], mobile, data["aliyun_sms_sign_name"], data["aliyun_sms_code"], "{\"code\":\""+captcha+"\"}") + if err != nil { + return e.NewErr(400, "验证码错误,请重试") + } + cache.SetEx("sms:"+mobile, captcha, 300) } else { data := AliyunSmsBase(c, types) //发送短信 @@ -44,6 +68,12 @@ func CommSmsCheck(c *gin.Context, mobile, code string) error { if bools == false { return e.NewErr(400, "验证码错误,请重试") } + } else if smsPlatform == "aliyun_own" { + captcha, _ := cache.GetString("sms:" + mobile) + if captcha != code || code == "" { + return e.NewErr(400, "验证码错误,请重试") + } + cache.Del("sms:" + mobile) } else { data := AliyunSmsBase(c, "") err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], mobile, code) diff --git a/go.mod b/go.mod index 8ea1b6f..9909908 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( require ( code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241216083317-8f7f975c0482 - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241217040418-3640cd7169f0 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241217084154-72a590107d63 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible @@ -62,6 +62,7 @@ require ( github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.10 // indirect github.com/alibabacloud-go/debug v1.0.1 // indirect github.com/alibabacloud-go/dypnsapi-20170525/v2 v2.2.3 // indirect + github.com/alibabacloud-go/dysmsapi-20170525/v4 v4.1.0 // indirect github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect github.com/alibabacloud-go/openapi-util v0.1.0 // indirect github.com/alibabacloud-go/tea v1.2.2 // indirect