header('d-token', ''); $param_sign = $request->header('sign', ''); $nonce = $request->header('nonce', ''); $timestamp = $request->header('timestamp', ''); if (!$token) { $token = $request->input('d_token', ''); if (!$token) Utils::throwError(ErrorConst::NOT_LOGIN); } $referer_url = $request->input('_url', ''); // 先验签(非本地模式需要验签) if (env('CHECK_SIGN')) { $check_params = [ 'd-token' => $token, 'nonce' => $nonce, 'timestamp' => $timestamp, ]; $params = $check_params; $params['_url'] = $referer_url; if (!$nonce || !$timestamp) { dLog('checkSign')->info('验签失败, 请求参数不正确;传参: '.json_encode($params, 256)); Utils::throwError('1002:签名异常'); } if (time() - $timestamp > 300) { dLog('checkSign')->info('验签失败, 签名5分钟内有效;传参: '.json_encode($params, 256)); Utils::throwError('1002:签名异常'); } ksort($check_params); $str = strtoupper(http_build_query($check_params)); $sign = md5($str.'&key='.env('SIGN_SALT')); if ($param_sign != $sign) { $params['_url'] = $referer_url; $params['sign'] = $param_sign; $params['check_sign'] = $sign; $params['check_str'] = $str.'&key='.env('SIGN_SALT'); dLog('checkSign')->info('验签失败, 签名不正确;传参: '.json_encode($params, 256)); Utils::throwError('1002:签名异常'); } } return $next($request); } }