본문 바로가기

프로그래밍

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

반응형

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) : '';
    }

     


 

반응형