Laravel——Guzzlehttp 布满荆棘的人生 2022-10-01 10:57 5阅读 0赞 # 安装 # composer require guzzlehttp/guzzle 复制代码 # 创建客户端 # use GuzzleHttp\Client; $client = new Client([ 'base_uri' => 'http://httpbin.org' ]); 复制代码 # GET请求 # 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; } 复制代码 # 参考文档 # [快速入门][Link 1] 转载于:https://juejin.im/post/5cbd5e00e51d456e46603e3c [Link 1]: https://link.juejin.im?target=https%3A%2F%2Fguzzle-cn.readthedocs.io%2Fzh_CN%2Flatest%2Fquickstart.html
还没有评论,来说两句吧...