본문 바로가기
개발자공간/SCRIPT

스윗트래커 배송조회 api사용

by 냉국이 2023. 3. 28.
728x90

jquery 

//스윗트래커로 송장번호를 넘겨주고 배송정보를 가져옴
let delikey = "YOUR API KEY";
let delivery_idx = $(this).data('comidx');

let delivery_no = $.trim($(this).data('invno').toString().replace(/[^0-9]/g, "")); //숫자만 추출

if(delivery_idx && delivery_no){
    let apiEndpoint = "https://info.sweettracker.co.kr/api/v1/trackingInfo?t_key="+delikey+"&t_code="+delivery_idx+"&t_invoice="+delivery_no;



    $.ajax({
        type: 'GET',
        url: apiEndpoint,
        dataType: 'json',
        success: function(Obj) {
            let headerData = "";
            if(Obj.status == false){


            }else{
                delivery_pop(Obj); //조회 팝업 
            }
        },
        error: function(xhr, status, error) {
            loading_close();
            // Handle any errors here
            console.error(error);
        }
    });
}
        
        
//배송조회 팝업창 호출
function delivery_pop(data){
    $.ajax({
        type: 'POST',
        data : data,
        url: "/delivery_pop.php",
        dataType: 'html',
        success: function(Obj) {
            let html = Obj;
             $("#content").find('.od_list_wrap').after(html);

            $('.delivery_pop').find('.delivery_close').on('click',function(e){
                //여기는 한 화면에서 여러건 조회가 가능해서 그냥 지움
                $('.delivery_pop').remove();
            });
            loading_close();
        }
    });
}

 

 

 

 

 
delivery_pop.php
<?php
$trakingDetail = $_POST['trackingDetails'];
?>

<div class="delivery_pop">
  <div class="delivery_bg"></div>
  <div class="delivery_box">
    <div class="delivery_close"></div>
    <div class="delivery_title">배송정보</div>

    <table class="delivery_area">
      <thead>
        <tr>
          <th style="padding: 8px 0">처리일시</th>
          <th>현재위치</th>
          <th>배송상태</th>
          <th>연락처</th>
        </tr>
      </thead>

      <tbody class="delivery_data">
        <?php
                foreach($trakingDetail as $k=>$val){ ?>
        <tr>
          <td style="padding: 10px"><?=$val['timeString'];?></td>
          <td><?=$val['where'];?></td>
          <td><?=$val['kind'];?></td>
          <td><?=$val['telno'];?></td>
        </tr>
        <?php
                }
                ?>
      </tbody>
    </table>
  </div>
</div>
 
300x250

댓글