diff --git a/Application/Home/Controller/BaseController.class.php b/Application/Home/Controller/BaseController.class.php index 4817777a8..772e4e842 100644 --- a/Application/Home/Controller/BaseController.class.php +++ b/Application/Home/Controller/BaseController.class.php @@ -5,6 +5,8 @@ namespace Home\Controller; use Base\Service\PromoteCompanyService; use Think\Controller; use Base\Service\PromoteService; +use Base\Tool\Redis; +use Think\Log; class BaseController extends HomeController { @@ -30,6 +32,9 @@ class BaseController extends HomeController $this->login(); $loginer = $this->getLoginPromote(); + + $this->accessLimit($loginer); + // $this->certifiCation(); $pid = is_login_promote(); define('PLEVEL', $loginer['parent_id']); @@ -432,4 +437,22 @@ class BaseController extends HomeController ->group('relation_game_id') ->select(); } + + public function accessLimit($loginer) + { + $url = MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME; + $urlKey = substr(md5($url), 8, 16); + $key = $loginer['id'] . ':' . $urlKey; + $check = Redis::exists($key); + if ($check) { + $count = Redis::incr($key); + if ($count > 60) { + Log::write('user_access_limit:' . date('Y-m-d H:i:s') . ' ' . $key . '[' . $url . ']', 'INFO'); + die('请求太频繁,请稍后再试!'); + } + } else { + Redis::incr($key); + Redis::expire($key, 60); + } + } }