dmamontov / geohelper-api-client-php
此包已废弃,不再维护。未建议替代包。
Geohelper API 的 PHP 客户端
1.0.0
2016-10-06 10:17 UTC
Requires
- php: >=5.3.0
- ext-curl: *
This package is auto-updated.
Last update: 2022-01-18 01:48:47 UTC
README
PHP客户端用于Geohelper API。
使用 API 文档
要求
- PHP 5.3 及以上
- PHP 的 cURL 支持
安装
-
获取 composer
-
在项目目录中运行
composer require dmamontov/geohelper-api-client-php ~1.0.0
如果您之前未使用过 composer
,请将自动加载器包含到您的项目中。
require 'path/to/vendor/autoload.php';
用法
获取国家
$client = new \Geohelper\ApiClient( 'api_key' ); try { $response = $client->countriesList(); } catch (\Geohelper\Exception\CurlException $e) { echo "Connection error: " . $e->getMessage(); } if ($response->isSuccessful()) { $countries = isset($response['result']) ? $response['result'] : array(); foreach ($countries as $country) { echo $country['name']; } } else { echo sprintf( "Error: [HTTP-code %s] %s", $response->getStatusCode(), $response->getErrorMsg() ); }