Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var title = data.title;
- console.log ('title ', title);
- var custom= data['custom'];
- console.log('custom ', custom);
- });
- <?php
- require_once "connection.php";
- $url = 'https://android.googleapis.com/gcm/send';
- $apiKey = 'my_api_key';
- $message = array(
- 'message' => 'test message',
- 'title' => 'test title',
- 'custom' => $myVar
- );
- $myVar = "34";
- $registatoin_ids = array();
- $selezione = "SELECT * FROM table";
- $update = mysqli_query($conn, $selezione);
- while ($row = $update->fetch_assoc()) {
- array_push($registatoin_ids, $row["gcm_id"]);
- echo($row["gcm_id"]);
- }
- $fields = array(
- 'registration_ids' => $registatoin_ids,
- 'data' => $message
- );
- $test = json_encode($fields['data']);
- echo($test);
- $headers = array( 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //curl connection
- $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);
- curl_close($ch);
- echo $result;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement