|
- <?php
-
- namespace App\Transmission;
-
- use App\Transmission\Layouts\SIFRequest;
- use Carbon\Carbon;
- use Illuminate\Http\Client\Response;
- use Illuminate\Support\Facades\Http;
-
- class SIFSender extends Sender
- {
- private string $host = 'localhost';
-
-
-
- private bool $already_init = false;
-
- public function __construct()
- {
- }
-
- public function init(string $host = null)
- {
- $this->setHost($host);
-
- $this->already_init = true;
- }
-
- public function send(SIFRequest $request): Response
- {
- if (!$this->already_init) {
- $this->init();
- }
-
- $now = Carbon::now();
-
- $request->header->resultCode = ResultCode::SUCCESS->value;
- $request->header->sendDatetime = $now->format('YmdHis');
- $data = $request->toArray();
-
- info('SEND ' . $request->header->interfaceId, $data);
-
- $this->response = Http::post($this->getUrl($request->getPath()), $data);
- return $this->response;
- }
-
-
-
- private function setHost(string|null $host): void
- {
- if ($host !== null) {
- $this->host = $host;
- } else {
- $this->host = config('transmission.sif_server_url', 'https://ht_hogehoge.co.jp');
- }
- }
-
-
- public function getUrl($path = null): string
- {
- $url = $this->host;
- if ($path !== null) {
- $url .= $path;
- }
- return $url;
- }
- }
|