mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-05-10 10:54:27 +08:00
1. 维护代码健壮
2. 更新项目结构文档
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\http\mer\middleware;
|
||||
|
||||
use app\exception\UnauthorizedException;
|
||||
use app\service\merchant\auth\MerchantAuthService;
|
||||
use support\Context;
|
||||
use Webman\Http\Request;
|
||||
@@ -34,6 +35,7 @@ class MerchantAuthMiddleware implements MiddlewareInterface
|
||||
* @param Request $request 请求对象
|
||||
* @param callable $handler handler
|
||||
* @return Response 响应对象
|
||||
* @throws UnauthorizedException
|
||||
*/
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
@@ -42,11 +44,7 @@ class MerchantAuthMiddleware implements MiddlewareInterface
|
||||
|
||||
if ($token === '') {
|
||||
if ((int) env('AUTH_MIDDLEWARE_STRICT', 1) === 1) {
|
||||
return json([
|
||||
'code' => 401,
|
||||
'msg' => 'merchant unauthorized',
|
||||
'data' => null,
|
||||
]);
|
||||
throw new UnauthorizedException('商户未授权');
|
||||
}
|
||||
} else {
|
||||
$result = $this->merchantAuthService->authenticateToken(
|
||||
@@ -55,11 +53,7 @@ class MerchantAuthMiddleware implements MiddlewareInterface
|
||||
$request->header('user-agent', '')
|
||||
);
|
||||
if (!$result) {
|
||||
return json([
|
||||
'code' => 401,
|
||||
'msg' => 'merchant unauthorized',
|
||||
'data' => null,
|
||||
]);
|
||||
throw new UnauthorizedException('商户未授权');
|
||||
}
|
||||
|
||||
Context::set('auth.merchant_id', (int) $result['merchant']->id);
|
||||
|
||||
Reference in New Issue
Block a user