FinancialController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Http\Controllers\Service;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Http;
  5. use App\Http\Controllers\Controller;
  6. /*
  7. * 한국수출입은행
  8. * https://www.koreaexim.go.kr/
  9. * 환율 / 대출금리 / 국제금리 정보 제공
  10. */
  11. class FinancialController extends Controller
  12. {
  13. const API_EXCHANGE_KEY = 'OiZlh6SjbXGBlfbagekBpi6kAE4UyonP';
  14. const API_EXCHANGE_HOST = 'https://www.koreaexim.go.kr/site/program/financial/exchangeJSON';
  15. const API_INTEREST_KEY = '4olJNSqYHe4oVsW50JFXpXyYmDh9O9NN';
  16. const API_INTEREST_HOST = 'https://www.koreaexim.go.kr/site/program/financial/interestJSON';
  17. const API_INTERNATIONAL_KEY = 'UI3DgPS3oZucxxCThkJQV6eAGprSbLJy';
  18. const API_INTERNATIONAL_HOST = 'https://www.koreaexim.go.kr/site/program/financial/internationalJSON';
  19. public function __construct()
  20. {
  21. $this->middleware('front');
  22. }
  23. /**
  24. * 환율 정보
  25. * @method GET
  26. * @see /service/financial/exchange
  27. */
  28. public function exchange(Request $request)
  29. {
  30. $date = $request->get("date", now()->format('Y-m-d'));
  31. $response = Http::get(self::API_EXCHANGE_HOST, [
  32. 'authkey' => self::API_EXCHANGE_KEY,
  33. 'searchdate' => $date,
  34. 'data' => 'AP01',
  35. ]);
  36. $total = 0;
  37. $list = null;
  38. if($response->ok()) {
  39. $list = $response->object();
  40. $total = count($list);
  41. }
  42. return view(layout('service.financial.exchange'), [
  43. 'menuID' => 'exchange',
  44. 'total' => $total,
  45. 'list' => $list,
  46. 'date' => $date
  47. ]);
  48. }
  49. /**
  50. * 대출금리
  51. * @method GET
  52. * @see /service/financial/interest
  53. */
  54. public function interest(Request $request)
  55. {
  56. $date = $request->get("date", now()->format('Y-m-d'));
  57. $response = Http::get(self::API_INTEREST_HOST, [
  58. 'authkey' => self::API_INTEREST_KEY,
  59. 'searchdate' => $date,
  60. 'data' => 'AP02',
  61. ]);
  62. $total = 0;
  63. $list = null;
  64. if($response->ok()) {
  65. $list = $response->object();
  66. $total = count($list);
  67. }
  68. return view(layout('service.financial.interest'), [
  69. 'menuID' => 'interest',
  70. 'total' => $total,
  71. 'list' => $list,
  72. 'date' => $date
  73. ]);
  74. }
  75. /**
  76. * 국제금리
  77. * @method GET
  78. * @see /service/financial/international
  79. */
  80. public function international(Request $request)
  81. {
  82. $date = $request->get("date", now()->format('Y-m-d'));
  83. $response = Http::get(self::API_INTERNATIONAL_HOST, [
  84. 'authkey' => self::API_INTERNATIONAL_KEY,
  85. 'searchdate' => $date,
  86. 'data' => 'AP03',
  87. ]);
  88. $sofrList = [];
  89. $estrList = [];
  90. $euriborList = [];
  91. $tonaList = [];
  92. $tiborList = [];
  93. $swapRfrList = [];
  94. $liborList = [];
  95. $swapList = [];
  96. $cirrList = [];
  97. if($response->ok()) {
  98. $list = $response->object();
  99. $map = function($list) {
  100. $ret = [];
  101. foreach($list as $row) {
  102. $ret[$row->cur_fund][] = $row;
  103. }
  104. return $ret;
  105. };
  106. $sofrList = $list->sofr_list;
  107. $estrList = $list->estr_list;
  108. $tonaList = $list->tona_list;
  109. $euriborList = $map($list->euribor_list);
  110. $tiborList = $map($list->tibor_list);
  111. $swapRfrList = $map($list->swapRfr_list);
  112. $liborList = $map($list->libor_list);
  113. $swapList = $map($list->swap_list);
  114. $cirrList = $map($list->cirr_list);
  115. }
  116. return view(layout('service.financial.international'), [
  117. 'menuID' => 'international',
  118. 'sofrList' => $sofrList,
  119. 'estrList' => $estrList,
  120. 'euriborList' => $euriborList,
  121. 'tonaList' => $tonaList,
  122. 'tiborList' => $tiborList,
  123. 'swapRfrList' => $swapRfrList,
  124. 'liborList' => $liborList,
  125. 'swapList' => $swapList,
  126. 'cirrList' => $cirrList,
  127. 'date' => $date
  128. ]);
  129. }
  130. }