pablogic / esios
v1.0.0
2018-02-23 17:14 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- monolog/monolog: ^1.22
- phpunit/phpunit: >=5.7
This package is not auto-updated.
Last update: 2024-09-21 14:48:53 UTC
README
该库提供了一些工具来访问 Esios 平台(系统运营商信息系统)的信息。
- 版本 1.0
设置
安装
composer require paulogic/esios依赖
- php >=5.6 且支持 curl
如何使用
使用 EsiosHelperFactory
通过包含的 Helper Factory 类,以最简单的方式发起调用并接收格式化的响应(日期-值 php 数组)
#!php
$token = 'AUTHENTICATION TOKEN';
//Prepare the factory
$factory = new Esios\EsiosHelperFactory($token);
//Create a helper to issue calls to obtain the list of prices
$helper = $factory->getEsiosCaller(Esios\EsiosCallTypes::PVPC_20A_PRICES);
$params = [
'start_date' => '2017-04-01T01:00',
'end_date' => '2017-04-01T05:00'
];
$data = $helper->get($params);
//Create a helper to issue calls to obtain the list of indicators
$helper = $factory->getEsiosCaller(Esios\EsiosCallTypes::INDICATORS_LIST);
$params = [
'text' => 'facturacion de energia'
];
$data = $helper->get($params);
可能的调用类型列表在抽象类 EsiosCallTypes 中定义
- PVPC_20A_PRICES
- PVPC_20DHA_PRICES
- PVPC_20DHS_PRICES
- PVPC_20A_PROFILES
- PVPC_20DHA_PROFILES
- PVPC_20DHS_PROFILES
- PVPC_20A_PEAJESACCESO
- PVPC_20DHA_PEAJESACCESO
- PVPC_20DHS_PEAJESACCESO
- INDICATORS_LIST
可以将新的调用类型及其对应的 URL 路径添加到 EsiosCallTypes 中。
直接调用 Esios REST API
您可以使用 EsiosCallService 工具类直接向 REST API 发起调用
#!php
$token = 'AUTHENTICATION TOKEN';
//optional config, may be empty
$config = [
'timeout' => 10,
'timezone' => 'Atlantic/Canary'
];
$callService = new Esios\Service\EsiosCallService($token, $config);
$params = [
'start_date' => '2017-04-23',
'end_date' => '2017-04-24',
];
//Direct call to indicator 1013 (prices of rate 20A)
$data = $callService->getData('/indicators/1013', $params);
示例
您可以在功能示例列表中找到如何单独使用这些类的方法
- 创建 API 访问器并返回原始数据
- 创建格式化原始数据的格式化器
- 使用自定义日志记录器
查看示例文件
examples/examples.php
运行测试
vendor/bin/phpunit
检查 API 响应测试
有一组测试用于检查实际 Esios API 调用的响应格式。这些测试需要在线连接和有效的认证令牌。要激活这些测试
- 修改 phpunit.xml
- 删除排除组 'onlinecheck'
- 将 TOKEN 替换为 Esios 发布的认证令牌