|
@@ -0,0 +1,78 @@
|
|
|
|
+<?php
|
|
|
|
+declare(strict_types=1);
|
|
|
|
+namespace App\Controller;
|
|
|
|
+
|
|
|
|
+use App\JsonRpc\NewsServiceInterface;
|
|
|
|
+use App\JsonRpc\WebsiteServiceInterface;
|
|
|
|
+use App\Tools\PublicData;
|
|
|
|
+use Hyperf\Di\Annotation\Inject;
|
|
|
|
+use Hyperf\HttpServer\Annotation\AutoController;
|
|
|
|
+use App\Tools\Result;
|
|
|
|
+use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
|
|
|
+use App\Constants\ErrorCode;
|
|
|
|
+/**
|
|
|
|
+ * Class WebController
|
|
|
|
+ * @package App\Controller
|
|
|
|
+ */
|
|
|
|
+class WebController extends AbstractController
|
|
|
|
+{
|
|
|
|
+ #[Inject]
|
|
|
|
+ protected ValidatorFactoryInterface $validationFactory;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var NewsServiceInterface
|
|
|
|
+ */
|
|
|
|
+ #[Inject]
|
|
|
|
+ private $newsServiceClient;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var WebsiteServiceInterface
|
|
|
|
+ */
|
|
|
|
+ #[Inject]
|
|
|
|
+ private $websiteServiceClient;
|
|
|
|
+ protected $siteId;
|
|
|
|
+ public function __construct(){
|
|
|
|
+ $websiteInfo = $this->getWebsiteId();
|
|
|
|
+ if($websiteInfo['code'] == 200){
|
|
|
|
+ $this->siteId = $websiteInfo['data']['id'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 获取栏目导航
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function getWebsiteCategory()
|
|
|
|
+ {
|
|
|
|
+ $data = [
|
|
|
|
+ 'website_id'=>$this->siteId
|
|
|
|
+ ];
|
|
|
|
+ $result = $this->websiteServiceClient->getWebsiteCategory($data);
|
|
|
|
+ if ($result['code'] != ErrorCode::SUCCESS) {
|
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
|
+ }
|
|
|
|
+ return Result::success($result['data']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function getWebsiteId()
|
|
|
|
+ {
|
|
|
|
+ $header = $this->request->getHeaders();
|
|
|
|
+ var_dump("获取header:",$header);
|
|
|
|
+ if(!isset($header['origin'])){
|
|
|
|
+ return Result::error("header请配置origin");
|
|
|
|
+ }
|
|
|
|
+ $origin = $header['origin'][0];
|
|
|
|
+ $logindevice = explode("//", $origin);
|
|
|
|
+ $data = [
|
|
|
|
+ 'website_url'=>$logindevice[1]
|
|
|
|
+ ];
|
|
|
|
+ $result = $this->websiteServiceClient->getWebsiteId($data);
|
|
|
|
+ if ($result['code'] != ErrorCode::SUCCESS) {
|
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
|
+ }
|
|
|
|
+ return Result::success($result['data']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|