1

我用下面的PHP腳本來發送推送通知,並使用「WAMP服務器」IOS推送通知本地工作,但不是在BlueHost的

如果從我的本地計算機發送它的工作完美,但我現在使用BlueHost的服務,並買了一專用IP和他們開了APNS端口我2195和2196

,但我總是收到「APNS連接失敗:0」,而同樣的代碼工作完美的本地

任何幫助傢伙?並提前致謝。

stream_socket_client():無法啓用加密在 /public_html/simplepush.php

stream_socket_client():無法連接到 SSL://gateway.sandbox.push.apple.com:2195 (未知錯誤)在 /public_html/simplepush.php

代碼:

<?php 




//$tHost = 'gateway.sandbox.push.apple.com'; 
$tHost = 'gateway.sandbox.push.apple.com'; 
$tPort = 2195; 
// Provide the Certificate and Key Data. 

$tCert = 'Key.pem'; 
$tPassphrase = 'mypasssss'; 
$tToken = "5d0897edddb84f38b951109dce8b99b7a7c7446d57b78a154f057d47dd878ac2"; 

$tAlert = 'New news has been added'; 
$tBadge = 1; 
$tSound = 'default'; 
$tPayload = 'xxx'; 

$tBody['aps'] = array (
'alert' => $tAlert, 
'badge' => $tBadge, 
'sound' => $tSound, 
); 

$tBody ['payload'] = $tPayload; 
$tBody = json_encode ($tBody); 

$tContext = stream_context_create(); 
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert); 
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase); 

// Open the Connection to the APNS Server. 
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext); 
// Check if we were able to open a socket. 
if (!$tSocket) 
exit ("APNS Connection Failed: $error $errstr" . PHP_EOL); 

// Build the Binary Notification. 
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody; 

// Send the Notification to the Server. 
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg)); 
if ($tResult) 
echo 'Delivered Message to APNS' . PHP_EOL; 
else 
echo 'Could not Deliver Message to APNS' . PHP_EOL; 
// Close the Connection to the Server. 
fclose ($tSocket); 

?> 

回答

0

每一個面臨這個問題去和生成一個新的新的.pem文件和一切都會工作