KTV/app/Services/ApiClient.php
allen.yan 3bbb1a5cc0 Room 加入 is_online 來區別再不再線上
調整 FavoriteSongs 資料塞值改用seeder
加入 user_song table
/api/room/receiveRegister 調整邏輯
room介面 開關包帳功能調整
寫入心跳封包
20250522
2025-05-22 10:08:34 +08:00

41 lines
1.1 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class ApiClient
{
protected string $baseUrl;
protected string $token;
public function __construct(string $token = null)
{
$this->baseUrl = config('services.room_api.base_url', 'https://ktv.test/api');
$this->token = $token ?? config('services.room_api.token');
}
public function setToken(string $token): self
{
$this->token = $token;
return $this;
}
public function withDefaultHeaders(): \Illuminate\Http\Client\PendingRequest
{
return Http::withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . config('services.room_api.token'),
'Content-Type' => 'application/json',
]);
}
public function post(string $endpoint, array $data = [])
{
return $this->withDefaultHeaders()->post($this->baseUrl . $endpoint, $data);
}
public function get(string $endpoint, array $query = [])
{
return $this->withDefaultHeaders()->get($this->baseUrl . $endpoint, $query);
}
}