我正在使用php作为我的后端向我的ios应用程序发送推送通知。这是我的代码:
$deviceToken = "XXXX";
$ctx = stream_context_create();
// ck.pem is your certificate file
stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'] . '/uploads/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'xxxx');
// 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);
// Create the payload body
$body['aps'] = array(
'alert' => array(
'title' => "haia",
'body' => "how are you",
),
'sound' => 'default'
);
// 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));
// Close the connection to the server
fclose($fp);
if (!$result)
return 'Message not delivered' . PHP_EOL;
else
return 'Message successfully delivered' . PHP_EOL;
在上面的代码中我收到此错误
Message: stream_socket_client(): Unable to set private key file `/home/developer/workspace/codeigniter/Ekattor/uploads/ck.pem'
Message: stream_socket_client(): failed to create an SSL handle
Message: stream_socket_client(): Failed to enable crypto
Message: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)
但是当我从stream_socket_client()函数中删除ssl时,它不会显示任何错误。如果我在stream_socket_client()中包含ssl,则显示上述错误。我看到已经解决了答案,但我没有运气。请有人帮我解决这个问题