# 한진택배 api PHP에서 HMACSha245 값 처리방법

- 주소: https://duotone.co.kr/entry/%ED%95%9C%EC%A7%84%ED%83%9D%EB%B0%B0-api-PHP%EC%97%90%EC%84%9C-HMACSha245-%EA%B0%92-%EC%B2%98%EB%A6%AC%EB%B0%A9%EB%B2%95
- 글쓴이: 서기㏇
- 카테고리: 개발·프로그래밍
- 작성일: 2023-12-26
- 태그: API, hash, HMAC, php, SHA256, 송장출력, 키 만들기, 한진택배

php로 한진택배 송장출력 api를 작성중에 관련 소스가 없어서 오픈한다. 

 

  $hanjin_client_id  =  "고객사 id"; // 영문아이디 

   $hanjinApiKey =  "한진APIKEY";

  $hanjinSecretKey =  "한진SecretKey";

 

   $method = "POST"; // "POST"; //  $_SERVER['REQUEST_METHOD'];

    $requestUrl = "http://$_SERVER[HTTP_HOST]"."$_SERVER[REQUEST_URI]";

    $queryString =  getQueryString($requestUrl);

 

    $timestamp = date("YmdHis");

    $message = $timestamp . $method . $queryString . $hanjinSecretKey;

   echo 'message: ' . $message . "\n";

    $signature = hash_hmac('sha256', $message, $hanjinSecretKey);      

    $authorization = 'client_id=' . $hanjin_client_id . ' timestamp=' . $timestamp . ' signature=' . $signature;

 

   

    $header = array(

        'x-api-key: '.$hanjinApiKey,

        "content-type: application/json" ,

        "Authorization: ".$authorization,

    );

 

 

 

 

 

    function getQueryString($url) {

        $arrSplit = explode('?', $url);

        return count($arrSplit) > 1 ? substr($url, strpos($url, '?') + 1) : '';

    }
