Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

88 Zeilen
2.8KB

  1. <?php
  2. namespace App\Transmissions\HTICWeb;
  3. use App\Codes\EnvironmentName;
  4. use App\Exceptions\AppCommonException;
  5. use App\Exceptions\GeneralErrorMessageException;
  6. use Illuminate\Support\Facades\Http;
  7. trait Sender
  8. {
  9. protected function sendSeasonTicketContractCreate(array $contents)
  10. {
  11. return $this->sendToHTICWeb("seasonticketcontract/create", $contents);
  12. }
  13. protected function sendSeasonTicketContractUpdate(array $contents)
  14. {
  15. return $this->sendToHTICWeb("seasonticketcontract/update", $contents);
  16. }
  17. protected function sendSeasonTicketContractDelete(array $contents)
  18. {
  19. return $this->sendToHTICWeb("seasonticketcontract/delete", $contents);
  20. }
  21. protected function getSeasonTicketContractParams(array $contents)
  22. {
  23. return $this->sendToHTICWeb("seasonticketcontract/params", $contents);
  24. }
  25. protected function getSeasonTicketContractFetch(array $contents)
  26. {
  27. return $this->sendToHTICWeb("seasonticketcontract/fetch", $contents);
  28. }
  29. protected function sendUserCreate(array $contents)
  30. {
  31. return $this->sendToHTICWeb("user/create", $contents);
  32. }
  33. protected function sendUserUpdate(array $contents)
  34. {
  35. return $this->sendToHTICWeb("user/update", $contents);
  36. }
  37. protected function sendUserDelete(array $contents)
  38. {
  39. return $this->sendToHTICWeb("user/delete", $contents);
  40. }
  41. private function sendToHTICWeb(string $url, array $contents)
  42. {
  43. $fullUrl = sprintf("%s/api/kyoto-public/%s", config("custom.ht-ic-web.url", ""), $url);
  44. $customerCode = app()->environment([EnvironmentName::PRODUCTOIN->value]) ? "1163" : "9990";
  45. $sendContents = [
  46. ...$contents,
  47. 'customer_code' => $customerCode,
  48. 'ht-ic-web-api-key' => config("custom.ht-ic-web.apiKey", ""),
  49. ];
  50. logger([
  51. "senddata",
  52. 'url' => $fullUrl,
  53. "contents" => $sendContents
  54. ]);
  55. $res = Http::post($fullUrl, $sendContents);
  56. if ($res->failed()) {
  57. throw $res->toException();
  58. }
  59. if ($res->json('result') !== 0) {
  60. logger($res->json());
  61. $generalErrorMessage = $res->json('messages.general', "");
  62. if (!!$generalErrorMessage) {
  63. throw new GeneralErrorMessageException($generalErrorMessage);
  64. }
  65. $messages = $res->json('messages.errors', []);
  66. logger(['messages' => $messages]);
  67. if (0 < count($messages)) {
  68. $key = array_key_first($messages);
  69. $message = $messages[$key];
  70. throw new GeneralErrorMessageException(sprintf("%s: %s", $key, $message));
  71. }
  72. throw new AppCommonException("HTICWeb連携失敗");
  73. }
  74. return $res;
  75. }
  76. }