Advertisement
Guest User

Untitled

a guest
May 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. var title = data.title;
  2. console.log ('title ', title);
  3. var custom= data['custom'];
  4. console.log('custom ', custom);
  5. });
  6.  
  7. <?php
  8. require_once "connection.php";
  9. $url = 'https://android.googleapis.com/gcm/send';
  10. $apiKey = 'my_api_key';
  11. $message = array(
  12. 'message' => 'test message',
  13. 'title' => 'test title',
  14. 'custom' => $myVar
  15. );
  16. $myVar = "34";
  17.  
  18. $registatoin_ids = array();
  19. $selezione = "SELECT * FROM table";
  20. $update = mysqli_query($conn, $selezione);
  21. while ($row = $update->fetch_assoc()) {
  22. array_push($registatoin_ids, $row["gcm_id"]);
  23. echo($row["gcm_id"]);
  24. }
  25.  
  26. $fields = array(
  27. 'registration_ids' => $registatoin_ids,
  28. 'data' => $message
  29. );
  30.  
  31.  
  32. $test = json_encode($fields['data']);
  33. echo($test);
  34. $headers = array( 'Authorization: key=' . $apiKey,
  35. 'Content-Type: application/json'
  36. );
  37.  
  38. //curl connection
  39. $ch = curl_init();
  40. curl_setopt($ch, CURLOPT_URL, $url);
  41. curl_setopt($ch, CURLOPT_POST, true);
  42. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  43. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  44. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  45. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  46. $result = curl_exec($ch);
  47. curl_close($ch);
  48. echo $result;
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement