gpt4 book ai didi

php - 向多个 iPhone 设备发送推送通知时收到警告消息

转载 作者:搜寻专家 更新时间:2023-10-31 21:12:11 24 4
gpt4 key购买 nike

当我使用 php 网络服务向多个 iphone 设备发送推送通知时,我收到如下警告消息:

Warning: stream_socket_client() [function.stream-socket-client]: SSL: crypto enabling timeout in /home/sample_app/pushnotification.php on line 66

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/sample_app/pushnotification.php on line 66

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) in /home/sample_app/pushnotification.php on line 66

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/sample_app/pushnotification.php on line 79

这是我的代码:

$message='testing';
$q1="select devicetoken from tbl_devicetokens";
$re1 = mysql_query($q1);
while($row1=mysql_fetch_row($re1))
{
pushMessage($row1[0],$message,'myapp');
}


function pushMessage($deviceToken,$message,$app) {
echo "Sending iPhone Push Notifications to " . $deviceToken . "<br /><br />";
echo "Your Message: " . $message . "<br /><br />";
$time = time();
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-myapp.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns) {
$payload = array();
$payload['aps'] = array('alert' => $message, 'badge' => 0, 'sound' => 'default');
$payload = json_encode($payload);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
} else {
echo "Connection Failed - iPhone Push Notifications Server";
echo $errorString."<br />";
echo $error."<br />";
}
//socket_close($apns);
fclose($apns);
}

所以,谁能告诉我如何解决这个问题

最佳答案

这可能看起来是一个愚蠢的答案,但您是否尝试过您的防火墙/iptables?那些没有进一步信息的错误对我来说看起来像是连接问题。您首先需要解决的是超时问题。

关于php - 向多个 iPhone 设备发送推送通知时收到警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17205925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com