1 line
4.1 KiB
JSON
1 line
4.1 KiB
JSON
{"uuid":"bb27b906-efd5-4c58-8370-e439b4bbedef","slug":"barry-api-php","title":"Barry Api.php","author":"cedric@abonnel.fr","published":true,"published_at":"2021-03-03 21:26:26","created_at":"2021-03-03 21:26:26","updated_at":"2021-03-03 21:26:26","revisions":[],"cover":"","files_meta":[],"external_links":[],"seo_title":"","seo_description":"","og_image":"","category":"Électronique","content":"# Barry Api.php\n\n```PHP\n<?PHP\n\n$priceArea = array(\n 'dk' => 'DK_NORDPOOL_SPOT_DK1',\n 'fr' => 'FR_EPEX_SPOT_FR'\n);\n\nfunction getMethod($postData) {\n- Le token suivant n'est pas valide. Il faut le modifier avec le votre, obtenu dans l'application Barry Eenrgy\n $authToken = 'Bx6Da6v0h34MM7OhAjCaN9zak+IZLNe9tUlCebw7+LiP8+5SH6BcdNrOY85s9q7Sdfrmc/yyjWrJROlJ9vhlRCYY310TsHcGNodMzr3cGfZOwVYNPYWxGxcZHO94p6W98SJC/TdIYhsE+tRnvMMKHktTdkRjmMolHAtWpYyFzDw=';\n $url = \"https:*jsonrpc.barry.energy/json-rpc\";\n\n echo \"<pre>\";\n echo '<p>La méthode appelée : </p>';\n print_r(json_encode($postData));\n echo \"</pre></br>\";\n\n- Create the context for the request\n $context = stream_context_create(array(\n 'http' => array(\n 'method' => 'POST',\n 'header' => \"Authorization: Bearer {$authToken}\\r\\n\".\n \"Content-Type: application/json\\r\\n\",\n 'content' => json_encode($postData)\n )\n ));\n\n- Send the request\n $response = file_get_contents($url, FALSE, $context);\n\n- Check for errors\n if($response === FALSE){\n die('Error');\n }\n return $response;\n}\n\nfunction translateDate($strDate) {\n $nomJourSemaineEN = array(\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\");\n $nomJourSemaineFR = array(\"Lundi\", \"Mardi\", \"Mercredi\", \"Jeudi\", \"Vendredi\", \"Samedi\", \"Dimanche\");\n $nomMoisEN = array(\"January\",\"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\");\n $nomMoisFR = array(\"Janvier\",\"Février\", \"Mars\", \"Avril\", \"Mai\", \"Juin\", \"Juillet\", \"Août\", \"Septembre\", \"Octobre\", \"Novembre\", \"Décembre\");\n $strDate = str_ireplace($nomMoisEN, $nomMoisFR, $strDate);\n $strDate = str_ireplace($nomJourSemaineEN, $nomJourSemaineFR, $strDate);\n return $strDate;\n}\n\nsetlocale(LC_ALL,'fr');\n\n*$dateJour=date('d F Y', strtotime('31-12-2018'));\n$dateJour=date('d F Y');\n$dateJourDemain=date('d F Y', strtotime('+1 day', strtotime($dateJour)));\n\necho \"<h1>Métriques de Barry Energy</h1>\";\necho \"<p>Rapport établi le \".translateDate(date('l d F Y')).\" à \".date('H:i:s').\"</p>\";\n\necho \"<h2>Etat de l'abonnement</h2>\";\n\n* The data to send to the API getMeteringPoints\n$postData = array('method' => 'co.getbarry.api.v1.OpenApiController.getMeteringPoints'\n , 'id' => 0\n , 'jsonrpc' => '2.0'\n , 'params' => array()\n);\n\n$response = getMethod($postData);\n* Decode the response\n$responseData = json_decode($response, TRUE);\n\necho \"<pre>\";\necho '<p>La réponse : </p>';\nprint_r($responseData);\necho \"</pre>\";\n\necho \"<h2>Consommation du $dateJour </h2>\";\n\n* The data to send to the API getAggregatedConsumption\n$postData = array('method' => 'co.getbarry.api.v1.OpenApiController.getAggregatedConsumption'\n , 'id' => 0\n , 'jsonrpc' => '2.0'\n , 'params' => array(date(DATE_ATOM, strtotime($dateJour)), date(DATE_ATOM, strtotime($dateJourDemain)))\n);\n\n$response = getMethod($postData);\n* Decode the response\n$responseData = json_decode($response, TRUE);\n\necho \"<pre>\";\necho '<p>La réponse : </p>';\nprint_r($responseData);\necho \"</pre>\";\n\necho \"<h2>Prix du $dateJour </h2>\";\n\n* The data to send to the API getPrice\n$postData = array('method' => 'co.getbarry.api.v1.OpenApiController.getPrice'\n , 'id' => 0\n , 'jsonrpc' => '2.0'\n , 'params' => array($priceArea['fr'], date(DATE_ATOM, strtotime($dateJour)), date(DATE_ATOM, strtotime($dateJourDemain)) )\n \n);\n\n$response = getMethod($postData);\n* Decode the response\n$responseData = json_decode($response, TRUE);\n\necho \"<pre>\";\necho '<p>La réponse : </p>';\nprint_r($responseData);\necho \"</pre>\";\n```","featured":false,"tags":[]} |