Compare commits

..

No commits in common. "main" and "v0.6.1" have entirely different histories.
main ... v0.6.1

4 changed files with 1251 additions and 93 deletions

View File

@ -1,5 +1,5 @@
{
"name": "paidian/php-internal-api-client",
"name": "arch/php-internal-api-client",
"type": "library",
"require": {
"guzzlehttp/guzzle": "^6.3",

1194
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,27 +15,6 @@ class InternalApi
app()->configure('internal_api');
}
private function isClientIPPermitted($ip)
{
if (!app()->environment('production', 'staging')) {
return true;
}
if (Str::startsWith($ip, [
'127.0.0.1',
//局域网
'192.168.',
//vpc
'10.0.',
//pod network
'172.20.',
//北京办公区
'172.16.'
])) {
return true;
}
return false;
}
/**
* Handle an incoming request.
*
@ -46,8 +25,11 @@ class InternalApi
public function handle($request, Closure $next)
{
$ip = $request->getClientIp();
if (!$this->isClientIPPermitted($ip)) {
return new JsonResponse("$ip is forbidden", 403);
if (!Str::startsWith($ip, [
'127.0.0.', '192.168.', '10.0.'
])) {
return new JsonResponse('', 404);
}
$params = $request->all();
@ -60,7 +42,7 @@ class InternalApi
if (empty($params['timestamp'])) {
$data = ['error' => 'require time',];
return new JsonResponse($data, 403);
} else if (intval($params['timestamp']) + 60 < time()) {
} elseif (intval($params['timestamp']) + 60 < time()) {
$data = ['error' => 'sign expired',];
return new JsonResponse($data, 403);
}

View File

@ -2,26 +2,8 @@
namespace PdInternalApi;
use Illuminate\Http\Request;
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot(){
Request::setTrustedProxies([
//pod network
'172.20.0.0/16',
//vpc
'10.0.0.0/16',
//local
'127.0.0.1',
//北京办公区
'172.16.0.0/16',
//aliyun slb
'100.116.0.0/16',
], Request::HEADER_X_FORWARDED_ALL);
}
/**
* Register any application services.
*