觉得博客写得不好,可以查看官网: http://docs.guzzlephp.org/en/latest/index.html
反正我写来也是给自己看的、、、、、、
一、安装 guzzlehttp/guzzle 扩展包
composer require guzzlehttp/guzzle
二、使用扩展
<?php
namespace App\Http\Controllers\Auth;
use Laravel\Lumen\Routing\Controller as BaseController;
use GuzzleHttp\Client as Client;
class HelperApiController extends BaseController
{
/**
* 请求地址
*/
public $baseUri = 'http://www.123.com';
public $client;
public function __construct()
{
$this->client = new Client();
}
/**
* 请求远程接口
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function call_base( $params, $method = 'get' )
{
$method = strtoupper($method); // 请求方式转化为大写 get post
$url = $this->baseUri; // 请求地址
$res = $this->client->request($method, $url, $params);
$content = $res->getBody()->getContents();
$result = json_decode($content, true);
dd( $content );
}
public function call(Request $request)
{
// 查询示例 查询国家
$params = [
'table' => 'C_VIP',
'start' => 1,
'range' => 2, // 查询条数
'count' => false, // 是否显示count
];
$result = $this->call_base($params,'get');
}
}