我在尝试通过PHP发送推送通知时收到以下错误消息:
stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
我想这可能是过去SSL3问题的问题?但这是否意味着脚本不再可用了?我需要改变什么,因为我不知道。我检查了所有证书,他们正在工作。我可以通过终端使用证书连接到apple的沙盒,握手似乎可以通过终端工作。
这是我的PHP脚本
class PushNotification {
public function sendTestMessageToDevice($message){
$devicetoken = Config::get('mfsconfig.PushNotificationTest.deviceToken');
$passphrase = Config::get('mfsconfig.PushNotificationTest.passPhrase');
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open connection to APNS
$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'
);
// Encode the payload as JSON
$payload = json_encode($body);
// build a binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $devicetoken) . pack('n', strlen($payload)) . $payload;
// Send to server
$result = fwrite($fp, $msg, strlen($msg));
if(!result) {
echo 'Message not delivered' . PHP_EOL;
} else {
echo 'Message successfully delivered' . PHP_EOL;
}
fclose($fp);
}
答案 0 :(得分:1)
我想我得到了解决方案:
现在将p12文件转换为pem文件:
$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
上传新创建的pem文件后,一切顺利!