Skip to content

Commit 6c6c687

Browse files
committed
update
1 parent fa3c25c commit 6c6c687

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/ApiGateway.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,33 @@ public function RequestEvent(RequestEvent $event)
8686
$headers['Authorization'] = "hmac id=\"{$this->secretId}\", algorithm=\"{$this->signatureMethod}\", headers=\"date nonce\", signature=\"{$sign}\"";
8787
$event->request->addHeaders($headers);
8888
}
89+
90+
/**
91+
* 发送请求
92+
* @param string $method
93+
* @param array|string $url
94+
* @param array|string $data
95+
* @param array $headers
96+
* @param array $options
97+
* @return array response data.
98+
* @throws Exception
99+
*/
100+
public function sendRequest($method, $url, $data, $headers, $options)
101+
{
102+
$request = $this->createRequest()
103+
->setMethod($method)
104+
->setUrl($url)
105+
->addHeaders($headers)
106+
->addOptions($options);
107+
if (is_array($data)) {
108+
$request->setData($data);
109+
} else {
110+
$request->setContent($data);
111+
}
112+
$response = $request->send();
113+
if (!$response->isOk) {
114+
throw new Exception('Request fail. response: ' . $response->content, $response->statusCode);
115+
}
116+
return $response->data;
117+
}
89118
}

0 commit comments

Comments
 (0)