/** * @param Request\Request $request * @return array */ public function buildHeader($request) { $date = gmdate('D, d M Y H:i:s T'); $idempotencyKey = $request->getIdempotence() ? md5(uniqid(rand(), true)) : ''; $signature = Middleware::generateSignature(parse_url($this->apiUrl, PHP_URL_HOST) . ':' . parse_url($this->apiUrl, PHP_URL_PORT), $request->getMethod(), parse_url($this->apiUrl . $request->getPath(), PHP_URL_PATH), parse_url($this->apiUrl, PHP_URL_QUERY), $date, $idempotencyKey, $request->getBody(), $this->paymentKey); $header = array("Host: " . parse_url($this->apiUrl, PHP_URL_HOST), "Date: " . $date, "User-Agent: " . $this->userAgent, "Authorization: BZ1-HMAC-SHA256 DivisionId=" . $this->divisionId . ", Signature=" . $signature); if ($idempotencyKey !== '') { $header[] = "Idempotency-Key: " . $idempotencyKey; } return $header; }
/** * Outputs the result of the request * * @param int $format * @param bool $inline * * @return mixed */ public function outputResult($format = Type\OutputFormat::JSON, $inline = FALSE) { if (isset($this->error)) { $result = $this->error; } else { $this->startTimingForLabel('total', 'frest'); try { $result = $this->request->generateResult(); } catch (Exception $exception) { $result = $exception->generateError(); } $this->stopTimingForLabel('total', 'frest'); } $output = $result->output($this, $format, $inline); if (!$inline) { die; } return $output; }
/** * 获取请求参数,包括$_GET、$_POST信息 或者命令行参数:$_SERVER["argv"] * * @param string|int $name 参数名称(web请求),或参数序号(cli请求) * @param string $defaultValue 当获取变量失败的时候返回该值,默认该值为null * * @return string */ public function getParameter($name, $defaultValue = null) { return $this->request->getParameter($name, $defaultValue); }