ClientService.php 969 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\JsonRpc;
  3. use Hyperf\RpcClient\AbstractServiceClient;
  4. use Hyperf\Logger\LoggerFactory;
  5. use Psr\Log\LoggerInterface;
  6. class ClientService extends AbstractServiceClient implements ClientServiceInterface
  7. {
  8. /**
  9. * 定义对应服务提供者的服务名称
  10. * @var string
  11. */
  12. protected string $serviceName = 'ClientService';
  13. /**
  14. * 定义对应服务提供者的服务协议
  15. * @var string
  16. */
  17. protected string $protocol = 'jsonrpc-http';
  18. protected $logger;
  19. public function __construct(LoggerFactory $loggerFactory)
  20. {
  21. $this->logger = $loggerFactory->get('default');
  22. }
  23. /**
  24. * test
  25. * @param array $data
  26. * @return array
  27. */
  28. public function test(array $data): array
  29. {
  30. var_dump($data, $this->serviceName, $this->protocol);
  31. $this->logger->info('请求数据: ' . json_encode($data));
  32. return $this->__request(__FUNCTION__, $data);
  33. }
  34. }