Ios 推送通知 PHP 脚本不适用于 Ubuntu 14.04
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端口的问题,请问如何解决!
这对 link 非常有帮助:
http://php.net/manual/en/migration56.openssl.php
http://php.net/manual/en/context.php
描述 openssl 在 PHP 5.6 中所做更改的官方文档
多了解一个 Tou 应该设置为 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; ?>
我正在开发一个使用 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端口的问题,请问如何解决!
这对 link 非常有帮助:
http://php.net/manual/en/migration56.openssl.php http://php.net/manual/en/context.php
描述 openssl 在 PHP 5.6 中所做更改的官方文档 多了解一个 Tou 应该设置为 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; ?>