Browse Source

Merge branch 'develop' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into develop

master
parent
commit
1ccd47bdc2
  1. 4
      app/Controller/CouponController.php
  2. 22
      app/Middleware/Auth/ApiMiddleware.php

4
app/Controller/CouponController.php

@ -245,7 +245,7 @@ class CouponController extends BaseController
$notAvailable = []; $notAvailable = [];
foreach ($data as $key => &$item) { foreach ($data as $key => &$item) {
if (in_array($item->id, $couponIds)) { if (in_array($item->id, $couponIds)) {
$notAvailable[] = $item;
$notAvailable[$item->id] = $item;
} else { } else {
$available[] = $item; $available[] = $item;
} }
@ -253,7 +253,7 @@ class CouponController extends BaseController
return $this->success([ return $this->success([
'available' => $available, 'available' => $available,
'not_available' => $notAvailable
'not_available' => array_values($notAvailable)
]); ]);
} }

22
app/Middleware/Auth/ApiMiddleware.php

@ -39,9 +39,9 @@ class ApiMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 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']); unset($params['sign']);
$timestamp = $params['timestamp']; $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; return false;
} }
ksort($params);
$params = http_build_query($params);
return $sign == $this->signature($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