update
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
APP_DEBUG=true
|
||||||
|
|
||||||
|
SERVER_PROCESS_GROUP=''
|
||||||
|
SERVER_PROCESS_USER=''
|
||||||
|
|
||||||
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=xxx
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=ip2location
|
||||||
|
DB_USERNAME=root
|
||||||
|
DB_PASSWORD=xxxxx
|
||||||
|
|
||||||
|
SESSION_DRIVER=file
|
||||||
|
|
||||||
|
REDIS_HOST=center-redis
|
||||||
|
REDIS_PASSWORD=password
|
||||||
|
REDIS_PORT=6379
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace app\controller;
|
namespace app\controller;
|
||||||
|
|
||||||
|
use App\model\Ip2locationDb11Model;
|
||||||
use itbdw\Ip\IpLocation;
|
use itbdw\Ip\IpLocation;
|
||||||
|
use support\Db;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
class Index
|
class Index
|
||||||
@@ -21,4 +23,30 @@ class Index
|
|||||||
|
|
||||||
return json(['ip' => $ip, 'location' => $location]);
|
return json(['ip' => $ip, 'location' => $location]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function location(Request $request, $checkIp = null)
|
||||||
|
{
|
||||||
|
$ip = $request->getRealIp();
|
||||||
|
|
||||||
|
if ($checkIp) {
|
||||||
|
$ip = gethostbyname($checkIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ipNum = ip2long($ip);
|
||||||
|
|
||||||
|
|
||||||
|
$record = Ip2locationDb11Model::query()->where(
|
||||||
|
'ip_from', '<=', $ipNum
|
||||||
|
)->where(
|
||||||
|
'ip_to', '>=', $ipNum
|
||||||
|
)->first();
|
||||||
|
|
||||||
|
if ($record) {
|
||||||
|
$record = $record->toArray();
|
||||||
|
} else {
|
||||||
|
$record = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return json(['ip' => $ip, 'record' => $record]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jhx
|
||||||
|
* @date 2022/7/6 14:53
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class Ip2locationDb11Model extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = FALSE;
|
||||||
|
|
||||||
|
protected $primaryKey = 'ip_from';
|
||||||
|
|
||||||
|
protected $table = 'ip2location_db11';
|
||||||
|
}
|
||||||
+8
-1
@@ -27,7 +27,14 @@
|
|||||||
"php": ">=7.2",
|
"php": ">=7.2",
|
||||||
"workerman/webman-framework": "^1.3.14",
|
"workerman/webman-framework": "^1.3.14",
|
||||||
"monolog/monolog": "^2.0",
|
"monolog/monolog": "^2.0",
|
||||||
"itbdw/ip-database": "^3.0"
|
"itbdw/ip-database": "^3.0",
|
||||||
|
"ip2location/ip2location-php": "^8.3",
|
||||||
|
"psr/container": "^1.1.1",
|
||||||
|
"illuminate/database": "^8.83",
|
||||||
|
"illuminate/pagination": "^8.83",
|
||||||
|
"illuminate/events": "^8.83",
|
||||||
|
"symfony/var-dumper": "^5.4",
|
||||||
|
"vlucas/phpdotenv": "^5.4"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-event": "For better performance. "
|
"ext-event": "For better performance. "
|
||||||
|
|||||||
Generated
+2409
-15
File diff suppressed because it is too large
Load Diff
+22
-1
@@ -12,4 +12,25 @@
|
|||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return [];
|
return [
|
||||||
|
|
||||||
|
'default' => 'mysql',
|
||||||
|
|
||||||
|
'connections' => [
|
||||||
|
|
||||||
|
'mysql' => [
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('DB_PORT', '3306'),
|
||||||
|
'database' => env('DB_DATABASE', 'forge'),
|
||||||
|
'username' => env('DB_USERNAME', 'forge'),
|
||||||
|
'password' => env('DB_PASSWORD', ''),
|
||||||
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
|
'charset' => 'utf8',
|
||||||
|
'collation' => 'utf8_unicode_ci',
|
||||||
|
'prefix' => '',
|
||||||
|
'strict' => true,
|
||||||
|
'engine' => null,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ Route::any('/', [\app\controller\Index::class, 'index']);
|
|||||||
|
|
||||||
Route::any('/check[/{ip}]', [\app\controller\Index::class, 'index']);
|
Route::any('/check[/{ip}]', [\app\controller\Index::class, 'index']);
|
||||||
|
|
||||||
|
Route::any('/location[/{ip}]', [\app\controller\Index::class, 'location']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user