rkljw пре 2 месеци
родитељ
комит
5051a7ce9e
1 измењених фајлова са 26 додато и 2 уклоњено
  1. 26 2
      app/Middleware/Auth/FooMiddleware.php

+ 26 - 2
app/Middleware/Auth/FooMiddleware.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace App\Middleware\Auth;
 
+use Hyperf\Di\Annotation\Inject;
 use Hyperf\HttpServer\Contract\RequestInterface;
 use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
 use Psr\Container\ContainerInterface;
@@ -12,7 +13,7 @@ use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Server\MiddlewareInterface;
 use Psr\Http\Server\RequestHandlerInterface;
 use Hyperf\Context\Context;
-
+use App\JsonRpc\WebsiteServiceInterface;
 use Phper666\JWTAuth\JWT;
 class FooMiddleware implements MiddlewareInterface
 {
@@ -22,7 +23,11 @@ class FooMiddleware implements MiddlewareInterface
 
     protected HttpResponse $response;
     protected JWT $JWT;
-
+    /**
+     * @var WebsiteServiceInterface
+     */
+    #[Inject]
+    private $websiteServiceClient;
     public function __construct(ContainerInterface $container, HttpResponse $response, RequestInterface $request,Jwt $JWT)
     {
         $this->container = $container;
@@ -50,6 +55,25 @@ class FooMiddleware implements MiddlewareInterface
                        ]
                    );
                 }
+                if($header['userurl'][0]){
+                    $origin = $header['userurl'][0];
+                    $data = [
+                        'website_url'=>$origin
+                    ];
+
+                    $result = $this->websiteServiceClient->getWebsiteId($data);
+                    if(!isset($result['data']['id']) || !$result['data']['id']){
+                        return $this->response->json(
+                            [
+                                'code' => -1,
+                                'data' => [],
+
+                                'message' => '网站不存在...',
+                            ]
+                        );
+                    }
+                    Context::set("SiteId",$result['data']['id']);
+                }
 //                var_dump("中间件:",$ver);
                 Context::set("UserId",$ver['uid']);
                 Context::set("TypeId",$ver['type_id']);