Sindbad~EG File Manager
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class WordPressService
{
protected $baseUri;
protected $clientId;
protected $clientSecret;
public function __construct()
{
$this->baseUri = rtrim(env('WP_OAUTH_BASE_URI'), '/');
$this->clientId = env('WP_OAUTH_CLIENT_ID');
$this->clientSecret = env('WP_OAUTH_CLIENT_SECRET');
}
public function obtenerAccessToken()
{
$response = Http::asForm()->post("{$this->baseUri}/oauth/token", [
'grant_type' => 'client_credentials',
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
]);
if ($response->failed()) {
Log::error('Error al obtener token de WordPress', ['response' => $response->body()]);
throw new \Exception('No se pudo obtener el token de acceso de WordPress.');
}
return $response->json()['access_token'];
}
public function obtenerUsuarios()
{
$token = $this->obtenerAccessToken();
$response = Http::withToken($token)->get("{$this->baseUri}/wp-json/wp/v2/users");
if ($response->failed()) {
Log::error('Error al obtener usuarios de WordPress', ['response' => $response->body()]);
throw new \Exception('No se pudieron obtener los usuarios.');
}
return $response->json();
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists