Files
hyperf_test/app/Service/Test/Proxy/Remote/RemoteOrderServiceProxy.php
2025-09-07 14:18:01 +08:00

51 lines
1.3 KiB
PHP

<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Proxy\Remote;
use App\Interface\Test\Decorator\LoggerInterface;
use App\Interface\Test\Proxy\OrderInterface;
use Hyperf\RpcClient\ProxyFactory;
use Throwable;
class RemoteOrderServiceProxy implements OrderInterface
{
/**
* @var LoggerInterface
*/
protected LoggerInterface $logger;
// public function __construct(ProxyFactory $rpcClient, LoggerInterface $logger)
// {
// $this->rpcClient = $rpcClient;
// $this->logger = $logger;
// }
public function createOrder(array $data): array
{
$data['request_id'] = uniqid();
$data['timestamp'] = time();
$this->logger->log('Sending order creation request'.json_encode($data));
try {
// $response = $this->rpcClient->__call('OrderService.createOrder',[$data]);
$this->logger->log('Order created successfully, response:'.json_encode($response));
return $response;
} catch (Throwable $exception) {
$this->logger->error('Order creation error: '.$exception->getMessage());
return [];
}
}
}