2016-06-14 1 views
0

J'utilise le plugin push de notification push chrome. Il envoie une notification à l'arrière-plan à android mais je ne connais pas la clé pour aller chercher la réponse côté android. J'avais déjà "notification" "notifications" "données" .. Mais ils ne fonctionnaient pas. Aidez-moi, s'il vous plaît.Clé pour aller chercher la réponse de la notification push chromée côté android

public function sendGCM($data) 
    { 
    $this->putNotificationOnQueue($data); 

    $apiKey = get_option('web_push_api_key'); 
    $url = 'https://android.googleapis.com/gcm/send'; 
    $id = $this->getClientIds(); 

    if (empty($id)) { 
     return 'No subscribers on your site yet!'; 
    } 

    if (count($id) >= 1000) { 
     $newId = array_chunk($id, 1000); 
     foreach ($newId as $inner_id) { 
      $fields = array(
       'registration_ids' => $inner_id, 
      ); 
      $headers = array(
       'Authorization: key=' . $apiKey, 
       '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_VERIFYPEER, false); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
      $result = curl_exec($ch); 
      //print_r($result); 
     } 
    } else { 
     $fields = array(
      'registration_ids' => $id, 
     ); 
     $headers = array(
      'Authorization: key=' . $apiKey, 
      '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_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
     $result = curl_exec($ch); 
    } 

    $answer = json_decode($result); 
    curl_close($ch); 

    if ($answer) { 
     $this->cleanClientIds($answer); 
    } 

    return $result; 
} 
+0

foreach ($ newID comme inner_id $) { $ champs = array ( 'registration_ids de => $ inner_id, 'les données' => $ data,); $ headers = array ( 'Autorisation: clé ='. $ ApiKey, 'Type de contenu: application/json'); } –

Répondre

0

foreach ($ newID comme inner_id $) {$ Les champs = array ('registration_ids de => $ inner_id, 'data'=> $ data,); $ headers = array ('Autorisation: key ='. $ apiKey, 'Content-Type: application/json'); }