xvilo / greenchoice
Greenchoice API 客户端
0.4.0
2020-06-30 07:43 UTC
Requires
- php: ^7.4
- php-http/cache-plugin: ^1.4
- php-http/client-common: ^1.6 || ^2.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.1 || ^2.0
- psr/cache: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- cache/array-adapter: ^0.4
- friendsofphp/php-cs-fixer: ^2.16
- guzzlehttp/psr7: ^1.2
- php-http/guzzle6-adapter: ^1.0 || ^2.0
- php-http/mock-client: ^1.2
- phpunit/phpunit: ^7.0 || ^8.0
This package is auto-updated.
Last update: 2024-09-29 05:42:45 UTC
README
一个 Greenchoice API 包装器,请注意目前尚无官方公开API。然而,此API客户端是通过检查他们的应用的网络流量制作的。
安装
您可以通过composer安装此包,最简单的方法是
composer require xvilo/greenchoice
用法
一些用法示例
<?php declare(strict_types=1); use Greenchoice\HttpClient\Plugin\Authentication\GrantType\Password; require_once 'vendor/autoload.php'; $client = new Greenchoice\Client(); $clientToken = $client->authentication->requestToken( 'MobileApp', 'A6E60EBF73521F57', 'xxxxx-xxx-xxx-xxxx-xxxxxxxxxx', new Password(), 'you@example.com', 'S0mes3c#password' ); // Authenticate $client->authenticate($clientToken['access_token']); // Get contracts $contracts = $client->customer->getContracts(); if (count($contracts) === 0) { die('No contracts found for this customer'); } $contractId = $contracts[0]['Id']; $customerId = $contracts[0]['Klantnummer']; echo sprintf("Using contract[ID=%s] for customer[ID=%s]", $contractId, $customerId) . PHP_EOL; // Get approved contract $approvedContract = $client->contracts->getApproved($contractId); echo sprintf("Contract[ID=%s] has %s approved contract(s)", $contractId, count($approvedContract)) . PHP_EOL; // Get contract features $contractFeatures = $client->features->getByContractId($contractId); echo sprintf("Contract[ID=%s] has %s contract feature(s)", $contractId, count($contractFeatures)) . PHP_EOL; // Get contract counters $contractCounters = $client->readings->getCounters($contractId); echo sprintf("For contract[ID=%s] there is %s registered meter(s)", $contractId, count($contractCounters)) . PHP_EOL; // get contract readings $contractReadings = $client->readings->getCounterData($contractId); echo sprintf("Last known meter readings since: \n\n - %s:\n - high: %s\n - low: %s", $contractReadings[0]['DatumInvoer'], $contractReadings[0]['MeterstandenOutput'][0]['Hoog'], $contractReadings[0]['MeterstandenOutput'][0]['Laag']) . PHP_EOL;
将输出
Using contract[ID=1234567] for customer[ID=67890] Contract[ID=1234567] has 0 approved contract(s) Contract[ID=1234567] has 4 contract feature(s) For contract[ID=1234567] there is 1 registered meter(s) Last known meter readings since: - 2020-06-15T00:00:00: - high: 123456 - low: 1234