46 lines
875 B
PHP
46 lines
875 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Exception;
|
|
use GuzzleHttp\Client;
|
|
|
|
class ShopService
|
|
{
|
|
|
|
/**
|
|
* @var string|mixed
|
|
*/
|
|
private string $baseUri;
|
|
|
|
/**
|
|
* @var string|mixed
|
|
*/
|
|
private string $key;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->baseUri = env('SHOP_URL');
|
|
$this->key = env('SHOP_KEY');
|
|
}
|
|
|
|
public function request($method, $action, $data = [])
|
|
{
|
|
$client = new Client();
|
|
$url = $this->baseUri . $action;
|
|
$param = [
|
|
'headers' => [
|
|
'Key' => $this->key
|
|
],
|
|
'query' => $data
|
|
];
|
|
|
|
$resp = $client->request($method, $url, $param);
|
|
if ($resp->getStatusCode() != 200) {
|
|
throw new Exception('shop service error');
|
|
}
|
|
|
|
return json_decode($resp->getBody()->getContents(), true);
|
|
}
|
|
|
|
} |