27 lines
770 B
PHP
27 lines
770 B
PHP
<?php
|
|
|
|
namespace app\middleapi\http\middleware;
|
|
|
|
use app\middleapi\service\ApiSignService;
|
|
use app\common\service\JsonService;
|
|
|
|
class AuthMiddleware
|
|
{
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
//获取header参数
|
|
$appid = $request->header('appid');
|
|
$timestamp = $request->header('timestamp');
|
|
$sign = $request->header('sign');
|
|
//验证参数
|
|
if(empty($appid) || empty($timestamp) || empty($sign)){
|
|
return JsonService::fail('缺少请求头参数', [], 0);
|
|
}
|
|
//验证签名
|
|
$checkSign = ApiSignService::verifySign(['appid'=>$appid,'timestamp'=>$timestamp,'sign'=>$sign],env('app.app_secret'));
|
|
if($checkSign['code'] == 0){
|
|
return JsonService::fail($checkSign['msg'],[],0);
|
|
}
|
|
return $next($request);
|
|
}
|
|
} |