我在 php 中使用以下代码进行分发中的 APNS 通知。我的代码适用于我的服务器,但是当我将服务器转移到爸爸时,应用程序将停止通知并响应failed to connect : 0
我的代码
$message=stripslashes($_POST['message']);
$sql='insert into message set message = "'.$message.'"';
$res=mysql_query($sql);
$query="select deviceId from pushnotification";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
//$deviceToken = '76dcc65ccd155180ff56a15a539173137e38c9dde363d648e5f17343e0940c8d';
$deviceToken = $row['deviceId'];
$passphrase = '******';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
//echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$resultmsg = fwrite($fp, $msg, strlen($msg));
if (!$resultmsg)
$msg='Message not delivered' . PHP_EOL;
else
$msg='Message successfully delivered' . PHP_EOL;
fclose($fp);
任何帮助将不胜感激谢谢