paulogic/esios

访问 Esios API 库

v1.0.0 2018-02-23 17:14 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:41:52 UTC


README

本库提供了一些实用工具,用于访问 Esios 平台(系统运营商信息系统)的信息。

  • 版本 1.0

设置

  • 安装

      composer require paulogic/esios
    
  • 依赖

    • php >=5.6 with 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

可以在 EsiosCallTypes 中添加新的调用类型以及相应的 URL 路径。

直接调用 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 发出的认证令牌