You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
<?php
|
|
namespace app\common\middleware;
|
|
|
|
//验证权限
|
|
class ApiAuth
|
|
{
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
$apiStatus=config('app.api_status');
|
|
if(!$apiStatus){
|
|
return shutdown(lang('system.apiClose'));
|
|
}
|
|
$appId=config('app.app_id');
|
|
$appSecret=config('app.app_secret');
|
|
$header = $request->header();
|
|
$app_id=$header['x-im-appid'] ?? '';
|
|
$timeStamp=$header['x-im-timestamp'] ?? 0;
|
|
$sign=$header['x-im-sign'] ?? '';
|
|
if(!$app_id || !$timeStamp || !$sign){
|
|
return shutdown(lang('system.parameterError'));
|
|
}
|
|
// 时间戳不能大约60秒
|
|
if(time()-$timeStamp>60){
|
|
return shutdown(lang('system.longTime'));
|
|
}
|
|
if($appId!=$app_id){
|
|
return shutdown(lang('system.appIdError'));
|
|
}
|
|
$signStr=md5($appId.$timeStamp.$appSecret);
|
|
if($sign!=$signStr){
|
|
return shutdown(lang('system.signError'));
|
|
}
|
|
return $next($request);
|
|
}
|
|
}
|