|
@@ -10,6 +10,7 @@ import (
|
|
"regexp"
|
|
"regexp"
|
|
"sort"
|
|
"sort"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
@@ -146,12 +147,12 @@ var (
|
|
{
|
|
{
|
|
"3",
|
|
"3",
|
|
2,
|
|
2,
|
|
- 3 * 60,
|
|
|
|
|
|
+ 3 * 60 * 60,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"7",
|
|
"7",
|
|
3,
|
|
3,
|
|
- 7 * 60,
|
|
|
|
|
|
+ 7 * 60 * 60,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"2h",
|
|
"2h",
|
|
@@ -163,6 +164,7 @@ var (
|
|
smsIpKey = "sms_ip_%s_%s"
|
|
smsIpKey = "sms_ip_%s_%s"
|
|
smsPhoneKey = "sms_phone_%s_%s"
|
|
smsPhoneKey = "sms_phone_%s_%s"
|
|
smsCacheCode = "other"
|
|
smsCacheCode = "other"
|
|
|
|
+ smsLock = &sync.Mutex{}
|
|
)
|
|
)
|
|
|
|
|
|
func SmsStrategy(keys ...string) (abnormalKey []string) {
|
|
func SmsStrategy(keys ...string) (abnormalKey []string) {
|
|
@@ -171,6 +173,7 @@ func SmsStrategy(keys ...string) (abnormalKey []string) {
|
|
cacheKey := fmt.Sprintf(key, s.Day)
|
|
cacheKey := fmt.Sprintf(key, s.Day)
|
|
num := redis.GetInt(smsCacheCode, cacheKey)
|
|
num := redis.GetInt(smsCacheCode, cacheKey)
|
|
ttl := redis.GetTTL(smsCacheCode, cacheKey)
|
|
ttl := redis.GetTTL(smsCacheCode, cacheKey)
|
|
|
|
+ log.Println(cacheKey, "---------", num, "-------", ttl, "---", s.Num)
|
|
if num > s.Num {
|
|
if num > s.Num {
|
|
abnormalKey = append(abnormalKey, cacheKey)
|
|
abnormalKey = append(abnormalKey, cacheKey)
|
|
}
|
|
}
|
|
@@ -184,6 +187,8 @@ func SmsStrategy(keys ...string) (abnormalKey []string) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
func SendSMS(r *http.Request, BaseMysql *mysql.Mysql, address, mobile string, params ...string) (msg string) {
|
|
func SendSMS(r *http.Request, BaseMysql *mysql.Mysql, address, mobile string, params ...string) (msg string) {
|
|
|
|
+ smsLock.Lock()
|
|
|
|
+ defer smsLock.Unlock()
|
|
//异常手机号及ip拦截策略
|
|
//异常手机号及ip拦截策略
|
|
ip := util.GetIp(r)
|
|
ip := util.GetIp(r)
|
|
if strings.Contains(ip, ",") {
|
|
if strings.Contains(ip, ",") {
|
|
@@ -226,7 +231,7 @@ func SendSMS(r *http.Request, BaseMysql *mysql.Mysql, address, mobile string, pa
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}(aks, ip, mobile)
|
|
}(aks, ip, mobile)
|
|
- msg = "当前用户发送短信验证次数超过最大限制"
|
|
|
|
|
|
+ msg = "当前用户发送短信验证次数超过最大限制:" + strings.Join(aks, ",")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
sms.SendSms(address, "01", mobile, params...)
|
|
sms.SendSms(address, "01", mobile, params...)
|