[英]Ios push-notification PHP script not working for Ubuntu 14.04
我正在使用iOS推送通知的iOS应用程序。 我想从我的Windows PC上的PHP脚本发送通知。 我使用这个PHP脚本发送通知,它也运行良好:
// Put your device token here (without spaces):
$deviceToken = 'sdsdsdsdsczc2';
$sound = '';
// Put your private key's passphrase here:
$passphrase = 'awertf';
// Put your alert message here:
$message = 'My first push notification!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.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;
// Create the payload body
$body['aps'] = array(
'badge' => +1,
'alert' => $message,
'sound' => $sound
);
// Encode the payload as JSON
$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;
// Close the connection to the server
fclose($fp);
这个PHP脚本在Windows上运行良好,但现在我正在使用Ubuntu 14.04操作系统和相同的PHP脚本给我错误。
Message: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
我猜这是与2195端口有关的东西。但是如何解决这个问题!
这是一个非常有用的链接,可以找到:
http://php.net/manual/en/migration56.openssl.php http://php.net/manual/en/context.php
一篇官方文档,描述了在PHP 5.6中对openssl所做的更改。学习另一个参数应该设置为false / true是有用的:例如“verify_peer_name”=> false
所以一些代码看起来像这样:
<?php
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents('ssl://'.$host.':'.$port, false, stream_context_create($arrContextOptions));
echo $response; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.