有关push.~
利用终端进行证书的生成:
1.
openssl pkcs12 -clcerts -nokeys -out cert.pem -in
Certificates.p12
2.
openssl pkcs12 -nocerts -out key.pem -in Certificates.p12
3.
openssl rsa -in key.pem -out key.unencrypted.pem
4.
cat cert.pem key.unencrypted.pem > ck.pem
php代码:
1 #!/Applications/XAMPP/xamppfiles/bin/php
2 <?php
3 $deviceToken = '9d232cf5 93fc0e52 04ae6a13 00eb2649 633e3d5a ad37c389 6c912609 c2d4c046'; // masked for security reason
4 // Passphrase for the private key (ck.pem file)
5 $pass = '1234';
6 // Get the parameters from http get or from command line
7 $message = $_GET['message'] or $message = $argv[1] or $message = 'Message received from javacom';
8 $badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
9 $sound = $_GET['sound'] or $sound = $argv[3];
10
11 $message = 'This is message';
12 $badge = 1;
13 $sound = 'cowbell.wav';
14
15 // Construct the notification payload
16 $body = array();
17 $body['aps'] = array('alert' => $message);
18 if ($badge)
19 $body['aps']['badge'] = $badge;
20 if ($sound)
21 $body['aps']['sound'] = $sound;
22 /* End of Configurable Items */
23 $ctx = stream_context_create();
24 stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
25 // assume the private key passphase was removed.
26 // stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
27 $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
28 if (!$fp) {
29 print "Failed to connect $err $errstrn";
30 return;
31 }
32 else {
33 print "Connection OK\n";
34 }
35 $payload = json_encode($body);
36 $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
37 print "sending message :" . $payload . "\n";
38 fwrite($fp, $msg);
39 fclose($fp);
40 ?>
利用终端运行:
通过命令符:php ./php文件名.php
来进行运行。