0

Bu, terminal aracılığıyla bildirim göndermek için benim curl komutumdur. Düzgün fakat (XHR isteği kullanarak) düğmesi tıklandığında bildirim göndermek için nasılXHR (Ajax) kullanarak GCM aracılığıyla bir push bildirimi nasıl gönderilir?

curl --header "Authorization: key=AIzaSyCjrU5SqotSg2ybDLK0dMusvY" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"f5xzshqcfDE2qiKGJu858nFhqGCuk0uuUC6vm\"]}" 

cevap

0

Sen javascript veya seçtiğiniz diğerleri gibi bir amaca hizmet ve sadece müşteri ile bir XHR isteği yapmak için bir php script yazabilirsiniz işleri . İşte benim php senaryosunu aylar önce yaptım ve çalışıyor.

<?php 
    $message = "\": 3,\"title\": \"High score alert!\",\"\": true,\"custom_field\": { \"score\": 51,\"headlines\": \"And now for something completely different...\" }}"; 
    $apiKey = "Your Key"; 
    $registrationIDs = array("Registration id"); 
    $url = 'https://android.googleapis.com/gcm/send'; 
    // Set POST variables 
    $notify = array(
     "alert"=> "great match!", 
     "title"=> "Portugal vs. Denmark", 
     "icon" => "myicon", 
     "badge"=>3, 
     "vibrate"=>true, 
    "notification"=>"message" 
    ); 

    $fields = array(
    'registration_ids' => $registrationIDs, 
    'data' => array("payload" => $notify, 
    "notification"=>json_encode($notify))); 
    $headers = array(
    'Authorization: key=' . $apiKey, 
    'Content-Type: application/json' 
    ); 
    $ch = curl_init(); // Open connection 
    curl_setopt($ch, CURLOPT_URL, $url); 
    // Set the url, number of POST vars, POST data 
    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)); 
    var_dump($url); 
    var_dump($headers); 
    var_dump(json_encode($fields)); 
    $result = curl_exec($ch); // Execute post 
    if($result === false) 
    die('Curl failed ' . curl_error()); 
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    curl_close($ch); 
    $response = json_decode($result); 
    print_r($response); 
    ?> 
+0

Cevabınız için teşekkürler ama orada javascript –

+0

bunu yapmak herhangi bir şekilde php.Is kullanmak istemiyorsanız javascript Eğer uygun ya nedir? – Technacron

+0

evet ajax da kullanabilirim ..... ajax, jquery @Asim Khan –