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.
34 lines
829 B
34 lines
829 B
<?php
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\middleware;
|
|
|
|
use think\exception\HttpException;
|
|
|
|
class CheckParams
|
|
{
|
|
public function handle($request, \Closure $next): object
|
|
{
|
|
$params = $request->param();
|
|
if(!isset($params['sign'])){
|
|
return json(['code'=>401,'message'=>'API驗證失敗','data'=>'No Sign','time'=>time()]);
|
|
}
|
|
$sign = $params['sign'];
|
|
|
|
unset($params['sign']);
|
|
|
|
ksort($params);
|
|
|
|
$string = md5(md5(strtolower(http_build_query($params))).'seckey');
|
|
|
|
if($string !== $sign){
|
|
// throw new HttpException(401, 'Sign Error!!!');
|
|
return json(['code'=>401,'message'=>'API驗證失敗','data'=>'Sign Error','time'=>time()]);
|
|
}
|
|
|
|
$response = $next($request);
|
|
|
|
return $response;
|
|
}
|
|
} |