2016-04-09 7 views
1

Ich bin nicht in der Lage, die Benachrichtigung zu schieben.
meine Antwort ist:Ich kann die Benachrichtigung nicht drücken

"{\"multicast_id\":8319582670472068768,\"success\":0,\"failure\":3,\"canonical_ids\":0,\"results\":[{\"error\":\"InvalidRegistration\"},{\"error\":\"InvalidRegistration\"},{\"error\":\"InvalidRegistration\"}]}" 

Code:

public function sendNotification($registration_ids,$message){ 


    $url = 'https://android.googleapis.com/gcm/send';   

    $fields = array(
     'registration_ids' => $registration_ids, 
     'data' => $message, 
    ); 

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

    $curl = curl_init(); 

    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($fields)); 

    $result = curl_exec($curl); 
    if ($result === FALSE) { 
     die('Curl failed: ' . curl_error($curl)); 
    } 

    error_log("Response from GCM Server:".$result); 

    curl_close($curl); 
    return $result; 

Antwort

2

Dieses Problem tritt in der Regel, wenn Ihr API-Schlüssel ungültig ist. Welcher Statuscode ist die Antwort? Sie können mehr hier lesen: https://developers.google.com/cloud-messaging/http#checkAPIkey

Wenn Sie einen HTTP-Statuscode 401 erhalten, ist Ihr API-Schlüssel nicht gültig. Ansonsten Sie sollten etwas sehen:

{"multicast_id":6782339717028231855,"success":0,"failure":1, "canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

Es ist auch bequemer sein kann für Sie ein Laravel Paket zu verwenden, die für Sie GCM Messaging Griffe: https://github.com/davibennun/laravel-push-notification/

Bitte lassen Sie mich wissen, was Statuscode, den Sie erhalten.

+0

Ich habe ein Ergebnis.Es ist sehr nützlich für mich. Danke ThePurpleK –

Verwandte Themen