2016-07-12 15 views
0

私はPHPのfirebase通知スクリプトを使用していますが、通知を送信するには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

それはあなたのコントローラ

+0

こんにちはミハイルでこのphp #{RAILS_ROOT}/public/php_script.phpを書いてPHPスクリプトを実行することが可能である、私はまだRoRの言語に新しいですので、私はちょうど私のApplicationController.rbに次のことを書くのか? – iOSAndroid

+0

はい。 ApplicationController.rbに書き込んでみてください。 –