tvup/ewiiapi
最新稳定版本:v2.1.1
Composer 安装命令:
composer require tvup/ewiiapi
包简介
API for getting consumption data as an Ewii customer
README 文档
README
This repository contains PHP library code to facilitate communication with Ewii Api's. It is intended to be loaded into another PHP application as a composer package through packagist. The API exposes functions for login and for getting consumption data and the requests neccesary in between.
Use at own risk
Prerequisites
Requires an account at https://selvbetjening.ewii.com/Login with the possibility to login with E-mail and password.
If you are an existing customer but doesn't have the setup with login using e-mail and password, follow these steps:
- Login as normal (nem-id)
- In upper right corner click "Min profil" (My profile)
- Choose "Mine oplysninger" (My information)
- Find the card "Tildel andre adgang" (Grant access to others) and click "Tildel adgang" (Grant access)
- Follow the steps to setup an account which can access your consumption data. I don't know if it will break anything if you choose an email-adress which Ewii already has - probably choose another email than your primary or use the "google dot"-trick if you're familiary with that.
This should set you up with a secondary login using email and password.
Installation with composer
composer require tvup/ewiiapi
Work-flow of the api
Obviously you will need to make a call through the api to login. This will set a cookie which is used to authenticate you during all other requests.
The flow has these steps:
- Login
- Get "AddressPickerViewModel" - a list of your addresses - probably only has one if you don't have products at multiple addresses
- For each address is a list of installations. Again probably only one, but there shouldn't be much imagination to imagine that you could electricity and internet broadband or multiple electricity installations each with their own meter.
- Pick "the one"
- Set "the one" with call to "setSelectedAddressPickerElement" - somehow this seems mandatory else the next request will fail
¯\_(ツ)_/¯ - Get metadata for the meter
- Use some of the metadat to get the consumption data
Example code
require_once 'vendor/autoload.php';
$ewiiApi = new Tvup\EwiiApi\EwiiApi();
//$ewiiApi->setDebug(true);
//1
$ewiiApi->login('AN_EMAIL_ADDRESS','A_PASSWORD');
//2
$addressElement = $ewiiApi->getAddressPickerViewModel();
//3
$ewiiApi->setSelectedAddressPickerElement($addressElement);
//4
$consumptionMeterMetaData = $ewiiApi->getConsumptionMeters();
//5
$response = $ewiiApi->getConsumptionData('csv', $consumptionMeterMetaData);
print_r($response);
Cookies and login
The api is handling the cookies from Ewii and saves them to disk. If a cookie is present at disk, it will be used and login will not be called even though you hit the method public function login(string $email, string $password): void
Please remember, that this api wasn't created for you to make tons of requests to Ewii's services and drawing attention.
Feedback
Always welcome. This project was created because I was curious if it was possible, and I tend to lose interest when the goal has been accomplished. You wan't something differently - you can make a pull-request we can share a bit of each other's understanding.
Appreciate it?
Great. Glad I could help.
I want to make a donation as a sign of appreciation
Don't
I insist
It will probably be spent on beer: https://www.buymeacoffee.com/tvup
tvup/ewiiapi 适用场景与选型建议
tvup/ewiiapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tvup/ewiiapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tvup/ewiiapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-09