composer require guzzlehttp/guzzle
複製代碼
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'http://httpbin.org'
]);
複製代碼
public function getLotteryHistory($lottery_id, $page_size, $page)
{
$url = "/lottery/history?key=$this->key&lottery_id=$lottery_id&page_size=$page_size&page=$page";
$histroyData = $this->getQueryData($url);
return $histroyData;
}
public function getQueryData($url)
{
$response = $this->http->get($url);
if ($response->getStatusCode() != 200) {
throw new ThirdException();
}
$responseData = json_decode($response->getBody());
if ($responseData->error_code != 0) {
throw new ThirdException(3001, $responseData->reason);
}
return $responseData;
}
複製代碼
快速入門html