2017-10-10 4 views
0

내 codeigniter 프로젝트에서 sms 템플릿을 등록하기위한 API를 통합해야합니다. 이건 내 코드입니다 :API에 대한 콜백 URL

$postdata = array('userid'   => 'user', 
        'password'   => '[email protected]', 
        'template'   => 'Demo template', 
        'callback_url'  => base_url().'API/templateCallback' 
       ); 

$postdata = json_encode($postdata); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,"http://example.com/TemplateRegistration2/registerTemplate.jsp"); 

curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$response = curl_exec ($ch); 
curl_close ($ch); 
$response = json_decode($response); 
print_r($response); 

는 응답이 같은 JSON 객체가 될 것입니다,

{"req_id":"809ff62f-74a9-45a5-9cb5-5e60763289af","status":"0" ,"comment":"OK"} 

하지만 난 내 templateCallback이 JSON 객체를 읽는 방법() 함수. 동일한 기능을 수행하는 함수가 내장되어 있습니까?

답변

2

템플릿 콜백은 PHP 파일입니다. 그런 다음 요청을 구문 분석해야합니다. 이 같은

뭔가 :

$json = file_get_contents('php://input'); 
$obj = json_decode($json, TRUE);