PHP code example of youbuwei / ip-location

1. Go to this page and download the library: Download youbuwei/ip-location library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

youbuwei / ip-location example snippets


'cz88' => [
    'db-path' => '',
]

'enable' => true,



declare(strict_types=1);

return [
    \Youbuwei\IPLocation\LocationApiInterface::class => \Youbuwei\IPLocation\Api\TencentLocation::class,
];

'cache' => [
    'enable' => true,
    'expire' => 86400,
],

'ip-api' => [
    'method' => 'GET',
    'domain' => 'http://ip-api.com',
    'uri' => '/json/',
    'lang' => 'zh-CN',
],

'tencent' => [
    'method' => 'GET',
    'domain' => 'https://apis.map.qq.com',
    'uri' => '/ws/location/v1/ip',
    'key' => '',
    'secret' => '',
],

'baidu' => [
    'method' => 'GET',
    'domain' => 'https://api.map.baidu.com',
    'uri' => '/location/ip',
    'ak' => '',
    'sk' => '',
    'use_sn' => false,
    'coor' => '',
],

'amap' => [
    'method' => 'GET',
    'domain' => 'https://restapi.amap.com',
    'uri' => '/v3/ip',
    'key' => '',
    'secret' => '',
],

'custom' => [
    'method' => 'GET',
    'domain' => '',
    'uri' => '',
    'other' => '',
],



declare(strict_types=1);

namespace Youbuwei\IPLocation;

use Psr\Http\Message\RequestInterface;

interface LocationApiInterface
{
    public function makeRequest($ip): ?RequestInterface;

    public function getLocation(string $location): ?array;
}



declare(strict_types=1);

namespace App\Controller;

use Youbuwei\IPLocation\Location;

class IndexController extends AbstractController
{
    public function __construct(
        protected Location $location
    ) {}

    public function index()
    {
        $location = $this->location->getLocation('66.66.66.66');

        return [
            'location' => $location,
        ];
    }
}
config/autoload/dependencies.php
\Youbuwei\IPLocation\Api\LocalLocation.php::class