src/Service/WemapService.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use Exception;
  4. use GuzzleHttp\Exception\ClientException;
  5. use GuzzleHttp\Exception\RequestException;
  6. use Psr\Http\Message\ResponseInterface;
  7. //Token user; 3GU8S4LI8EBXP87HGQBYBC21Z
  8. //Client id: 6r7mnD8u1b0WUnO6DqM2qg155M7utS82fxo7jQMC
  9. //Secret client;: 1AmMPG18o7NXgEHYx7cLmHC0XbcRDUaDdPAESABnPHrhGJnatiFbgMSb2NjKsJkLevUfa38zK74LKm7iCvxVfERf2Su7wqH8Nidmm1INOFD98CkFAHofoMcbMiTEEOkD
  10. class WemapService
  11. {
  12.     protected string $secret_key "1AmMPG18o7NXgEHYx7cLmHC0XbcRDUaDdPAESABnPHrhGJnatiFbgMSb2NjKsJkLevUfa38zK74LKm7iCvxVfERf2Su7wqH8Nidmm1INOFD98CkFAHofoMcbMiTEEOkD";
  13.     protected string $client_id "6r7mnD8u1b0WUnO6DqM2qg155M7utS82fxo7jQMC";
  14.     protected mixed $access_token = [];
  15.     private WemapClient $client;
  16.     public function __construct()
  17.     {
  18.         $this->client = new WemapClient();
  19.         $this->client->setPublicKey($this->client_id);
  20.         $this->auth();
  21.         //$this->getAgenda();
  22.     }
  23.     private function auth(): void
  24.     {
  25.         if (empty($this->access_token)) {
  26.             $datas = [
  27.                 'grant_type' => 'client_credentials',
  28.                 'client_id' => $this->client_id,
  29.             ];
  30.             try {
  31.                 $this->client->setAuthToken('NnI3bW5EOHUxYjBXVW5PNkRxTTJxZzE1NU03dXRTODJmeG83alFNQzoxQW1NUEcxOG83TlhnRUhZeDdjTG1IQzBYYmNSRFVhRGRQQUVTQUJuUEhyaEdKbmF0aUZiZ01TYjJOaktzSmtMZXZVZmEzOHpLNzRMS203aUN2eFZmRVJmMlN1N3dxSDhOaWRtbTFJTk9GRDk4Q2tGQUhvZm9NY2JNaVRFRU9rRA==');
  32.                 $response $this->client->post('/v3.0/oauth2/token'$datastrue);
  33.                 $decode_response json_decode((string)$response->getBody()->getContents(), null512JSON_THROW_ON_ERROR);
  34.                 $this->access_token = ['access_token' => $decode_response->access_token'expires_in' => $decode_response->expires_in];
  35.                 $this->client->setAccessToken($decode_response->access_token);
  36.             } catch (RequestException $e) {
  37.                 $response $e->getResponse();
  38.                 if ($e->hasResponse()) {
  39.                     throw new Exception($response->getBody()->getContents());
  40.                 }
  41.             } catch (Exception $e) {
  42.                 throw $e;
  43.             }
  44.         }
  45.     }
  46.     public function getAllPois(int $limitint $offset): mixed
  47.     {
  48.         $decode_response false;
  49.         try {
  50.             $response $this->client->get('/v3.0/pinpoints?list=69184&offset=' $offset '&limit=' $limit);
  51.             $decode_response json_decode((string)$response->getBody()->getContents(), null512JSON_THROW_ON_ERROR);
  52.         } catch (RequestException $e) {
  53.             $response $e->getResponse();
  54.             if ($e->hasResponse()) {
  55.                 $decode_response false;
  56.                 //throw new Exception($response->getBody()->getContents());
  57.             }
  58.         } catch (Exception $e) {
  59.             $decode_response false;
  60.         }
  61.         return $decode_response;
  62.     }
  63.     public function getCategories(): mixed
  64.     {
  65.         try {
  66.             $response $this->client->get('/v3.0/livemaps/22215');
  67.             $decode_response json_decode((string)$response->getBody()->getContents(), null512JSON_THROW_ON_ERROR);
  68.         } catch (RequestException $e) {
  69.             //$response = $e->getResponse();
  70.             /*if ($e->hasResponse()) {
  71.                 throw new Exception($response->getBody()->getContents());
  72.             }*/
  73.             $decode_response false;
  74.         } catch (Exception $e) {
  75.             //throw $e;
  76.             $decode_response false;
  77.         }
  78.         return $decode_response;
  79.     }
  80. }