51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Services\AdminService;
|
|
|
|
class CustomerInfoService
|
|
{
|
|
protected $adminService;
|
|
|
|
public function __construct(AdminService $adminService)
|
|
{
|
|
$this->adminService = $adminService;
|
|
}
|
|
|
|
public function getThingsBoardDevices($customerId)
|
|
{
|
|
try {
|
|
$token = $this->adminService->getToken();
|
|
|
|
if (!$token) {
|
|
Log::error("Failed to authenticate with ThingsBoard.");
|
|
return [];
|
|
}
|
|
|
|
$response = Http::withHeaders([
|
|
'Authorization' => "Bearer $token",
|
|
'Accept' => 'application/json',
|
|
])->get("http://65.0.131.117:8080/api/customer/{$customerId}/deviceInfos?pageSize=100&page=0");
|
|
|
|
if (!$response->successful()) {
|
|
Log::error("Failed to fetch ThingsBoard devices: " . $response->body());
|
|
return [];
|
|
}
|
|
|
|
return $response->json()['data'] ?? [];
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error("Error fetching ThingsBoard devices: " . $e->getMessage());
|
|
return [];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|