7x/sdk

7x API Suite的PHP SDK

1.6 2023-12-02 05:32 UTC

This package is auto-updated.

Last update: 2024-08-31 00:49:13 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require Build Status

7x API的PHP SDK

要使用此SDK,您需要一个API密钥。请注册https://7x.ax开始使用。

安装

composer require 7x/sdk

用法

时区API

use Psr\Log\LogLevel;
use SevenEx\SDK\Timezone;

$tz = new Timezone('API_KEY', LogLevel::DEBUG);
$result = $tz->get('22.22', '33.33');
// $result is an instance of SevenEx\DTO\Timezone\Timezone.
$result->timezones; // An array of timezones matching the co-ordinates. Mostly just contains a single string.

距离API

按坐标计算距离

use Psr\Log\LogLevel;
use SevenEx\SDK\Distance;

$d = new Distance('API_KEY', LogLevel::DEBUG);
$result = $d->getByCoordinates('22.22', '33.33', '44.44', '55.55', 'km');
// $result is an instance of SevenEx\DTO\Distance\Distance.
$result->distance;
$result->unit; // km if you specified km, or mi if you specified mi. Defaults to km if not specified.

按地址计算距离

use Psr\Log\LogLevel;
use SevenEx\SDK\Distance;

$d = new Distance('API_KEY', LogLevel::DEBUG);
$result = $d->getByAddress('Trafalgar Square, London, UK', 'Tower Bridge, London, UK', 'mi');
// $result is an instance of SevenEx\DTO\Distance\Distance.
$result->distance;
$result->unit; // mi in this case.

地理编码API

按城市/地址字符串进行地理编码

use Psr\Log\LogLevel;
use SevenEx\SDK\Geocode;

$g = new Geocode('API_KEY', LogLevel::DEBUG);
$result = $g->geocode('Trafalgar Square, London, UK');
// $result is an instance of SevenEx\DTO\Geocode\GeocodeCollection. This contains an array of objects.
foreach ($result->objects as $geocoded) {
    var_dump($geocoded->coordinates); // Instance of SevenEx\DTO\Common\Coordinates
    var_dump($geocoded->location); // Instance of SevenEx\DTO\Geocode\Location
}

地理编码搜索(用于构建搜索建议/自动完成功能)

use Psr\Log\LogLevel;
use SevenEx\SDK\Geocode;

$g = new Geocode('API_KEY', LogLevel::DEBUG);
$result = $g->search('Lon');
// $result is an instance of SevenEx\DTO\Geocode\GeocodeCollection. This contains an array of objects.
foreach ($result->objects as $geocoded) {
    var_dump($geocoded->coordinates); // Instance of SevenEx\DTO\Common\Coordinates
    var_dump($geocoded->location); // Instance of SevenEx\DTO\Geocode\Location
}

按坐标反向地理编码

use Psr\Log\LogLevel;
use SevenEx\SDK\Geocode;

$g = new Geocode('API_KEY', LogLevel::DEBUG);
$result = $g->reverse('55.555555', '33.3333333');
// $result is an instance of SevenEx\DTO\Geocode\GeocodeCollection. This contains an array of objects.
foreach ($result->objects as $reversed) {
    var_dump($reversed->coordinates); // Instance of SevenEx\DTO\Common\Coordinates
    var_dump($reversed->location); // Instance of SevenEx\DTO\Geocode\Location
}

数字

use Psr\Log\LogLevel;
use SevenEx\SDK\Numbers;

$g = new Numbers('API_KEY', LogLevel::DEBUG);
$result = $g->arabicToLatin('١٢٣٤٥٦٧٨٩٠');
$result = $g->latinToArabic('1234567890');
// $result is an instance of SevenEx\DTO\Numbers\Arabic.
$result = $g->arabicToHtml('١٢٣٤٥٦٧٨٩٠');
// $result is an instance of SevenEx\DTO\Numbers\Html.

日期和时间

use Psr\Log\LogLevel;
use SevenEx\SDK\DateAndTime;

$g = new DateAndTime('API_KEY', LogLevel::DEBUG);
$result = $g->byTimezone('Europe/London'); // or
$result = $g->byAddress('Trafalgar Square, London, UK'); // or
$result = $g->byCoordinates('51.507351', '-0.127758');
// $result is an instance of SevenEx\DTO\DateAndTime\DateAndTime.

地理位置

use Psr\Log\LogLevel;
use SevenEx\SDK\Geolocate;

$f = new Geolocate('API_KEY', LogLevel::DEBUG);
$result = $f->ip('109.74.197.73');
// Result is an instance of SevenEx\DTO\Geolocate\Geolocate.

机场

use Psr\Log\LogLevel;
use SevenEx\SDK\Airports;

$a = new Airports('API_KEY', LogLevel::DEBUG);
$a->airport('LHR'); // returns is an instance of SevenEx\DTO\Airports\Airports
$a->airports(type: 'large_airport', country: 'ae'); // returns is an instance of SevenEx\DTO\Airports\SingleAirports
$a->types(); // returns is an instance of SevenEx\DTO\Airports\Types
$a->countries(); // returns is an instance of SevenEx\DTO\Airports\CountriesCollection
$a->country('ae'); // returns is an instance of SevenEx\DTO\Airports\CountriesCollection
$a->continents(); // returns is an instance of SevenEx\DTO\Airports\ContinentsCollection
$a->continent('eu'); // returns is an instance of SevenEx\DTO\Airports\ContinentCollection