Browse Source

修改签名算法

master
weigang 6 years ago
parent
commit
7f7ac81628
  1. 22
      app/Middleware/Auth/ApiMiddleware.php

22
app/Middleware/Auth/ApiMiddleware.php

@ -39,9 +39,9 @@ class ApiMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (env('APP_ENV') == 'dev') {
return $handler->handle($request);
}
// if (env('APP_ENV') == 'dev') {
// return $handler->handle($request);
// }
// 签名校验
@ -82,18 +82,22 @@ class ApiMiddleware implements MiddlewareInterface
unset($params['sign']);
$timestamp = $params['timestamp'];
if (empty($sign) || ($timestamp+config('autoload.auth.api.sign.expire')) < time()) {
if (empty($sign) || ($timestamp+config('auth.api.sign.expire_time')) < time()) {
return false;
}
ksort($params);
$params = http_build_query($params);
return $sign == $this->signature($params);
}
private function signature($http_query)
private function signature($params)
{
return sha1(md5($http_query).config('autoload.auth.api.sign.secret_key'));
ksort($params);
$http_query = [];
foreach ($params as $key => $value) {
$http_query[] = $key.'='.$value;
}
return sha1(md5(implode('&', $http_query)).config('auth.api.sign.secret_key'));
}
}
Loading…
Cancel
Save