【发布时间】:2015-09-12 16:00:53
【问题描述】:
我有一个 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)
【问题讨论】:
-
嗨@Tushar,你找到任何解决方案了吗
标签: apple-push-notifications apns-php