我在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);
任何帮助将不胜感激 感谢
答案 0 :(得分:0)
做了非常hotch potch之后,再次创建我的私钥并再次为我的app Id创建ssl证书。它奏效了。这完全是关于应用密钥和证书,代码很好。