|
@@ -25,7 +25,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)
|
|
- jylog.Info(cacheKey, "-----num----", num, "----ttl---", ttl, "--s.Num--", s.Num)
|
|
|
|
|
|
+ jylog.Info(cacheKey, "#num:", num, "#ttl:", ttl, "#s.Num:", s.Num)
|
|
if num >= s.Num {
|
|
if num >= s.Num {
|
|
abnormalKey = append(abnormalKey, cacheKey)
|
|
abnormalKey = append(abnormalKey, cacheKey)
|
|
}
|
|
}
|
|
@@ -46,6 +46,7 @@ func Verify(reqData *ReqData) bool {
|
|
var keys = []string{fmt.Sprintf(smsPhoneKey, "%s", reqData.Phones)}
|
|
var keys = []string{fmt.Sprintf(smsPhoneKey, "%s", reqData.Phones)}
|
|
if ips := strings.Split(reqData.Ip, ","); len(ips) > 0 {
|
|
if ips := strings.Split(reqData.Ip, ","); len(ips) > 0 {
|
|
for _, ip := range ips {
|
|
for _, ip := range ips {
|
|
|
|
+ ip = strings.TrimSpace(ip)
|
|
ipHead := strings.Split(ip, ".")[0]
|
|
ipHead := strings.Split(ip, ".")[0]
|
|
if config.SmsIpMap[ipHead] {
|
|
if config.SmsIpMap[ipHead] {
|
|
continue
|
|
continue
|
|
@@ -59,39 +60,59 @@ func Verify(reqData *ReqData) bool {
|
|
var (
|
|
var (
|
|
ipState, phoneState int
|
|
ipState, phoneState int
|
|
now = time.Now()
|
|
now = time.Now()
|
|
- ipE, _ = redis.Exists(smsCacheCode, fmt.Sprintf(smsExistKey, ip))
|
|
|
|
- phoneE, _ = redis.Exists(smsCacheCode, fmt.Sprintf(smsExistKey, mobile))
|
|
|
|
)
|
|
)
|
|
for _, v := range aks {
|
|
for _, v := range aks {
|
|
if strings.Contains(v, "sms_ip") {
|
|
if strings.Contains(v, "sms_ip") {
|
|
- ipState = 1
|
|
|
|
- redis.Put(smsCacheCode, fmt.Sprintf(smsExistKey, ip), 1, 30*24*60*60)
|
|
|
|
|
|
+ ipState = ipState + 1
|
|
}
|
|
}
|
|
if strings.Contains(v, "sms_phone") {
|
|
if strings.Contains(v, "sms_phone") {
|
|
- phoneState = 1
|
|
|
|
- redis.Put(smsCacheCode, fmt.Sprintf(smsExistKey, mobile), 1, 30*24*60*60)
|
|
|
|
|
|
+ phoneState = phoneState + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if !ipE {
|
|
|
|
- if id := config.BaseMysql.Insert("useranaly.sms_black_ip", map[string]interface{}{
|
|
|
|
|
|
+ if ipState > 0 {
|
|
|
|
+ ipQuery := map[string]interface{}{
|
|
|
|
+ "ip": ip,
|
|
|
|
+ }
|
|
|
|
+ ipData := map[string]interface{}{
|
|
"ip": ip,
|
|
"ip": ip,
|
|
"ip_state": ipState,
|
|
"ip_state": ipState,
|
|
"date": date.FormatDate(&now, date.Date_Full_Layout),
|
|
"date": date.FormatDate(&now, date.Date_Full_Layout),
|
|
- }); id <= 0 {
|
|
|
|
- jylog.Info("sms_black_ip 信息保存异常:", mobile, ip)
|
|
|
|
|
|
+ }
|
|
|
|
+ tableName := "useranaly.sms_black_ip"
|
|
|
|
+ if ipD := config.BaseMysql.FindOne(tableName, ipQuery, "ip,ip_state", "date desc"); ipD == nil {
|
|
|
|
+ if id := config.BaseMysql.Insert(tableName, ipData); id <= 0 {
|
|
|
|
+ jylog.Info("sms_black_ip 信息保存异常:", mobile, ip)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ delete(ipData, "ip")
|
|
|
|
+ if ok := config.BaseMysql.Update(tableName, ipQuery, ipData); !ok {
|
|
|
|
+ jylog.Info("sms_black_ip 信息更新异常:", mobile, ip)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if !phoneE {
|
|
|
|
- if id := config.BaseMysql.Insert("useranaly.sms_black_phone", map[string]interface{}{
|
|
|
|
|
|
+ if phoneState > 0 {
|
|
|
|
+ phoneQuery := map[string]interface{}{
|
|
|
|
+ "phone": mobile,
|
|
|
|
+ }
|
|
|
|
+ phoneData := map[string]interface{}{
|
|
"phone": mobile,
|
|
"phone": mobile,
|
|
"phone_state": phoneState,
|
|
"phone_state": phoneState,
|
|
"date": date.FormatDate(&now, date.Date_Full_Layout),
|
|
"date": date.FormatDate(&now, date.Date_Full_Layout),
|
|
- }); id <= 0 {
|
|
|
|
- jylog.Info("sms_black_phone 信息保存异常:", mobile, ip)
|
|
|
|
|
|
+ }
|
|
|
|
+ tableName := "useranaly.sms_black_phone"
|
|
|
|
+ if phoneD := config.BaseMysql.FindOne(tableName, phoneQuery, "ip,ip_state", "date desc"); phoneD == nil {
|
|
|
|
+ if id := config.BaseMysql.Insert(tableName, phoneData); id <= 0 {
|
|
|
|
+ jylog.Info("sms_black_phone 信息保存异常:", mobile, ip)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ delete(phoneData, "phone")
|
|
|
|
+ if ok := config.BaseMysql.Update(tableName, phoneQuery, phoneData); !ok {
|
|
|
|
+ jylog.Info("sms_black_phone 信息更新异常:", mobile, ip)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}(aks, reqData.Ip, reqData.Phones)
|
|
}(aks, reqData.Ip, reqData.Phones)
|
|
- jylog.Info(reqData.Phones, "---当前用户发送短信验证次数超过最大限制:"+strings.Join(aks, ","))
|
|
|
|
|
|
+ jylog.Info(reqData.Phones, "---发送短信次数过多,规则:"+strings.Join(aks, "###"))
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
return true
|