rubin / opensky

此包最新版本(1.0.2)没有提供许可证信息。

OpenSky REST API 连接器

1.0.2 2024-07-22 13:01 UTC

This package is auto-updated.

Last update: 2024-09-22 13:15:32 UTC


README

Build Status Latest Stable Version Coverage Status PHP Version Require

PHP 实现的 OpenSky Network REST API。此库基于 REST API 文档

安装

使用 composer

composer require rubin/opensky

用法

创建 API 连接器

$openSkyApi = new \OpenSky\OpenSkyApi();

设置凭据(可选)

$openSkyApi->setCredentials('{username}', '{password}');

参考 限制,了解为什么/何时用户账户会被优先考虑。

示例

包含时间和飞机的查询示例: https://opensky-network.org/api/states/all?time=1458564121&icao24=3c6444

echo "ICAO\tLongitude\tLatitude\n";
foreach ($openSkyApi->getStatesAll(time: 1458564121, icao24: '3c6444')->getStates() as $state) {
    printf(
        "%s\t%f\t%f\n",
        $state->getIcao24(),
        $state->getLongitude(),
        $state->getLatitude()
    );
}

覆盖瑞士的边框框查询示例: https://opensky-network.org/api/states/all?lamin=45.8389&lomin=5.9962&lamax=47.8229&lomax=10.5226

echo "ICAO\tLongitude\tLatitude\n";
foreach ($openSkyApi->getStatesAll(bBox: new \OpenSky\BoundingBox(45.8389, 47.8229, 5.9962, 10.5226))->getStates() as $state) {
    printf(
        "%s\t%f\t%f\n",
        $state->getIcao24(),
        $state->getLongitude(),
        $state->getLatitude()
    );
}

检索两架特定飞机的状态: https://opensky-network.org/api/states/all?icao24=3c6444&icao24=3e1bf9

echo "ICAO\tLongitude\tLatitude\n";
foreach ($openSkyApi->getStatesAll(icao24: ['3c6444', '3e1bf9'])->getStates() as $state) {
    printf(
        "%s\t%f\t%f\n",
        $state->getIcao24(),
        $state->getLongitude(),
        $state->getLatitude()
    );
}

获取 2018 年 1 月 29 日中午 12 点到下午 1 点的航班: https://opensky-network.org/api/flights/all?begin=1517227200&end=1517230800

echo "ICAO\tDep  - Arr\n";
foreach ($openSkyApi->getFlightsAll(begin: 1517227200, end: 1517230800)->getFlights() as $flight) {
    printf(
        "%s\t%s - %s\n",
        $flight->getIcao24(),
        $flight->getEstDepartureAirport() ?: '----',
        $flight->getEstArrivalAirport() ?: '----'
    );
}

获取 2018 年 1 月 29 日 D-AIZZ(3c675a)的航班: https://opensky-network.org/api/flights/aircraft?icao24=3c675a&begin=1517184000&end=1517270400

echo "ICAO\tDep  - Arr\n";
foreach ($openSkyApi->getFlightsAircraft(icao24: '3c675a', begin: 1517227200, end: 1517230800)->getFlights() as $flight) {
    printf(
        "%s\t%s - %s\n",
        $flight->getIcao24(),
        $flight->getEstDepartureAirport() ?: '----',
        $flight->getEstArrivalAirport() ?: '----'
    );
}

获取 2018 年 1 月 29 日中午 12 点到下午 1 点到达法兰克福国际机场(EDDF)的所有航班: https://opensky-network.org/api/flights/arrival?airport=EDDF&begin=1517227200&end=1517230800

echo "ICAO\tDep  - Arr\n";
foreach ($openSkyApi->getFlightsArrival(airport: 'EDDF', begin: 1517227200, end: 1517230800)->getFlights() as $flight) {
    printf(
        "%s\t%s - %s\n",
        $flight->getIcao24(),
        $flight->getEstDepartureAirport() ?: '----',
        $flight->getEstArrivalAirport() ?: '----'
    );
}

获取 2018 年 1 月 29 日中午 12 点到下午 1 点从法兰克福国际机场(EDDF)起飞的所有航班: https://opensky-network.org/api/flights/departure?airport=EDDF&begin=1517227200&end=1517230800

echo "ICAO\tDep  - Arr\n";
foreach ($openSkyApi->getFlightsDeparture(airport: 'EDDF', begin: 1517227200, end: 1517230800)->getFlights() as $flight) {
    printf(
        "%s\t%s - %s\n",
        $flight->getIcao24(),
        $flight->getEstDepartureAirport() ?: '----',
        $flight->getEstArrivalAirport() ?: '----'
    );
}