forked from jPaolantonio/SimplePush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplepush.php
52 lines (35 loc) · 1.24 KB
/
simplepush.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
$deviceToken = 'cd709e03d85823af923a21d63863bbc123a1456b1f31633873d46d68450a6d86';
$message = 'iPad!';
$body['aps'] = array(
'alert' => $message,
'badge' => 18
);
//$body['category'] = 'message';
$body['category'] = 'profile';
//$body['category'] = 'dates';
//$body['category'] = 'daily_dates';
//$body['sender'] = 'jamesHAW';
$body['sender'] = 'jerrytest35';
//Server stuff
$passphrase = '';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ipad_sandbox.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
fclose($fp);
?>