FinancialTrait.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Traits;
  3. trait FinancialTrait
  4. {
  5. /**
  6. * 환율정보 처리
  7. * User: 김국현
  8. * Date: 2019-02-04
  9. * Time: 오후 11:22
  10. *
  11. * https://www.data.go.kr/dataset/3068846/openapi.do
  12. * https://www.koreaexim.go.kr/site/program/openapi/openApiView?menuid=001003002002001&apino=2&viewtype=C
  13. */
  14. /*
  15. * 모든 환율목록 조회
  16. */
  17. function exchangeList($searchDate = "")
  18. {
  19. if(!$searchDate) {
  20. date('Y-m-d', time());
  21. }
  22. $key = KOREA_OPEN_API_KEY;
  23. $url = "site/program/financial/exchangeJSON?authkey={$key}&searchdate={$searchDate}&data=AP01";
  24. $result = json_decode(file_get_contents(KOREA_OPEN_API_HOST . $url), true);
  25. return $result;
  26. }
  27. /*
  28. * 유로화 조회
  29. */
  30. function getEuRate()
  31. {
  32. $exchangeList = $this->exchangeList();
  33. $result = [];
  34. foreach ($exchangeList as $exchange) {
  35. if ($exchange['cur_unit'] == "EUR") {
  36. $result = $exchange;
  37. break;
  38. }
  39. }
  40. return $result;
  41. }
  42. }