123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace addons\unishop\controller;
- use app\common\controller\Api;
- use think\Cache;
- use think\Lang;
- class Base extends Api
- {
-
- protected $noNeedRight = ['*'];
-
- protected $frequently = [];
-
- public function __construct()
- {
- parent::__construct();
- $this->loadUniShopLang();
- $this->limitVisit();
- }
-
- public function limitVisit_bak($millisecond = 200) {
-
-
- $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);
- }
- }
|