我有一个godaddy 专用服务器,我在其上安装了godaddy 的SSL 证书。
我正在使用以下脚本发送推送通知
$passphrase = 'pass';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '../folder/file/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.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(
'alert' => $message,
'sound' => 'default',
'badge' => 1,
'category' => 'NOTIFICATION'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
fclose($fp);
当我从浏览器运行此代码时,我会收到通知,但是当我从 cron 作业运行相同的代码时,它给了我无法连接错误。
我从终端运行脚本它给了我以下错误
stream_socket_client(): Failed to enable crypto
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)