<?php
namespace App\Service;
use Exception;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
//Token user; 3GU8S4LI8EBXP87HGQBYBC21Z
//Client id: 6r7mnD8u1b0WUnO6DqM2qg155M7utS82fxo7jQMC
//Secret client;: 1AmMPG18o7NXgEHYx7cLmHC0XbcRDUaDdPAESABnPHrhGJnatiFbgMSb2NjKsJkLevUfa38zK74LKm7iCvxVfERf2Su7wqH8Nidmm1INOFD98CkFAHofoMcbMiTEEOkD
class WemapService
{
protected string $secret_key = "1AmMPG18o7NXgEHYx7cLmHC0XbcRDUaDdPAESABnPHrhGJnatiFbgMSb2NjKsJkLevUfa38zK74LKm7iCvxVfERf2Su7wqH8Nidmm1INOFD98CkFAHofoMcbMiTEEOkD";
protected string $client_id = "6r7mnD8u1b0WUnO6DqM2qg155M7utS82fxo7jQMC";
protected mixed $access_token = [];
private WemapClient $client;
public function __construct()
{
$this->client = new WemapClient();
$this->client->setPublicKey($this->client_id);
$this->auth();
//$this->getAgenda();
}
private function auth(): void
{
if (empty($this->access_token)) {
$datas = [
'grant_type' => 'client_credentials',
'client_id' => $this->client_id,
];
try {
$this->client->setAuthToken('NnI3bW5EOHUxYjBXVW5PNkRxTTJxZzE1NU03dXRTODJmeG83alFNQzoxQW1NUEcxOG83TlhnRUhZeDdjTG1IQzBYYmNSRFVhRGRQQUVTQUJuUEhyaEdKbmF0aUZiZ01TYjJOaktzSmtMZXZVZmEzOHpLNzRMS203aUN2eFZmRVJmMlN1N3dxSDhOaWRtbTFJTk9GRDk4Q2tGQUhvZm9NY2JNaVRFRU9rRA==');
$response = $this->client->post('/v3.0/oauth2/token', $datas, true);
$decode_response = json_decode((string)$response->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
$this->access_token = ['access_token' => $decode_response->access_token, 'expires_in' => $decode_response->expires_in];
$this->client->setAccessToken($decode_response->access_token);
} catch (RequestException $e) {
$response = $e->getResponse();
if ($e->hasResponse()) {
throw new Exception($response->getBody()->getContents());
}
} catch (Exception $e) {
throw $e;
}
}
}
public function getAllPois(int $limit, int $offset): mixed
{
$decode_response = false;
try {
$response = $this->client->get('/v3.0/pinpoints?list=69184&offset=' . $offset . '&limit=' . $limit);
$decode_response = json_decode((string)$response->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
} catch (RequestException $e) {
$response = $e->getResponse();
if ($e->hasResponse()) {
$decode_response = false;
//throw new Exception($response->getBody()->getContents());
}
} catch (Exception $e) {
$decode_response = false;
}
return $decode_response;
}
public function getCategories(): mixed
{
try {
$response = $this->client->get('/v3.0/livemaps/22215');
$decode_response = json_decode((string)$response->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
} catch (RequestException $e) {
//$response = $e->getResponse();
/*if ($e->hasResponse()) {
throw new Exception($response->getBody()->getContents());
}*/
$decode_response = false;
} catch (Exception $e) {
//throw $e;
$decode_response = false;
}
return $decode_response;
}
}