12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?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;
- use Hyperf\Context\Context;
- /**
- * 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();
- var_dump($websiteInfo);
- if($websiteInfo['code'] == 200){
- $this->siteId = $websiteInfo['data']['id'];
- }
- }
- /**
- * 获取栏目导航
- * @return array
- */
- public function getWebsiteCategory()
- {
- var_dump("网站id:",$this->siteId);
- $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]
- ];
- var_dump($data);
- $result = $this->websiteServiceClient->getWebsiteId($data);
- if ($result['code'] != ErrorCode::SUCCESS) {
- return Result::error($result['message'],0,[]);
- }
- return Result::success($result['data']);
- }
- }
|