码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 推送证书

时间:2014-04-27 23:12:13      阅读:749      评论:0      收藏:0      [点我收藏+]

标签:com   class   blog   http   code   div   img   java   style   javascript   ext   

push 服务器证书

钥匙串:登入--》证书,选项里面导出证书命名为cert.p12,跟密钥命名为key.p12

需要将上面的2个.p12文件转成.pem格式:

openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12

 

openssl pkcs12 -nocerts -out key.pem -in key.p12

 

如果需要对 key不进行加密:

  

openssl rsa -in key.pem -out key.unencrypted.pem

 

然后就可以 合并两个.pem文件, 这个ck.pem就是服务端需要的证书了。

  

cat cert.pem key.unencrypted.pem > ck.pem

 

4个pem,另外加上php文件,打包放到服务器上

 

php推送代码

mamicode.com,码迷
 1 <?php
 2     $deviceToken = ‘c9b4b78b a78d9b3a 9104690f 95c35aa9 2e0e3c6a 6d3edb68 60b4571a fdcb6b3f‘;    //loganv-itouch
 3     // Get the parameters from http get or from command line
 4     $message = $_GET[‘message‘] or $message = $argv[1] or $message = ‘hi from loganv!‘;
 5     $badge = (int)$_GET[‘badge‘] or $badge = (int)$argv[2] or $badge = 9;
 6     $sound = $_GET[‘sound‘] or $sound = $argv[3] or $sound = ‘default‘;
 7     // Construct the notification payload
 8     $body = array();
 9     $body[‘aps‘] = array(‘alert‘ => $message);
10     if ($badge)
11     $body[‘aps‘][‘badge‘] = $badge;
12     if ($sound)
13     $body[‘aps‘][‘sound‘] = $sound;
14     /* End of Configurable Items */
15     $ctx = stream_context_create();
16     stream_context_set_option($ctx, ‘ssl‘, ‘local_cert‘, ‘ck.pem‘);
17     // assume the private key passphase was removed.
18     //stream_context_set_option($ctx, ‘ssl‘, ‘passphrase‘, $pass);
19     // connect to apns
20     $fp = stream_socket_client(‘ssl://gateway.sandbox.push.apple.com:2195‘, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
21     if (!$fp) {
22         print "Failed to connect $err $errstr\n";
23         return;
24     }
25     else {
26         print "Connection OK\n<br/>";
27     }
28     // send message
29     $payload = json_encode($body);
30     $msg = chr(0) . pack("n",32) . pack(‘H*‘, str_replace(‘ ‘, ‘‘, $deviceToken)) . pack("n",strlen($payload)) . $payload;
31     print "Sending message :" . $payload . "\n";  
32     fwrite($fp, $msg);
33     fclose($fp);
34     ?>
mamicode.com,码迷

 

iOS 推送证书,码迷,mamicode.com

iOS 推送证书

标签:com   class   blog   http   code   div   img   java   style   javascript   ext   

原文地址:http://www.cnblogs.com/loganv/p/3695206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!