1<?php
2
3$deviceToken = '8845ba7c41e95e12caea6381ea6f01b5cd7b59a52feb9005e0727a65a4105dc2a0';
4
5$passphrase = '';
6
7$message = 'Your message';
8
9
10$ctx = stream_context_create();
11stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
12stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
13
14// Open a connection to the APNS server
15$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
16
17if (!$fp)
18 exit("Failed to connect: $err $errstr" . PHP_EOL);
19
20echo 'Connected to APNS' . PHP_EOL;
21
22
23$body['aps'] = array(
24 'alert' => array(
25 'body' => $message,
26 'action-loc-key' => 'Bango App',
27 ),
28 'badge' => 2,
29 'sound' => 'oven.caf',
30 );
31
32$payload = json_encode($body);
33
34// Build the binary notification
35$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
36
37
38$result = fwrite($fp, $msg, strlen($msg));
39
40if (!$result)
41 echo 'Message not delivered' . PHP_EOL;
42else
43 echo 'Message successfully delivered' . PHP_EOL;
44
45fclose($fp);
1<?php
2
3define( 'API_ACCESS_KEY', 'AIza......Xhdsnkf' ); // get API access key from Google/Firebase API's Console
4
5$registrationIds = array( 'cyMSGTKBzwU:APA91...xMKgjgN32WfoJY6mI' ); //Replace this with your device token
6
7
8// Modify custom payload here
9$msg = array
10(
11 'mesgTitle' => 'SMART TESTING',
12 'alert' => 'This is sample notification'
13
14);
15$fields = array
16(
17 'registration_ids' => $registrationIds,
18 'data' => $msg
19);
20
21$headers = array
22(
23 'Authorization: key=' . API_ACCESS_KEY,
24 'Content-Type: application/json'
25);
26
27$ch = curl_init();
28curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); //For firebase, use https://fcm.googleapis.com/fcm/send
29
30curl_setopt( $ch,CURLOPT_POST, true );
31curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
32curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
33curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
34curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
35$result = curl_exec($ch );
36curl_close( $ch );
37echo $result;
38
39?>
40