停车场系统数据中间件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
1.6 KiB

<?php
namespace App\Services\Api;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class BaseApiService
{
protected string $hostUrl;
public function __construct()
{
$this->hostUrl = env('SYS_URL', '');
}
/**
* @param string $url
* @param array $query
* @return Response
*/
protected function getHttp(string $url, array $query = []): Response
{
$getUrl = $this->hostUrl . $url;
return Http::withOptions(['verify' => false])->get($getUrl, $query);
}
/**
* @param string $url
* @param array $data
* @return Response
*/
protected function putHttp(string $url, array $data): Response
{
$getUrl = $this->hostUrl . $url;
return Http::withOptions(['verify' => false])->put($getUrl, $data);
}
/**
* @param string $url
* @return array
*/
protected function getBody(string $url): array
{
$Response = $this->getHttp($url);
if ($Response->successful()) {
$body = $Response->body();
if ($body) {
return json_decode($body, true);
}
}
return [];
}
/**
* @param string $url
* @param array $data
* @return array
*/
protected function putBody(string $url, array $data): array
{
$Response = $this->putHttp($url, $data);
if ($Response->successful()) {
$body = $Response->body();
if ($body) {
return json_decode($body, true);
}
}
return [];
}
}