iOS APNS推送Java、c# P12证书和Php pem证书制作

Java、c# P12证书:http://www.jianshu.com/p/4282...
Php pem证书制作:http://blog.csdn.net/dztianyu...

有可能出现的错误:

1.执行php push.php时报错 :

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Users/songhua/Desktop/推送证书文件/Php-Push/push.php on line 30

Warning: stream_socket_client(): Failed to enable crypto in /Users/songhua/Desktop/推送证书文件/Php-Push/push.php on line 30

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/songhua/Desktop/推送证书文件/Php-Push/push.php on line 30
Failed to connect 0 

解决方案:

去下载https://entrust2048.bj.bcebos... 网关文件并在push.php文件里加入stream_context_set_option($ctx,'ssl','cafile','entrust_2048_ca.cer');

php推送代码,entrust_2048_ca.cer、pem和php必须在同一个目录下:

 $message);  
if ($badge)  
  $body['aps']['badge'] = $badge;  
if ($sound)  
  $body['aps']['sound'] = $sound;  
//把数组数据转换为json数据  
$payload = json_encode($body);  
echo strlen($payload),"\r\n";  
  
//下边的写法就是死写法了,一般不需要修改,  
//唯一要修改的就是:ssl://gateway.sandbox.push.apple.com:2195这个是沙盒测试地址,ssl://gateway.push.apple.com:2195正式发布地址  
$ctx = stream_context_create();  
// $pem = dirname(__FILE__) .'/'.'phpck.pem';
stream_context_set_option($ctx, 'ssl', 'local_cert', 'phpck.pem');
stream_context_set_option($ctx,'ssl','cafile','entrust_2048_ca.cer');   
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);  
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);  
if (!$fp) {  
    print "Failed to connect $err $errstr\n";  
    return;  
}  
else {  
   print "Connection OK\n
"; } // send message $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload; print "Sending message :" . $payload . "\n"; fwrite($fp, $msg); fclose($fp); ?>

你可能感兴趣的:(ios,push)