|
|
@@ -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) |
|
|
|