log = new LogOpe('api/'.get_class($this) . 'Controller'); $this->apilog = new LogOpe("request/".date("YmdH") . "Request"); if(!$this->match($this->noNeedCheck)){ // $this->checkSign(); } $this->checkUser(); } /** * 检测当前控制器和方法是否匹配传递的数组. * * @param array $arr 需要验证权限的数组 * @return bool */ public function match($arr = []) { $request = Request::instance(); $arr = is_array($arr) ? $arr : explode(',', $arr); if (! $arr) { return false; } $arr = array_map('strtolower', $arr); // 是否存在 if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) { return true; } // 没找到匹配 return false; } /** * 请求校验(抛异常) * @param $class * @param string $scene * @param string|null $method 指定参数类型 * @param bool $limit 限制请求类型 * @throws \Exception */ protected function checkVaild($class, $scene = '', $method = null, $limit = false) { (new BaseService())->checkVaild($class, $scene, $method, $limit); } /** * 校验签名. * * @return bool */ public function checkSign() { $signService = new SignService(); // 获取请求数据 $post = $this->request->post(['appkey', 'timestamp']); // 获取签名以及key $sign = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : ''; if (!$sign){ throw new HttpResponseException(_error('缺少sign', 400)); } $signService->checkSign($post, $sign); } public function checkUser(){ $user_isli = $this->request->post('user_isli', ''); $userService = new UserService(); if(!empty($user_isli)){ // $userService->checkUser($user_isli); } } }