2016-03-31 21 views

答えて

0

コントローラに以下の機能を貼り付け、GCMキーを変更する必要があります。

 
public function androidPushNotification($registration_ids, $message) { 

     $registrationIds = array($registration_ids); 
     $msg = array('message' => $message, 'title' => 'test notification', 'vibrate' => 1, 'sound' => 1); 
     $fields = array('registration_ids' => $registrationIds, 'data' => $msg); 
     $headers = array('Authorization: key=', 'Content-Type: application/json'); 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
     $result = curl_exec($ch); 
     curl_close($ch); 
     $data = json_decode($result); 
     if ($data->success == 1) { 
      $return = 'SUCCESS'; 
     } else if ($data->failure == 1) { 
      $return = 'FAILURE'; 
     } 
     return $return; 
    }