Browse Source

短信接口防刷

lizhen_gitee 3 months ago
parent
commit
616f476cbc
1 changed files with 8 additions and 0 deletions
  1. 8 0
      application/api/controller/Sms.php

+ 8 - 0
application/api/controller/Sms.php

@@ -31,6 +31,14 @@ class Sms extends Api
         if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('手机号不正确'));
         }
+
+        if(!$this->apiLimit(60,10,request()->ip())){
+            $this->error('当前发送人数过多,请稍后再试');
+        };
+        if(!$this->apiLimit(3600,10,$mobile)){
+            $this->error('您的手机号发送频繁,请稍后再试');
+        };
+
         $last = Smslib::get($mobile, $event);
         if ($last && time() - $last['createtime'] < 60) {
             $this->error(__('发送频繁,请稍后再试'));