You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.4KB

  1. <?php
  2. namespace App\Transmission;
  3. use App\Transmission\Layouts\SIFRequest;
  4. use Carbon\Carbon;
  5. use Illuminate\Http\Client\Response;
  6. use Illuminate\Support\Facades\Http;
  7. class SIFSender extends Sender
  8. {
  9. private string $host = 'localhost';
  10. private bool $already_init = false;
  11. public function __construct()
  12. {
  13. }
  14. public function init(string $host = null)
  15. {
  16. $this->setHost($host);
  17. $this->already_init = true;
  18. }
  19. public function send(SIFRequest $request): Response
  20. {
  21. if (!$this->already_init) {
  22. $this->init();
  23. }
  24. $now = Carbon::now();
  25. $request->header->resultCode = ResultCode::SUCCESS->value;
  26. $request->header->sendDatetime = $now->format('YmdHis');
  27. $data = $request->toArray();
  28. info('SEND ' . $request->header->interfaceId, $data);
  29. $this->response = Http::post($this->getUrl($request->getPath()), $data);
  30. return $this->response;
  31. }
  32. private function setHost(string|null $host): void
  33. {
  34. if ($host !== null) {
  35. $this->host = $host;
  36. } else {
  37. $this->host = config('transmission.sif_server_url', 'https://ht_hogehoge.co.jp');
  38. }
  39. }
  40. public function getUrl($path = null): string
  41. {
  42. $url = $this->host;
  43. if ($path !== null) {
  44. $url .= $path;
  45. }
  46. return $url;
  47. }
  48. }