mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 15:10:54 +00:00
1. models 关系规范化; 2. 本地-在线 订单处理改写; 3. 优化用户界面节点的查表操作; 4. 半修复 VNet SSR版需要面板主动提交用户信息变动的问题;(节点等级,用户分组,Node信息修改 主动通知节点尚未添加); 5. 简化并提取出了 返利佣金相关处理逻辑;
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\Node;
|
|
use App\Models\NodeAuth;
|
|
use Closure;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Response;
|
|
|
|
class WebApi {
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param $request
|
|
* @param Closure $next
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next) {
|
|
$id = $request->id;
|
|
$key = $request->header('key');
|
|
$time = $request->header('timestamp');
|
|
|
|
if(!isset($key)){// 未提供 key
|
|
return $this->returnData('Your key is null!');
|
|
}
|
|
|
|
if(!isset($id)){// 未提供 node
|
|
return $this->returnData('Your Node Id is null!');
|
|
}
|
|
|
|
$node = Node::find($id);
|
|
if(!$node){// node不存在
|
|
return $this->returnData('Unknown Node!');
|
|
}
|
|
|
|
$nodeAuth = NodeAuth::whereNodeId($id)->first();
|
|
if(!$nodeAuth || $key !== $nodeAuth->key){// key不存在/不匹配
|
|
return $this->returnData('Token is invalid!');
|
|
}
|
|
|
|
if(abs($time - time()) >= 300){// 时差超过5分钟
|
|
return $this->returnData('Please resynchronize the server time!');
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
|
|
// 返回数据
|
|
public function returnData($message): JsonResponse {
|
|
return Response::json(['status' => 'fail', 'code' => 404, 'message' => $message]);
|
|
}
|
|
}
|