2016-07-12 4 views
0

질문이 있습니다. PHP 기반의 firebase 알림 스크립트가 있습니다.하지만 알림을 보내려는 RoR 서버를 원한다면 XAMPP를 통해 로컬로 알림을 보내고 있습니다. 전체 코드를 다시 코딩해야합니까? 루비 스크립트에 PHP 스크립트? 아니면 그냥 RoR 서버에서 내 PHP 스크립트를 직접 호출 할 수 있습니까?ROR Firebase 알림

아래는 제 작업 PHP 스크립트입니다.

function send_notification($tokens, $message) 
{ 
$url = "https://fcm.googleapis.com/fcm/send"; 
$fields = array(
    'registration_ids' => $tokens, 
    'data' => array("message"=> $message) , 
); 

$headers = array(
    'Authorization:key = AuthorizationKey', 
    'Content-Type: application/json' 
); 

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_POST,true); 
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); 
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields)); 

$result = curl_exec($ch); 
if ($result === FALSE) 
{ 
die('Curl Failed:' . curl_error($ch)); 
} 
curl_close($ch); 

return $result; 
} 

$conn = mysqli_connect("localhost","root","","demoflying");  

$sql = "Select Token From Users"; 

$result = mysqli_query($conn,$sql); 
$tokens = array(); 

if(mysqli_num_rows($result)>0) 
{ 
    while ($row = mysqli_fetch_assoc($result)) 
    { 
     $tokens[] = $row["Token"]; 
    } 
} 

mysqli_close($conn); 

$fromCountry = "UK"; 
$toCountry= "US"; 

$message = array(
    "FromCountry" => $fromCountry, 
    "ToCountry" => $toCountry, 
); 
$message_status = send_notification($tokens,$message); 
echo $message_status; 
?> 

답변

0

내가 RoR에 언어에 여전히 새로운 오전, 그래서 난 그냥 내 ApplicationController.rb에 다음 쓰기 컨트롤러

+0

안녕 미하일이 php #{RAILS_ROOT}/public/php_script.php를 작성하는 PHP 스크립트를 실행할 수 있습니까? – iOSAndroid

+0

예. ApplicationController.rb에 쓰기를 시도하십시오. –