Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向多个iphone设备发送推送通知时获取警告消息_Php_Apple Push Notifications - Fatal编程技术网

Php 向多个iphone设备发送推送通知时获取警告消息

Php 向多个iphone设备发送推送通知时获取警告消息,php,apple-push-notifications,Php,Apple Push Notifications,当我使用php Web服务向多个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-clie

当我使用php Web服务向多个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);
}
$message='testing';
$q1=“从tbl\U设备会话中选择设备会话”;
$re1=mysql\U查询($q1);
而($row1=mysql\u fetch\u row($re1))
{
pushMessage($row1[0],$message,'myapp');
}
函数pushMessage($deviceToken、$message、$app){
echo“将iPhone推送通知发送到“$deviceToken”。

”; 回显“您的消息:”.$Message.“

”; $time=time(); $apnsHost='gateway.push.apple.com'; $apnsPort=2195; $apnsCert='apns myapp.pem'; $streamContext=stream_context_create(); stream_context_set_选项($streamContext,'ssl','local_cert',$apnsCert); $apns=stream_socket_client('ssl://'.$apnsHost'.:'.$apnsPort,$error,$errorString,2,stream_client_CONNECT,$streamContext); 若有($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); }否则{ echo“连接失败-iPhone推送通知服务器”; echo$errorString。“
”; echo$错误。“
”; } //插座关闭($apns); fclose($apns); }

那么,有人能告诉我如何解决这个问题吗?

这似乎是一个愚蠢的答案,但你试过防火墙/iptables吗?这些没有进一步信息的错误在我看来像是连接问题。您需要解决的第一件事是超时问题。

将单个通知推送到单个设备时,是否仍会发生这种情况

如果有:

  • 你确定你有正确的证书路径吗
  • 确保证书文件名不包含字母以外的字符
如果没有:

  • 确保您在正确的设备环境(开发、生产)中使用了正确的证书
  • 如果设备被越狱,它将不会收到推送通知

请发布您的代码。请看,这不是您的完整代码。粘贴您的完整代码。是的,当我向单个设备发送推送通知时,会收到警告消息,即使给出了证书的正确路径并且证书文件名中不允许使用字母字符