34 lines
700 B
PHP
34 lines
700 B
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Helper;
|
||
|
|
||
|
use GuzzleHttp\Client;
|
||
|
use Hyperf\Guzzle\HandlerStackFactory;
|
||
|
|
||
|
class Curl
|
||
|
{
|
||
|
public static function get(string $url) : array
|
||
|
{
|
||
|
$factory = new HandlerStackFactory();
|
||
|
$stack = $factory->create();
|
||
|
|
||
|
$client = make(Client::class, [
|
||
|
'config' => [
|
||
|
'handler' => $stack,
|
||
|
]
|
||
|
]);
|
||
|
$response = $client->get($url, ['timeout' => 2]);
|
||
|
|
||
|
if ($response->getStatusCode() === 200) {
|
||
|
return json_decode($response->getBody()->getContents(), true);
|
||
|
}
|
||
|
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
public static function post(string $url, array $data = [])
|
||
|
{
|
||
|
}
|
||
|
}
|