This commit is contained in:
jhx
2022-07-06 15:31:54 +08:00
parent deaef05e01
commit a4c6f6b752
8 changed files with 2505 additions and 17 deletions
+17
View File
@@ -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
+28
View File
@@ -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]);
}
} }
+19
View File
@@ -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
View File
@@ -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
View File
File diff suppressed because it is too large Load Diff
+22 -1
View File
@@ -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,
],
]
];
+2
View File
@@ -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.