发送短信 ip限制

This commit is contained in:
2025-12-23 01:59:20 +08:00
parent bae8b3158d
commit 5fca7b9e06

View File

@@ -43,11 +43,12 @@ class Sms extends Api
//频率控制 //频率控制
$last = db::name('sms')->where(['mobile' => $mobile, 'event' => $event])->order('id', 'DESC')->find(); $last = db::name('sms')->where(['mobile' => $mobile, 'event' => $event])->order('id', 'DESC')->find();
if ($last && time() - $last['createtime'] < 60) { if ($last && time() - $last['createtime'] < 60) {
return V(0, '发送频繁'); return V(0, '发送频繁');
} }
$ipSendTotal = db::name('sms')->where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count(); $ip = request()->server('HTTP_X_REAL_IP') ?: request()->server('HTTP_X_FORWARDED_FOR') ?: request()->ip();
$ipSendTotal = db::name('sms')->where(['ip' => $ip])->whereTime('createtime', '-1 hours')->count();
if ($ipSendTotal >= 7) { if ($ipSendTotal >= 7) {
return V(0, '发送频繁'); return V(0, '发送频繁');
} }
//发送短信 //发送短信
$ret = $this->send_smsbao_msg($mobile, $event); $ret = $this->send_smsbao_msg($mobile, $event);