2012-08-03 2 views
0

OneAPI SMS 인터페이스를 사용하여 cURL을 사용하여 내 응용 프로그램에서 SMS 메시지를 보내려고합니다.GSMA OneApi에서 SMS 보내기

그것은 500 오류를 반환하고 여기 내가 사용하고 코드입니다 :

<?php 
$url = "https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel%3A%2B1234/requests"; 
$username = "secret"; 
$password = "secret"; 

$request = array(
    'address' => 'tel%3A%2B1222333444', 
    'message' => 'hello world', 
    'senderAddress' => 'tel%3A%2B1234', 
    'senderName' => 'joe doe' 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request)); 
$output = curl_exec($ch); 
$info = curl_getinfo($ch); 
curl_close($ch); 
print_r($info); 
?> 

이 어떤 도움이 어떤 도움을 크게

을 감상 할 수있다 할 woudl. 고맙습니다!

P.

Array ([url] => https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel%3A%2B1416XXXYYYY/requests 
[content_type] => application/json [http_code] => 500 [header_size] => 494 [request_size] => 349 
[filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.333515 [namelookup_time] => 0.000335 
[connect_time] => 0.054989 [pretransfer_time] => 0.229044 [size_upload] => 97 [size_download] => 172 [speed_download] => 515 
[speed_upload] => 290 [download_content_length] => -1 [upload_content_length] => 97 [starttransfer_time] => 0.333474 [redirect_time] => 0 [certinfo] => Array ()) 

은 조상을 위해

를 해결 : 컬이 작동하지 않는 몇 가지 이유를 들어, file_get_contents() 그래서 갈 수있는 방법입니다.

+0

오류를 포함 할 수 있습니까? 또한 사용자 이름과 암호를 고유 한 값으로 설정하고 대상 주소를 유효한 값으로 설정 했습니까? –

+0

senderAddress 7511을 사용해 볼 수 있습니까? 이 짧은 코드를 사용하여 샌드 박스 환경에서 샌드를 수행해야합니다. –

+0

입력 해 주셔서 감사합니다! 게시물을 업데이트했습니다. 7511을 사용하려고했지만 도움이되지 않았습니다. 분명히 나는 ​​내 자신의 가치관을 사용하고있다. 그래서 나는 그들의 매뉴얼을 확인했다 : 500 - Internal Error 500; 서버가 요청을 수행하지 못하게하는 예기치 않은 조건을 발견했습니다. – mikek

답변

0

JSON에서 매개 변수 값을 게시하는 경우 값을 URL 인코딩하면 안됩니다. JSON 대신 'form post'를 사용하는 경우에 필요합니다.

커맨드 라인 curl을 사용하여 동일한 요청을 시도하십시오. 500 리턴 코드와 함께 제공되는 서버 오류의 세부 사항을 가져올 수 있어야합니다.

0

분명히, 나는이 퍼즐을 cURL로 해결했습니다. 문제는 구문에있었습니다. API 용으로 작동하는 PHP 솔루션을 소개합니다.

Class SendSMS { 

     public $phone_number; 

     public function __construct($phone_number) { 
      $this->phone_number = $phone_number; 
     } 

     public function oneAPI() {  
      $url = "https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel%3A7511/requests"; // END POINT 
      $username = 'secret'; // APP's login 
      $password = 'secret'; // and psswd 

      $request = array(
       'address' => $this->phone_number, 
       'message' => 'hello world', 
       'senderAddress' => 'tel:7511' 
      ); 

      $request = http_build_query($request); 

      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // hide output 
      $output = curl_exec($ch); 
      $info = curl_getinfo($ch); 
      curl_close($ch); 

     } 

    } 

    $hello = new SendSMS('+1XXXXXXXXX'); // WHITE LISTED PHONE 

    $hello->oneAPI();