bigdatacloudapi/php-api-client

BigDataCloud API的PHP客户端封装

1.0.0 2019-04-06 10:15 UTC

This package is auto-updated.

Last update: 2024-09-13 04:09:48 UTC


README

一个用于连接BigDataCloud(BigDataCloud)提供的API服务的PHP客户端。

BigDataCloud提供哪些API服务?

BigDataCloud提供了一系列非常实用且快速的API,这些API可以在后端和前端场景中使用。从实时验证客户输入到下一代IP地理定位技术,BigDataCloud都有适合您需求的API。

您可以使用免费API密钥访问所有BigDataCloud API。要获取您的API密钥,请访问您的账户并从您的账户仪表板中检索它。如果您还不是客户,加入是完全免费的。

BigDataCloud API包

所有BigDataCloud API都捆绑成五个不同的API包。每个API包都有自己的订阅计划和定价。

您可以在各自的API包页面上找到更多详细信息。

文档

有关此API客户端的特定文档,请参阅以下内容。有关API的更具体文档,包括端点、请求和响应数据,请访问相应的API包页面。

身份验证/识别

要使用此API客户端,您必须拥有BigDataCloud API密钥。要获取您的个人密钥,请访问您的账户仪表板。如果您还不是客户,加入是完全免费的。

在初始化php API客户端时简单地提供此密钥,它将被包含在所有对BigDataCloud API服务器的请求中。请参见下面的示例。

通过Composer安装

composer require bigdatacloudapi/php-api-client

手动安装

  1. 下载包,将内容提取到相关文件夹
  2. 在您的PHP脚本中需要"(extracted-location)/src/Client.php"
  3. 如下示例使用\BigDataCloud\Api\命名空间初始化新客户端

示例用法

<?php

//Installed via Composer
require_once __DIR__ . '/vendor/autoload.php';

//Installed manually
//Using composer installed location for example, simply reference the /src/Client.php where extracted/installed instead.
//require_once __DIR__ . '/vendor/bigdatacloudapi/php-api-client/src/Client.php';

$apiKey = "XXX"; // Your api key found at: https://www.bigdatacloud.com/account

$client = new \BigDataCloud\Api\Client($apiKey);


/*
Can specify the api endpoint using either camelised magic methods, or by calling the communicate command directly.
Example magic method: "GET" from "ip-geolocation-full" endpoint becomes: getIpGeolocationFull();
*/

//$result=$client->communicate('ip-geolocation-full','GET',['ip'=>'8.8.8.8']);

$result=$client->getIpGeolocationFull(['ip'=>'8.8.8.8']);

var_dump($result);

示例输出

{
    "ip": "8.8.8.8",
    "country": {
        "isoAlpha2": "US",
        "isoAlpha3": "USA",
        "m49Code": 840,
        "isoName": "United States of America (the)",
        "isoAdminLanguages": [
            {
                "isoAlpha3": "eng",
                "isoAlpha2": "en",
                "isoName": "English"
            }
        ],
        "unRegion": "Americas/Northern America",
        "currency": {
            "numericCode": 840,
            "code": "USD",
            "name": "US Dollar",
            "minorUnits": 2
        },
        "wbRegion": {
            "id": "NAC",
            "iso2Code": "XU",
            "value": "North America"
        },
        "wbIncomeLevel": {
            "id": "HIC",
            "iso2Code": "XD",
            "value": "High income"
        },
        "callingCode": "1",
        "countryFlagEmoji": "🇺🇸"
    },
    "location": {
        "isoPrincipalSubdivision": "California",
        "isoPrincipalSubdivisionCode": "US-CA",
        "city": "Mountain View",
        "postcode": "94043",
        "latitude": 37.42,
        "longitude": -122.09,
        "timeZone": {
            "ianaTimeId": "America/Los_Angeles",
            "displayName": "(UTC-08:00) Pacific Time (US & Canada)",
            "effectiveTimeZoneFull": "Pacific Daylight Time",
            "effectiveTimeZoneShort": "PDT",
            "UtcOffsetSeconds": -25200,
            "UtcOffset": "-07",
            "isDaylightSavingTime": true,
            "localTime": "2019-04-06T04:06:39.1691744"
        }
    },
    "lastUpdated": "2019-04-06T09:09:36.1877959Z",
    "network": {
        "registry": "ARIN",
        "registryStatus": "assigned",
        "registeredCountry": "US",
        "registeredCountryName": "United States of America (the)",
        "organisation": "Google LLC",
        "isReachableGlobally": true,
        "isBogon": false,
        "bgpPrefix": "8.8.8.0/24",
        "bgpPrefixNetworkAddress": "8.8.8.0",
        "bgpPrefixLastAddress": "8.8.8.255",
        "totalAddresses": 256,
        "carriers": [
            {
                "asn": "AS15169",
                "asnNumeric": 15169,
                "organisation": "Google LLC",
                "name": "GOOGLE",
                "registry": "ARIN",
                "registeredCountry": "US",
                "registeredCountryName": "United States of America (the)",
                "registrationDate": "2000-03-30",
                "registrationLastChange": "2012-02-25",
                "totalIpv4Addresses": 8698103,
                "totalIpv4Prefixes": 435,
                "totalIpv4BogonPrefixes": 0,
                "rank": 53,
                "rankText": "#53 out of 62,872"
            }
        ],
        "viaCarriers": [
            {
                "asn": "AS7018",
                "asnNumeric": 7018,
                "organisation": "ATT Services Inc.",
                "registeredCountry": "US",
                "registeredCountryName": "United States of America (the)",
                "rank": 2
            },
       		/*........*/
            {
                "asn": "AS31019",
                "asnNumeric": 31019,
                "organisation": "Paulus M. Hoogsteder trading as Meanie",
                "registeredCountry": "NL",
                "registeredCountryName": "Netherlands (the)",
                "rank": 51153
            }
        ]
    },
    "confidence": "low",
    "confidenceArea": [
        {
            "latitude": 18.0256672,
            "longitude": -66.5275345
        },
        /*........*/
        {
            "latitude": 18.0256672,
            "longitude": -66.5275345
        }
    ],
    "securityThreat": "unknown",
    "hazardReport": {
        "isKnownAsTorServer": false,
        "isKnownAsProxy": false,
        "isKnownAsMailServer": false,
        "isKnownAsPublicRouter": false,
        "isBogon": false,
        "isUnreachable": false
    }
}