Php IOS中的推送通知-握手失败
每当我尝试发送推送通知时,它都会抛出多个错误, 我研究得很好,但没有解决办法 1.流\u套接字\u客户端():SSL操作失败,代码为1。OpenSSL错误消息: 错误:14094410:SSL例程:SSL3_读取字节:sslv3警报握手失败 - 2.严重性:警告 消息:流\u套接字\u客户端():无法启用加密 - 3.严重性:警告 消息:流\u套接字\u客户端():无法连接到ssl://gateway.sandbox.push.apple.com:2195 (未知错误) - 4.连接失败:0 下面是我的代码:Php IOS中的推送通知-握手失败,php,ios,push-notification,apple-push-notifications,Php,Ios,Push Notification,Apple Push Notifications,每当我尝试发送推送通知时,它都会抛出多个错误, 我研究得很好,但没有解决办法 1.流\u套接字\u客户端():SSL操作失败,代码为1。OpenSSL错误消息: 错误:14094410:SSL例程:SSL3_读取字节:sslv3警报握手失败 - 2.严重性:警告 消息:流\u套接字\u客户端():无法启用加密 - 3.严重性:警告 消息:流\u套接字\u客户端():无法连接到ssl://gateway.sandbox.push.apple.com:2195 (未知错误) - 4.连接失败:0 下
// Sends Push notification for iOS users
public function iOS($data, $devicetoken)
{
$deviceToken = $devicetoken;
$passphrase= "";
$ctx = stream_context_create();
// ck.pem is your certificate file
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.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' => $data['mtitle'],
'body' => $data['mdesc'],
),
'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;
}
有人能帮我整理一下吗?添加以下行
stream_context_set_option( $ctx , 'ssl', 'verify_peer', false);
若您在生成pem文件时设置了密码,那个么您必须在下面的行中提到它
$passphrase= "";
如果您没有设置,那么这个错误是由于pem文件。它没有正确生成。可能是您的pem文件没有正确生成pem文件。我同意。如果您没有正确生成pem文件。您将得到错误。我已经用我的pem文件测试了您的代码,并且工作正常。即使我也面临同样的问题创建pem文件时您是否设置了密码那你就用密码说了