无法连接到SSL://gateway.push.apple.com:2195 [英] unable to connect to ssl://gateway.push.apple.com:2195

查看:495
本文介绍了无法连接到SSL://gateway.push.apple.com:2195的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我Web服务使用PHP工作。在这我需要使用APNS生成设备上的通知,但它提供了以下错误无法连接到SSL://gateway.push.apple.com:2195

hi i am working on web services using php. in this i need to generate notification on the device using APNS but its gives following error unable to connect to ssl://gateway.push.apple.com:2195

我的code是继plz帮助我

my code is following plz help me

<?php
echo '<pre>';
echo 'APNCRON: Started at '.date("Y-m-d H:i:s")."\n";

$apnsHost = 'gateway.push.apple.com'; //gateway.push.apple.com //gateway.sandbox.push.apple.com
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem'; //replace with the appropriate production cert.

//include config.php here
      $con = mysql_connect('localhost','sunil_myapns','fIgBMQ?(G?T_') or die("Could not connect to host.");
      $database = mysql_select_db('sunil_myapns',$con) or die("Could not find database.");    

/**
loop the result 
send payload
*/
/*$sql = 'SELECT p.dev_token, 
        (SELECT COUNT(id) FROM tbl_news s WHERE s.created_date > p.last_access_time) AS cnt
        FROM
        tbl_apn p';*/ //This sql to give you an idea
//echo $sql; 
$sql = 'SELECT * from person';
//echo $sql;
$result = mysql_query($sql);

if(!result)
{
    echo 'APNCRON: Error while executing the query :'.mysql_error();//exit;
}

$rows = mysql_num_rows($result);
//echo $noDev2Push;exit;
if(!$rows)
{
    echo 'APNCRON: No update'; exit;
}

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'tcp', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 120, STREAM_CLIENT_CONNECT, $streamContext);

$i=0;

while($row = mysql_fetch_array($result))
{

    $deviceToken    = 'abcbc12f8d7006be4a544237428f071697bb342608f6408af725ca94ae848ee5'; // remember that devToken is 64 char string
    $cntUpdate = $row['id'];


    $payload = array();
    $payload['aps'] = array(
                                //'alert' => '',    //we are not sending popup alerts 
                                'badge' => (int) $cntUpdate, 
                                'sound' => 'default'
                            );

    $payload = json_encode($payload);
    $i++;
    //echo $payload; echo "\n";

    $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

    //echo $apnsMessage; echo "\n";

    fwrite($apns, $apnsMessage);
}

fclose($apns);

echo 'APNCRON: Completed at '.date("Y-m-d H:i:s")."\n";
echo 'Sent APN to '.$i.' device(s) ';//.date("Y-m-d H:i:s")."\n";
//socket_close($apns);


?>

在此先感谢

推荐答案

我能使用telnet连接到主机:从我家机端口就好了。最有可能的防火墙的东西是走IP /端口上月底,还是苹果和/或Akamai的已阻止你过的某些原因。

I'm able to use telnet to connect to that host:port just fine from my home machine. Most likely something firewalled away that ip/port on your end, or Apple and/or Akamai have blocked you off for some reason.

这篇关于无法连接到SSL://gateway.push.apple.com:2195的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆