|
|
@@ -41,19 +41,19 @@ class Base extends Api |
|
|
|
* @param int $millisecond |
|
|
|
*/ |
|
|
|
public function limitVisit($millisecond = 200) { |
|
|
|
$millisecond = $this->request->request('millisecond', $millisecond); |
|
|
|
|
|
|
|
// 限制200毫秒 防止1秒两刀 (双击甚至三击,同一时间导致接口请求两次以上) |
|
|
|
$action = $this->request->action(); |
|
|
|
if (!in_array($action, $this->frequently) && $this->auth && $this->auth->isLogin() && $millisecond > 0) { |
|
|
|
$controller = $this->request->controller(); |
|
|
|
if (Cache::has($controller.'_'.$action.'_'.$this->auth->id)) { |
|
|
|
if (Cache::get($controller.'_'.$action.'_'.$this->auth->id) + $millisecond > \addons\unishop\model\Config::getMillisecond()) { |
|
|
|
$this->error(__('Frequent interface requests')); |
|
|
|
} |
|
|
|
} |
|
|
|
Cache::set($controller.'_'.$action.'_'.$this->auth->id, \addons\unishop\model\Config::getMillisecond(), 1); |
|
|
|
} |
|
|
|
// $millisecond = $this->request->request('millisecond', $millisecond); |
|
|
|
// |
|
|
|
// // 限制200毫秒 防止1秒两刀 (双击甚至三击,同一时间导致接口请求两次以上) |
|
|
|
// $action = $this->request->action(); |
|
|
|
// if (!in_array($action, $this->frequently) && $this->auth && $this->auth->isLogin() && $millisecond > 0) { |
|
|
|
// $controller = $this->request->controller(); |
|
|
|
// if (Cache::has($controller.'_'.$action.'_'.$this->auth->id)) { |
|
|
|
// if (Cache::get($controller.'_'.$action.'_'.$this->auth->id) + $millisecond > \addons\unishop\model\Config::getMillisecond()) { |
|
|
|
// $this->error(__('Frequent interface requests')); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// Cache::set($controller.'_'.$action.'_'.$this->auth->id, \addons\unishop\model\Config::getMillisecond(), 1); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|