cookieDomain = Config::get('cookie.domain', ''); $header = Config::get('cookie.header'); $origin = $request->header('origin'); if ($origin && ('' == $this->cookieDomain || strpos($origin, $this->cookieDomain))) $header['Access-Control-Allow-Origin'] = $origin; if ($request->method(true) == 'OPTIONS') { $response = Response::create('ok')->code(200)->header($header); } else { $response = $next($request)->header($header); } $request->filter(['strip_tags', 'addslashes', 'trim']); // $c = $request->controller(); // $a = $request->action(); // $str = trim($c . '/' . $a); // $auth_api = ['v1.Withdrawal/executeAdmin', 'v1.Pay/adminPay']; // if (in_array($str, $auth_api) && false) { // 需要检测签名 // $sign = $request->header('sign'); // if (empty($sign)) // return app('json')->json_error('签名不存在'); // if ($this->createApiSign($request->param()) != $sign) // return app('json')->json_error('签名验证失败'); // } return $response; } /** * 获取接口签名 * @param array $params * @return string */ // protected function createApiSign (array $params): string // { // unset($params['sign']); // // //签名步骤一:按字典序排序数组参数 // ksort($params); // $string = $this->toUrlParams($params); // //签名步骤二:在string后加入KEY // $app_key = env('app.app_key'); // $string = trim($string . "&key=" . $app_key); // //签名步骤三:MD5加密 // $string = md5($string); // //签名步骤四:所有字符转为大写 // $result = strtoupper($string); // return $result; // } /** * 将参数拼接为url: key=value&key=value * @param $params * @return string */ protected function toUrlParams ($params) { $string = ''; if (!empty($params)) { $array = array(); foreach ($params as $key => $value) { $array[] = $key . '=' . $value; } $string = implode("&", $array); } return $string; } }