WebController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\JsonRpc\NewsServiceInterface;
  5. use App\JsonRpc\WebsiteServiceInterface;
  6. use App\Tools\PublicData;
  7. use Hyperf\Di\Annotation\Inject;
  8. use Hyperf\HttpServer\Annotation\AutoController;
  9. use App\Tools\Result;
  10. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  11. use App\Constants\ErrorCode;
  12. use Hyperf\Context\Context;
  13. /**
  14. * Class WebController
  15. * @package App\Controller
  16. */
  17. class WebController extends AbstractController
  18. {
  19. #[Inject]
  20. protected ValidatorFactoryInterface $validationFactory;
  21. /**
  22. * @var NewsServiceInterface
  23. */
  24. #[Inject]
  25. private $newsServiceClient;
  26. /**
  27. * @var WebsiteServiceInterface
  28. */
  29. #[Inject]
  30. private $websiteServiceClient;
  31. <<<<<<< HEAD
  32. protected $siteId;
  33. public function __construct(){
  34. $websiteInfo = $this->getWebsiteId();
  35. var_dump($websiteInfo);
  36. if($websiteInfo['code'] == 200){
  37. $this->siteId = $websiteInfo['data']['id'];
  38. }
  39. }
  40. =======
  41. >>>>>>> dc5ca2d82095a07156ecae10ce8899519068294e
  42. /**
  43. * 获取栏目导航
  44. * @return array
  45. */
  46. public function getWebsiteCategory()
  47. {
  48. <<<<<<< HEAD
  49. var_dump("网站id:",$this->siteId);
  50. =======
  51. >>>>>>> dc5ca2d82095a07156ecae10ce8899519068294e
  52. $data = [
  53. 'website_id'=>Context::get("SiteId")
  54. ];
  55. var_dump("网站id:",Context::get("SiteId"));
  56. $result = $this->websiteServiceClient->getWebsiteCategory($data);
  57. if ($result['code'] != ErrorCode::SUCCESS) {
  58. return Result::error($result['message'],0,[]);
  59. }
  60. return Result::success($result['data']);
  61. }
  62. <<<<<<< HEAD
  63. /**
  64. * @return array
  65. */
  66. public function getWebsiteId()
  67. {
  68. $header = $this->request->getHeaders();
  69. var_dump("获取header:",$header);
  70. if(!isset($header['origin'])){
  71. return Result::error("header请配置origin");
  72. }
  73. $origin = $header['origin'][0];
  74. $logindevice = explode("//", $origin);
  75. $data = [
  76. 'website_url'=>$logindevice[1]
  77. ];
  78. var_dump($data);
  79. $result = $this->websiteServiceClient->getWebsiteId($data);
  80. if ($result['code'] != ErrorCode::SUCCESS) {
  81. return Result::error($result['message'],0,[]);
  82. }
  83. return Result::success($result['data']);
  84. }
  85. =======
  86. >>>>>>> dc5ca2d82095a07156ecae10ce8899519068294e
  87. }