retailcrm/geohelper-php-sdk

Geohelper API的PHP客户端

1.0.0 2024-07-30 11:35 UTC

This package is auto-updated.

Last update: 2024-08-30 12:15:52 UTC


README

PHP客户端用于Geohelper API

使用API文档

要求

  • PHP 7.4及以上版本

安装

  1. 获取composer

  2. 在你的项目目录中运行

composer require retailcrm/geohelper-php-sdk ~1.0.0

如果你之前没有使用过composer,请将自动加载器包含到你的项目中。

require 'path/to/vendor/autoload.php';

用法

获取国家

$clientInterface = new \GuzzleHttp\Client();

$client = new RetailCrm\Geohelper\ApiClient(
    $clientInterface,
    'api_key'
);

$response = $client->countriesList();

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()
    );
}