我在 stackoverflow 中遇到了同样的问题并尝试了所有答案但没有帮助。我不知道错误是什么。
这是我正在使用的功能:
function sendRegistryNotification($message, $deviceToken, $deviceType, $batchcount)
{
$message=$message;
$batchcount=$batchcount;
$path=ABSPATH.'api'.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'Certificates2.pem';
$deviceType = strtolower($deviceType);
switch ($deviceType) {
case 'ios':
$pemPath = $path; // replace with the path to PEM file
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $pemPath);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',
$err,
$errstr,
60,
STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,
$ctx);
// Create the payload body
$body['aps'] = array(
'badge' => +$batchcount,
'alert' => $message,
'sound' => 'default'
);
$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));
var_dump($result);
if (!$result)
{
fclose($fp);
return false;
}
else
{
fclose($fp);
return true;
}
break;
case 'android':
$message = array("message" => $message,'title'=> 'eyLog','msgcnt'=>$batchcount);
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => array($deviceToken),
'data' => $message,
);
$headers = array(
'Authorization: key='.'AIzaSyDud68-R31c9SPq4dXZblt0JBPi4TBaneQ', // Key For eylog App
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
//var_dump($result);
if ($result === FALSE) {
// die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
return TRUE;
break;
}
return true;
}
这是我遇到的错误:
{
"status": "failure",
"uniquediary_id": "14407503971",
"message": "fwrite(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry"
}
我不明白为什么会这样。并且代码只在我的本地主机中的服务器中出现错误,它工作正常
最佳答案
当您尝试写入套接字时。如果出现问题,fwrite 将返回 false 或 0(取决于 php 版本)作为返回值。当它发生时,您必须对其进行管理。
对于上述问题,原因很简单:当 SSL_Write 返回 SSL_ERROR_WANT_WRITE 或 SSL_ERROR_WANT_READ 时,您必须在满足条件(套接字上可读/写可用)后再次使用相同的参数重复调用 SSL_write。
使用不同的参数调用它,将产生 1409F07F bad write retry 错误。
关于php - fwrite() : SSL operation failed with code 1. OpenSSL 错误消息:\nerror:1409F07F:SSL 例程:SSL3_WRITE_PENDING:PHP 中的错误写入重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32350550/