PHP backend proxy for Huawei FusionSolar NB API with session handling, caching and a Morocco proxy.
docker build -t fusion-solar-api .
docker run -p 8096:8096 \
-e FS_BASE=https://intl.fusionsolar.huawei.com \
-e FS_USER=your_user \
-e FS_CODE=your_code \
-e MA_PROXY=http://154.70.204.15:3128 \
fusion-solar-apiFor local development without Docker:
export FS_BASE=https://intl.fusionsolar.huawei.com
export FS_USER=your_user
export FS_CODE=your_code
export MA_PROXY=http://154.70.204.15:3128
composer install
php -S localhost:8096 -t app app/api/index.phpGET /api/stations?page=1GET /api/stations/:code/overviewGET /api/stations/:code/devicesGET /api/stations/:code/alarms?levels=1,2,3,4GET /api/healthz
FS_BASE– FusionSolar NB base URLFS_USER– login user (from FusionSolar)FS_CODE– login system codeMA_PROXY– HTTP proxy (e.g.http://154.70.204.15:3128)CACHE_TTL_SECONDS– cache time for NB responsesCACHE_BACKEND–file(default, stored inapp/storage/cache, TTL fromCACHE_TTL_SECONDS) ormemoryFRONTEND_ORIGIN– exact origin allowed by CORSAPP_VERSION– version string exposed by/healthzRATE_LIMIT_PER_MINUTE– requests per minute per IP for/api/*(0 disables)
Credentials are loaded from environment at runtime and are not stored in this repo.
All outbound HTTP requests go through MA_PROXY. The backend logs in to FusionSolar once, captures the xsrf-token (or XSRF-TOKEN cookie) and sends XSRF-TOKEN on every upstream call.
curl http://localhost:8096/api/stations?page=1
curl http://localhost:8096/api/stations/STATION_CODE/overview
curl http://localhost:8096/api/stations/STATION_CODE/devices
curl http://localhost:8096/api/stations/STATION_CODE/alarms?levels=1,2
curl http://localhost:8096/api/healthzA simple smoke script is available in tests/smoke.sh to exercise /api/stations and /api/healthz when the server is running.