loadUniShopLang(); $this->limitVisit(); }*/ public function __construct() { parent::__construct(); $this->loadUniShopLang(); $this->limitVisit(); } /** * 限制接口访问频率 * @param int $millisecond * @ApiInternal */ public function limitVisit_bak($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); } } public function limitVisit($millisecond = 200) { $action = $this->request->action(); if (!in_array($action, $this->frequently) && $this->auth && $this->auth->isLogin() && $millisecond > 0) { $apilimit = $this->apiLimit(); if(!$apilimit){ $this->error('操作过于频繁'); } } } /** * 加载语言文件 */ protected function loadUniShopLang() { $route = $this->request->route(); $lang = $this->request->header('lang') ?: 'zh-cn'; $path = ADDON_PATH . $route['addon'] . '/lang/' . $lang . '/' . str_replace('.', '/', $route['controller']) . '.php'; Lang::load(ADDON_PATH . $route['addon'] . '/lang/'.$lang.'.php'); // 默认语言包 Lang::load($path); } }