|
|
@@ -0,0 +1,225 @@
|
|
|
+<?php
|
|
|
+declare(strict_types=1);
|
|
|
+namespace App\Controller;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+use App\JsonRpc\NewsServiceInterface;
|
|
|
+use App\JsonRpc\WebsiteServiceInterface;
|
|
|
+use App\JsonRpc\AdServiceInterface;
|
|
|
+use App\JsonRpc\UserServiceInterface;
|
|
|
+use App\JsonRpc\ChatServiceInterface;
|
|
|
+use App\JsonRpc\OrderServiceInterface;
|
|
|
+use App\JsonRpc\CollectorServiceInterface;
|
|
|
+use App\JsonRpc\ClientServiceInterface;
|
|
|
+use App\Controller\IndexController;
|
|
|
+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;
|
|
|
+use \Phper666\JWTAuth\JWT;
|
|
|
+/**
|
|
|
+ * Class WebController
|
|
|
+ * @package App\Controller
|
|
|
+ */
|
|
|
+class TestController extends AbstractController
|
|
|
+{
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected ValidatorFactoryInterface $validationFactory;
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected IndexController $IndexController;
|
|
|
+ // #[Inject]
|
|
|
+ // protected JWT $jwt;
|
|
|
+ /**
|
|
|
+ * @var NewsServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $newsServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var WebsiteServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $websiteServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var AdServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $adServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var UserServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $userServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var ChatServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $chatServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var OrderServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $orderServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var CollectorServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $collectorServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var ClientServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $clientServiceClient;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试admin_consumer
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function testAdminConsumer()
|
|
|
+ {
|
|
|
+ $user = [
|
|
|
+ 'user_id' => 32,
|
|
|
+ 'username' => 'admin',
|
|
|
+ 'password' => '123456',
|
|
|
+ ];
|
|
|
+ return Result::success($user);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试public_producer
|
|
|
+ */
|
|
|
+ public function testPublicProducer()
|
|
|
+ {
|
|
|
+ $requireData = $this->request->all();
|
|
|
+ // return Result::success($requireData);
|
|
|
+ $result = $this->websiteServiceClient->selectWebsiteArea($requireData);
|
|
|
+ if ($result['code'] != ErrorCode::SUCCESS) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 测试ad_producer
|
|
|
+ */
|
|
|
+ public function testAdProducer()
|
|
|
+ {
|
|
|
+ // $requireData = $this->request->all();
|
|
|
+ $data = [
|
|
|
+ 'page' => 1,
|
|
|
+ 'pageSize' => 1,
|
|
|
+ ];
|
|
|
+ $result = $this->adServiceClient->getAdPlaceList($data);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 测试user_producer
|
|
|
+ */
|
|
|
+ public function testUserProducer()
|
|
|
+ {
|
|
|
+ // return Result::success($this->request->all());
|
|
|
+ $data = $this->request->all();
|
|
|
+ $user = $data['user_id'] ?? 32;
|
|
|
+ // return Result::success($user);
|
|
|
+ $result = $this->userServiceClient->getUserInfo((int)$user);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 测试news_producer
|
|
|
+ */
|
|
|
+ public function testNewsProducer()
|
|
|
+ {
|
|
|
+ $requestData = $this->request->all();
|
|
|
+ // $catid = $data['catid'] ?? 11;
|
|
|
+ $data = [
|
|
|
+ 'website_id'=> $requestData['website_id'] ?? 2,
|
|
|
+ 'catid' => $requestData['catid'] ?? 11,
|
|
|
+ 'level' => $requestData['level'] ?? 1,
|
|
|
+ 'pagesize' => 1
|
|
|
+ ];
|
|
|
+ $result = $this->newsServiceClient->getWebsiteModelArticles($data);
|
|
|
+ // var_dump($result);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ // 增加对返回数据是否为空的检查,避免尝试访问空数组元素导致的错误
|
|
|
+ if (empty($result['data'])) {
|
|
|
+ return Result::error('未获取到模块新闻数据', 0, []);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试order_producer
|
|
|
+ */
|
|
|
+ public function testOrderProducer()
|
|
|
+ {
|
|
|
+ $data = [
|
|
|
+ 'website_id' => 2,
|
|
|
+ ];
|
|
|
+ $result = $this->orderServiceClient->getAD($data);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试chat_producer
|
|
|
+ */
|
|
|
+ public function testChatProducer()
|
|
|
+ {
|
|
|
+ $data['page'] = 1;
|
|
|
+ $data['page_size'] = 1;
|
|
|
+ $result = $this->chatServiceClient->getTopicsList($data);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 测试collector_producer
|
|
|
+ */
|
|
|
+ public function testCollectorProducer()
|
|
|
+ {
|
|
|
+ $data['web_id'] = 49;
|
|
|
+ $data['pageSize'] = 1;
|
|
|
+ $data['page'] = 1;
|
|
|
+ $result = $this->collectorServiceClient->getRule($data);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 测试client_producer
|
|
|
+ */
|
|
|
+ public function testClientProducer()
|
|
|
+ {
|
|
|
+ $result = $this->clientServiceClient->test(['name' => 'test']);
|
|
|
+ if ($result['code'] != 200) {
|
|
|
+ return Result::error($result['message'],0,[]);
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+}
|