4 changed files with 59 additions and 31 deletions
-
23app/Http/Controllers/Controller.php
-
23app/Http/Middleware/ApiAuth.php
-
38app/Http/Middleware/ApiBase.php
-
6routes/api.php
@ -0,0 +1,38 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Middleware; |
|||
use App\Models\Agent; |
|||
use App\Models\User; |
|||
use Closure; |
|||
use Illuminate\Http\Request; |
|||
use Illuminate\Support\Facades\Cache; |
|||
|
|||
class ApiBase |
|||
{ |
|||
public function handle(Request $request, Closure $next) |
|||
{ |
|||
$appid = request()->header('appid'); |
|||
|
|||
if (empty($appid)) { |
|||
return response()->json([ |
|||
'code' => -1, |
|||
'msg' => '商户信息缺失', |
|||
'data' => [], |
|||
'status' => 500, |
|||
]); |
|||
} |
|||
|
|||
//检查代理商
|
|||
$agent_id = Cache::get($appid); |
|||
if (empty($agent_id) || $agent_id != Agent::query()->where(['appid' => $appid, 'status' => 1])->value('id')) { |
|||
return response()->json([ |
|||
'code' => -1, |
|||
'msg' => '商户不存在或已被禁用', |
|||
'data' => [], |
|||
'status' => 403, |
|||
]); |
|||
} |
|||
Cache::put($appid, $agent_id); |
|||
return $next($request); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue