src/Services/CallApiServices.php line 687

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\RouterInterface;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  7. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  8. use Psr\Log\LoggerInterface;
  9. class CallApiServices
  10. {
  11.     private $apiKey;
  12.     private $apiToken;
  13.     private $accountId;
  14.     private $serviceId;
  15.     private $apiURL;
  16.     private $baseURL;
  17.     private $session;
  18.     /* @var $router RouterInterface */
  19.     private $router;
  20.     private $parameters;
  21.     private $logger;
  22.     public function __construct(SessionInterface $session$apiKey$accountId$baseURL$apiToken$serviceId$apiURLRouterInterface $routerParameterBagInterface $parametersLoggerInterface $logger)
  23.     {
  24.         $this->apiKey $apiKey;
  25.         $this->apiToken $apiToken;
  26.         $this->accountId $accountId;
  27.         $this->serviceId $serviceId;
  28.         $this->apiURL $apiURL;
  29.         $this->baseURL $baseURL;
  30.         $this->session $session;
  31.         $this->router $router;
  32.         $this->parameters $parameters;
  33.         $this->logger $logger;
  34.     }
  35.     public function postApi($endpoint, array $data): array
  36.     {
  37.         $url $this->parameters->get('apiURL') . "/" "$endpoint";
  38.         $httpHost $this->parameters->get('baseURL');
  39.         $dataEncoded json_encode($data);
  40.         $headers = array(
  41.             "Accept: application/json",
  42.             "Content-Type: application/json",
  43.         );
  44.         $this->logger->info('Posting to API :' $url ' with referer:' $httpHost ' and data: ' $dataEncoded);
  45.         $curl curl_init($url);
  46.         curl_setopt($curlCURLOPT_REFERER$httpHost);
  47.         curl_setopt($curlCURLOPT_POSTtrue);
  48.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  49.         curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
  50.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  51.         curl_setopt($curlCURLOPT_POSTFIELDS$dataEncoded);
  52.         $response curl_exec($curl);
  53.         $curl_http_code curl_getinfo($curlCURLINFO_HTTP_CODE);
  54.         $curl_error curl_error($curl);
  55.         $curl_errno curl_errno($curl);
  56.         curl_close($curl);
  57.         if ($response === false) {
  58.             throw new \Exception($curl_error$curl_errno);
  59.             return ["null" => null];
  60.         } else {
  61.             $results = [];
  62.             // if (curl_getinfo($curl, CURLINFO_HTTP_CODE) === 200) {
  63.             //   $results = json_decode($response, true);
  64.             // } else if (curl_getinfo($curl, CURLINFO_HTTP_CODE) === 401) {
  65.             //   throw $results =  new \Exception('identifiant incorecte');
  66.             // } else if (curl_getinfo($curl, CURLINFO_HTTP_CODE) === 404) {
  67.             //   $response = json_decode($response, true);
  68.             //   $results =  $response;
  69.             // } else if (curl_getinfo($curl, CURLINFO_HTTP_CODE) === 403) {
  70.             //   $response = json_decode($response, true);
  71.             //   $results = $response;
  72.             // }
  73.             switch ($curl_http_code) {
  74.                 case 200:
  75.                     $results json_decode($responsetrue);
  76.                     break;
  77.                 case 401// Accès non autorisé, l'apiKey n'existe pas
  78.                     // a rediriger vers un page d'erreur qui dirait joindre le support, car c'est une erreur qui ne devrait jamais arrivée
  79.                     die(new RedirectResponse($this->router->generate('app_login')));
  80.                     //throw $results =  new \Exception('identifiant incorrecte');
  81.                     break;
  82.                 case 403:
  83.                 case 404:
  84.                     $response json_decode($responsetrue);
  85.                     $results =  $response;
  86.                     break;
  87.                 case 409// Conflit avec le compte ID ou service ID, l'apiKey existe, mais un conflit avec les valeurs configurées
  88.                     // a rediriger vers un page d'erreur qui dirait joindre le support, car c'est une erreur qui ne devrait jamais arrivée
  89.                     die(new RedirectResponse($this->router->generate('app_login')));
  90.                     break;
  91.                 case 410// apiToken n'exite pas ou la date est dépassée, vous devez démarrer une nouvelle session
  92.                     die(new RedirectResponse($this->router->generate('app_login')));
  93.                     break;
  94.                 default:
  95.                     $response json_decode($responsetrue);
  96.                     $results =  $response;
  97.                     break;
  98.             }
  99.         }
  100.         // $data = [ 'message' => "Accès non autorisé", 'responseCode' => "401" ];  l'apiKey n'existe pas
  101.         // $data = [ 'message' => "Conflit avec le référent HTTP", 'responseCode' => "409" ]; l'apiKey existe, mais un conflit avec les valeurs configurées
  102.         // $data = [ 'message' => "Conflit avec le compte ID", 'responseCode' => "409" ];
  103.         // $data = [ 'message' => "Conflit avec le service ID", 'responseCode' => "409" ];
  104.         // $data = [ 'message' => "token n’est plus disponible, vous devez démarrer une nouvelle session", "responseCode" => "410"}]
  105.         return $results;
  106.     }
  107.     public function getData(string $colletionName): array
  108.     {
  109.         $url 'http://localhost:8080/api';
  110.         $request_url $url '/' $colletionName;
  111.         $curl curl_init($request_url);
  112.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  113.         $response curl_exec($curl);
  114.         if ($response === false) {
  115.             return null;
  116.         } else {
  117.             $results = [];
  118.             if (curl_getinfo($curlCURLINFO_HTTP_CODE) === 200) {
  119.                 $response json_decode($responsetrue);
  120.             }
  121.         }
  122.         curl_close($curl);
  123.         return $response;
  124.     }
  125.     public function getDataById(string $colletionNamestring $id): array
  126.     {
  127.         $url 'http://localhost:8080/api';
  128.         $request_url $url '/' $colletionName '/' $id;
  129.         $curl curl_init($request_url);
  130.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  131.         $response curl_exec($curl);
  132.         if ($response === false) {
  133.             return null;
  134.         } else {
  135.             $results = [];
  136.             if (curl_getinfo($curlCURLINFO_HTTP_CODE) === 200) {
  137.                 $response json_decode($responsetrue);
  138.             }
  139.         }
  140.         curl_close($curl);
  141.         return $response;
  142.     }
  143.     public function authApi(string $loginstring $password): array
  144.     {
  145.         $url 'http://localhost:8080/api/login';
  146.         $curl curl_init($url);
  147.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  148.         $headers = array(
  149.             "Accept: application/json",
  150.             "Content-Type: application/json",
  151.         );
  152.         $data = [
  153.             "username" => $login,
  154.             "password" => $password
  155.         ];
  156.         $dataEncoded json_encode($data);
  157.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  158.         curl_setopt($curlCURLOPT_POSTFIELDS$dataEncoded);
  159.         $response curl_exec($curl);
  160.         if ($response === false) {
  161.             return ["null" => null];
  162.         } else {
  163.             $results = [];
  164.             if (curl_getinfo($curlCURLINFO_HTTP_CODE) === 200) {
  165.                 $response json_decode($responsetrue);
  166.             } else if (curl_getinfo($curlCURLINFO_HTTP_CODE) === 401) {
  167.                 throw new \Exception('identifiant incorecte');
  168.             }
  169.         }
  170.         curl_close($curl);
  171.         return $response;
  172.     }
  173.     public function getUserDetails(string $token): array
  174.     {
  175.         $url 'http://localhost:8080/api/me';
  176.         $curl curl_init($url);
  177.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  178.         $headers = array(
  179.             "Accept: application/json",
  180.             "Content-Type: application/json",
  181.             "Authorization: Bearer " $token ""
  182.         );
  183.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  184.         $response curl_exec($curl);
  185.         if ($response === false) {
  186.             return ["null" => null];
  187.         } else {
  188.             $results = [];
  189.             if (curl_getinfo($curlCURLINFO_HTTP_CODE) === 200) {
  190.                 $response json_decode($responsetrue);
  191.             }
  192.         }
  193.         curl_close($curl);
  194.         return $response;
  195.     }
  196.     // ** +++++++++++++++++ ------------        --------- +++++++++++++++++ **
  197.     // ** +++++++++++++++++ ------------        --------- +++++++++++++++++ **
  198.     public function getListConseillers($accountId$serviceId): array
  199.     {
  200.         $data = [
  201.             "accountId" => $accountId,
  202.             "serviceId" => $serviceId
  203.         ];
  204.         $results $this->restApiPOSTcURL('/plateforme/listeConseillersEtPresence'$data);
  205.         return $results;
  206.     }
  207.     public function configuratationPlateforme($accountId$serviceId): array
  208.     {
  209.         $data = [
  210.             "accountId" => $accountId,
  211.             "serviceId" => $serviceId
  212.         ];
  213.         $results $this->restApiPOSTcURL('/plateforme/configuratationPlateforme'$data);
  214.         return $results;
  215.     }
  216.     public function conseillerEtPlanning($pseudoId$serviceId): array
  217.     {
  218.         $data = [
  219.             "complementId" => $pseudoId,
  220.             "serviceId" => $serviceId
  221.         ];
  222.         $results $this->restApiPOSTcURL('/plateforme/conseillerEtPlanning'$data);
  223.         return $results;
  224.     }
  225.     public function prestationEcriteMails($accountId$serviceId): array
  226.     {
  227.         $data = [
  228.             "accountId" => $accountId,
  229.             "serviceId" => $serviceId
  230.         ];
  231.         $results $this->restApiPOSTcURL('/paramaters/PrestationEcriteMails'$data);
  232.         return $results;
  233.     }
  234.     public function clientAvisNoter($apiToken$sendAvisData): array
  235.     {
  236.         $data array_merge($apiToken$sendAvisData);
  237.         $results $this->restApiPOSTcURL('/plateforme/clientAvisNoter'$data);
  238.         return $results;
  239.     }
  240.     public function clientAuthentification(string $loginstring $password$serviceId): array
  241.     {
  242.         $data = [
  243.             "serviceId" => $serviceId,
  244.             "login" => $login,
  245.             "password" => $password
  246.         ];
  247.         $results $this->restApiPOSTcURL('/plateforme/clientAuthentification'$data);
  248.         if (isset($results['responseCode']) && ($results['responseCode'] != 200)) {
  249.             return $results;
  250.         }
  251.         $this->session->set('apiToken'$results["apiToken"]);
  252.         return $results;
  253.     }
  254.     //Avis
  255.     public function conseillerAvis($serviceId$complementId): array
  256.     {
  257.         $data = [
  258.             "serviceId" => $serviceId,
  259.             "complementId" => $complementId
  260.         ];
  261.         $results $this->restApiPOSTcURL('/plateforme/conseillerAvis'$data);
  262.         return $results;
  263.     }
  264.     public function clientAvis($serviceId$clientId): array
  265.     {
  266.         $data = [
  267.             "serviceId" => $serviceId,
  268.             "clientId" => $clientId
  269.         ];
  270.         $results $this->restApiPOSTcURL('/plateforme/clientAvis'$data);
  271.         return $results;
  272.     }
  273.     public function listePlateformeAvis($serviceId): array
  274.     {
  275.         $data = [
  276.             "serviceId" => $serviceId,
  277.         ];
  278.         $results $this->restApiPOSTcURL('/plateforme/listePlateformeAvis'$data);
  279.         return $results;
  280.     }
  281.     public function clientOperations($serviceId$clientId): array
  282.     {
  283.         $data = [
  284.             "serviceId" => $serviceId,
  285.             "clientId" => $clientId
  286.         ];
  287.         $results $this->restApiPOSTcURL('/plateforme/clientOperations'$data);
  288.         return $results;
  289.     }
  290.     public function clientProfile($serviceId$clientId$reqToken): array
  291.     {
  292.         $data = [
  293.             "apiToken" => $reqToken,
  294.             "serviceId" => $serviceId,
  295.             "clientId" => $clientId
  296.         ];
  297.         $results $this->restApiPOSTcURLWithOUtToken('/plateforme/clientProfile'$data);
  298.         return $results;
  299.     }
  300.     public function clientProfileCheck($serviceId$clientId): array
  301.     {
  302.         $data = [
  303.             "serviceId" => $serviceId,
  304.             "clientId" => $clientId
  305.         ];
  306.         $results $this->restApiPOSTcURL('/plateforme/clientProfile'$data);
  307.         return $results;
  308.     }
  309.     public function clientTransactions($serviceId$clientId): array
  310.     {
  311.         $data = [
  312.             "serviceId" => $serviceId,
  313.             "clientId" => $clientId
  314.         ];
  315.         $results $this->restApiPOSTcURL('/plateforme/clientTransactions'$data);
  316.         return $results;
  317.     }
  318.     public function clientConsultations($serviceId$clientId): array
  319.     {
  320.         $data = [
  321.             "serviceId" => $serviceId,
  322.             "clientId" => $clientId
  323.         ];
  324.         $results $this->restApiPOSTcURL('/plateforme/clientConsultations'$data);
  325.         return $results;
  326.     }
  327.     public function clientInscription($serviceId$parrainID$genre$email$password$firtsname$lastname$phoneNumber): ?array
  328.     {
  329.         $data = [
  330.             "serviceId" => $serviceId,
  331.             "parrainId" => $parrainID,
  332.             "genre" => $genre,
  333.             "username" => $email,
  334.             "password" => $password,
  335.             "nom" => $firtsname,
  336.             "prenom" => $lastname,
  337.             "pays" => "FRANCE",
  338.             "telephone" => $phoneNumber
  339.         ];
  340.         $results $this->restApiPOSTcURL('/plateforme/clientInscription'$data);
  341.         return $results;
  342.     }
  343.     public function socialInscription($serviceId$genre$email$password$firtsname$lastname$country$phoneNumber$social$socialUid): ?array
  344.     {
  345.         $data = [
  346.             "apiKey" =>  $this->apiKey,
  347.             "serviceId" => $serviceId,
  348.             "parrainId" => "0",
  349.             "genre" => $genre,
  350.             "username" => $email,
  351.             "password" => $password,
  352.             "nom" => $firtsname,
  353.             "prenom" => $lastname,
  354.             "pays" => $country,
  355.             "telephone" => $phoneNumber,
  356.             "social" => $social,
  357.             "socialUid" => $socialUid
  358.         ];
  359.         $results $this->restApiPOSTcURL('/plateforme/clientInscription'$data);
  360.         return $results;
  361.     }
  362.     public function clientForgotPassword($serviceId$username): ?array
  363.     {
  364.         $data = [
  365.             "serviceId" => $serviceId,
  366.             "username" => $username
  367.         ];
  368.         $results $this->restApiPOSTcURL('/plateforme/clientForgotPassword'$data);
  369.         return $results;
  370.     }
  371.     public function clientResetPassword($serviceId$username$oldPassword$newPassword$reqToken$limitToken): ?array
  372.     {
  373.         $data = [
  374.             "serviceId" => $serviceId,
  375.             "username" => $username,
  376.             "oldPassword" => $oldPassword,
  377.             "newPassword" => $newPassword
  378.         ]; 
  379.         $results $this->restApiPOSTcURL('/plateforme/clientResetPassword' $data);
  380.         return $results;
  381.     }
  382.     public function clientInscriptionValidation($serviceId$email$password$code$actif): ?array
  383.     {
  384.         $data = [
  385.             "serviceId" => $serviceId,
  386.             "username" => $email,
  387.             "password" => $password,
  388.             "code" => $code,
  389.             "actif" => $actif
  390.         ];
  391.         $results $this->restApiPOSTcURL('/plateforme/clientInscriptionValidation'$data);
  392.         return $results;
  393.     }
  394.     //Tarifs
  395.     //Tous les tarifs
  396.     public function tarifsPlateforme($serviceId): ?array
  397.     {
  398.         $data = [
  399.             "serviceId" => $serviceId,
  400.         ];
  401.         $results $this->restApiPOSTcURL('/plateforme/tarifsPlateforme'$data);
  402.         return $results;
  403.     }
  404.     public function cbTransaction($data): ?array
  405.     {
  406.         $results $this->restApiPOSTcURL('/plateforme/cbTransaction'$data);
  407.         return $results;
  408.     }
  409.     //Question Mail
  410.     //Test mise a jour lu et repondu
  411.     public function questionsMailMajMessage($serviceId$clientId$complementId$emailId$answered$isRead): ?array
  412.     {
  413.         $data = [
  414.             "serviceId" => $serviceId,
  415.             "clientId" => $clientId,
  416.             "complementId" => $complementId,
  417.             "emailsId" => $emailId,
  418.             "answered" => $answered,
  419.             "isRead" => $isRead
  420.         ];
  421.         $results $this->restApiPOSTcURL('/plateforme/questionsMailMajMessage'$data);
  422.         return $results;
  423.     }
  424.     //Info Mail
  425.     public function questionsMailConseillersListe($serviceId$clientId): ?array
  426.     {
  427.         $data = [
  428.             "serviceId" => $serviceId,
  429.             "clientId" => $clientId
  430.         ];
  431.         $results $this->restApiPOSTcURL('/plateforme/questionsMailConseillersListe'$data);
  432.         return $results;
  433.     }
  434.     //no route found for POST and GET
  435.     public function questionsMailConseiller($serviceId$clientid$complementId): ?array
  436.     {
  437.         $data = [
  438.             "serviceId" => $serviceId,
  439.             "clientId" => $clientid,
  440.             "complementId" => $complementId,
  441.         ];
  442.         $results $this->restApiPOSTcURL('/plateforme/questionsMailConseiller'$data);
  443.         return $results;
  444.     }
  445.     //Envoi de Mail
  446.     public function questionsMailEnvoiMessage($serviceId$clientId$complementId$titre$content$date$cost): ?array
  447.     {
  448.         $data = [
  449.             "serviceId" => $serviceId,
  450.             "clientId" => $clientId,
  451.             "complementId" => $complementId,
  452.             "title" => $titre,
  453.             "content" => $content,
  454.             "date" => $date->format('Y-m-d H:i:s'),
  455.             "client" => "1",
  456.             "answered" => "0",
  457.             "isRead" => "0",
  458.             "messageCost" => $cost
  459.         ];
  460.         $results $this->restApiPOSTcURL('/plateforme/questionsMailEnvoiMessage'$data);
  461.         return $results;
  462.     }
  463.     //Reponse Mail
  464.     public function questionsMailConseillerReponse(): ?array
  465.     {
  466.         $data = [
  467.             "serviceId" => "1010",
  468.             "clientId" => "1006",
  469.             "complementId" => "45",
  470.             "title" => " réponse de test titre",
  471.             "content" => "il va faire beau",
  472.             "date" => "2022-02-22 02:22:22",
  473.             "client" => "0",
  474.             "answered" => "0",
  475.             "isRead" => "0"
  476.         ];
  477.         $results $this->restApiPOSTcURL('/plateforme/questionsMailConseillerReponse'$data);
  478.         return $results;
  479.     }
  480.     //Horoscope
  481.     public function horoscopeJour(): ?array
  482.     {
  483.         $data = [
  484.             "accountId" => $this->accountId
  485.         ];
  486.         $results $this->restApiPOSTcURL('/horoscope/horoscopeJour'$data);
  487.         return $results;
  488.     }
  489.     public function horoscopeHebdomadaire(): ?array
  490.     {
  491.         $data = [
  492.             "accountId" => $this->accountId
  493.         ];
  494.         $results $this->restApiPOSTcURL('/horoscope/horoscopeHebdomadaire'$data);
  495.         return $results;
  496.     }
  497.     public function horoscopeMensuel(): ?array
  498.     {
  499.         $data = [
  500.             "accountId" => $this->accountId
  501.         ];
  502.         $results $this->restApiPOSTcURL('/horoscope/horoscopeMensuel'$data);
  503.         return $results;
  504.     }
  505.     public function request($data$endpoint): ?array
  506.     {
  507.         $results $this->restApiPOSTcURL($endpoint$data);
  508.         return $results;
  509.     }
  510.     public function restApiPOSTcURL($endpoint$data)
  511.     {
  512.         $results = [];
  513.         $this->apiToken $this->session->get('apiToken');
  514.         // ajouter les clés
  515.         $data['apiKey'] =  $this->apiKey;
  516.         $data['apiToken'] =  $this->apiToken;
  517.         $url $this->apiURL $endpoint;
  518.         $dataEncoded json_encode($data);
  519.         $headers = array(
  520.             "Accept: application/json",
  521.             "Content-Type: application/json",
  522.         );
  523.         $curl curl_init($url);
  524.         curl_setopt($curlCURLOPT_POSTtrue);
  525.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  526.         curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
  527.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  528.         curl_setopt($curlCURLOPT_POSTFIELDS$dataEncoded);
  529.         curl_setopt($curlCURLOPT_REFERER$this->baseURL);
  530.         $response curl_exec($curl);
  531.         $curl_error curl_error($curl);
  532.         $curl_errno curl_errno($curl);
  533.         $http_code curl_getinfo($curlCURLINFO_HTTP_CODE);
  534.         curl_close($curl);
  535.         //echo "<br> url:". print_r($url, 1)."<br>";
  536.         if ($response === false) {
  537.             $res =  ['responseCode' => $curl_error'message' => $curl_errno];
  538.             $results[throw new \Exception($res['message'])];
  539.         } else {
  540.             if ($http_code === 200) {
  541.                 $results json_decode($responsetrue);
  542.             } else {
  543.                 $results json_decode($responsetrue);
  544.                 if (!is_array($results)) {
  545.                     $results =  ['responseCode' => $http_code'message' => $results];
  546.                 }
  547.                 if ($http_code === 401) {
  548.                     // Accès non autorisé
  549.                 } else if ($http_code === 403) {
  550.                     // Aucun enregistrement correspondant
  551.                 } else if ($http_code === 404) {
  552.                     // Erreur sauvegarde
  553.                 } else if ($http_code === 409) {
  554.                     // Conflit 
  555.                 } else if ($http_code === 410) {
  556.                     // token n’est plus disponible
  557.                 }
  558.                 //$results [throw new \Exception( $res['message'] )];
  559.             }
  560.         }
  561.         return $results;
  562.     }
  563.     public function restApiPOSTcURLWithOUtToken($endpoint$data)
  564.     {
  565.         $results = [];
  566.         $this->apiToken $this->session->get('apiToken');
  567.         // ajouter les clés
  568.         $data['apiKey'] =  $this->apiKey;
  569.         $url $this->apiURL $endpoint;
  570.         $dataEncoded json_encode($data);
  571.         $headers = array(
  572.             "Accept: application/json",
  573.             "Content-Type: application/json",
  574.         );
  575.         $curl curl_init($url);
  576.         curl_setopt($curlCURLOPT_POSTtrue);
  577.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  578.         curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
  579.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  580.         curl_setopt($curlCURLOPT_POSTFIELDS$dataEncoded);
  581.         curl_setopt($curlCURLOPT_REFERER$this->baseURL);
  582.         $response curl_exec($curl);
  583.         $curl_error curl_error($curl);
  584.         $curl_errno curl_errno($curl);
  585.         $http_code curl_getinfo($curlCURLINFO_HTTP_CODE);
  586.         curl_close($curl);
  587.         //echo "<br> url:". print_r($url, 1)."<br>";
  588.         if ($response === false) {
  589.             $res =  ['responseCode' => $curl_error'message' => $curl_errno];
  590.             $results[throw new \Exception($res['message'])];
  591.         } else {
  592.             if ($http_code === 200) {
  593.                 $results json_decode($responsetrue);
  594.             } else {
  595.                 $results json_decode($responsetrue);
  596.                 if (!is_array($results)) {
  597.                     $results =  ['responseCode' => $http_code'message' => $results];
  598.                 }
  599.                 if ($http_code === 401) {
  600.                     // Accès non autorisé
  601.                 } else if ($http_code === 403) {
  602.                     // Aucun enregistrement correspondant
  603.                 } else if ($http_code === 404) {
  604.                     // Erreur sauvegarde
  605.                 } else if ($http_code === 409) {
  606.                     // Conflit 
  607.                 } else if ($http_code === 410) {
  608.                     // token n’est plus disponible
  609.                 }
  610.                 //$results [throw new \Exception( $res['message'] )];
  611.             }
  612.         }
  613.         return $results;
  614.     }
  615. }