嗨,我正在使用php进行Web服务。在这个我需要使用APNS在设备上生成通知,但它提供以下错误无法连接到ssl://gateway.push.apple.com:2195
我的代码是关注plz帮助我
<?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);
?>
提前致谢
答案 0 :(得分:2)
我可以使用telnet连接到该主机:从我的家用机器上端口就好了。很可能是因为某种原因阻止了你的ip / port,或Apple和/或Akamai因某种原因阻止了你。
答案 1 :(得分:0)
如果您只是重复使用旧的证书签名请求(CSR),请确保在导出新的证书签名请求和私钥(作为p12文件)之前删除过期/旧的APN证书。
答案 2 :(得分:-2)
使用curl函数访问外部链接并从该
获取响应