php curl 관련해서 질문드려요.

php curl 관련해서 질문드려요.

QA

php curl 관련해서 질문드려요.

본문

nhn TOAST를 이용하여 알림톡을 연동중에 있습니다.

 

연동도중에 curl을 이용하여 발송요청을 하고자 하는데

 

TOAST의 예시로는 CURL이

 

curl -X POST -H "Content-Type: application/json;charset=UTF-8" -H "X-Secret-Key:{secretkey}" https://api-alimtalk.cloud.toast.com/alimtalk/v1.4/appkeys/{appkey}/messages -d '{"plusFriendId":"{플러스친구 아이디}","templateCode":"{템플릿 코드}","requestDate":"2018-10-01 00:00","recipientList":[{"recipientNo":"{수신번호}","templateParameter":{"{치환자 필드}":"{치환 데이터}"}}]}'

이렇게 되어있습니다. 

요청 구조는

{ "plusFriendId": String, "templateCode": String, "requestDate": String, "senderGroupingKey": String, "recipientList": [{ "recipientNo": String, "templateParameter": { String: String }, "resendParameter": { "isResend" : boolean, "resendType" : String, "resendTitle" : String, "resendContent" : String, "resendSendNo" : String }, "recipientGroupingKey": String }] }

 

입니다.

 

여기서 질문 드릴게요.

recipientList":[{"recipientNo":"{수신번호}","templateParameter":{"{치환자 필드}":"{치환 데이터}"}}]}'

이렇게 되어있는데 이부분은 어떻게 처리 해야 하는 부분인가요?

 

현재 예시로 짜고 있는 코드는


<meta charset="utf-8">
<?php
function send_talk($plusFriendId, $templateCode) {
  $url = "https://api-alimtalk.cloud.toast.com/alimtalk/v1.4/appkeys/wYE0rZUNjqHgVMSF/messages";
  $req_body = array(
    'plusFriendId' => $plusFriendId,
    'templateCode' => $templateCode,
    'requestDate' => date(),
      'recipientList' => array(
          'recipientNo' => $mb_hp,
          'templateParameter' => array(
              '고객이름' => '홍길동',
              '요청파라메터' => '파라메터',
              '요청파라메터' => '파라메터',
              '요청파라메터' => '파라메터'
          )
      )
  );  // 요청 본문

  $req_header = array(
    "Content-Type: application/json;charset=UTF-8",
    "X-Secret-Key:{key}"
  );  // 요청 헤더 생성
  $curl  = curl_init($url); // curl 초기화
  curl_setopt_array($curl, array(
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => $req_header,
    CURLOPT_POSTFIELDS => json_encode($req_body)
  )); // 파라미터 설정
  $response = curl_exec($curl); // API 호출
  curl_close($curl);
  return $response;
}
$app_key = 'appkey';

$plusFriendId = '';
$templateCode = 'reservation1';
// $PASSWORD = '{API Password}';
$token = send_talk($plusFriendId, $templateCode);
// printf("%s\n", $token);
echo $token;
?>
 

 

 

붉은색 부분에 대해서 처리 해야 하는 방법이 궁금하여 문의 드립니다.

이 질문에 댓글 쓰기 :

답변 1

원하시는게 이게 맞는지 모르겠군요.


$token = send_talk($plusFriendId, $templateCode);
$token_result = json_decode($token, true);
print_r($token_result);

 

이렇게 하시면 될것 같습니다.

 

 

답변을 작성하시기 전에 로그인 해주세요.
전체 95
QA 내용 검색
filter #curl ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT