log = new Log(); if(!$this->match($this->noNeedCheck)){ $this->checkSign(); } } /** * 检测当前控制器和方法是否匹配传递的数组. * * @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; } /** * 校验签名. * * @return bool */ public function checkSign() { $signService = new SignService(); // 获取请求数据 $post = $this->request->post(); // 获取签名以及key $sign = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : ''; if (!$sign){ throw new HttpResponseException(_error('缺少sign', 400)); } $signService->checkSign($post, $sign); } }