Apple推动通知不起作用



我的php脚本总是给出Apple推动通知的错误代码0。我使用的代码在下面给出

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'passphrase', '');
stream_context_set_option($ctx, 'ssl', 'local_cert', 'TxxxProd.pem'); //TxxxDev.pem
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
stream_set_blocking ($fp, 0); 

$err总是返回0

我们在服务器上修改的是我们已升级了php版本,并且ssl证书已续订。

当前的PHP版本是 PHP版本5.6.29

由于代码以前工作,所以我找不到为什么它现在不起作用。作为初学者,我不知道服务器中的.pem文件吗?

我们是否需要对该.pem文件进行一些修改?

尝试这个,

<?php 
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'TxxxProd.pem'); //TxxxDev.pem
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
stream_set_blocking ($fp, 0); 

$tHost = 'gateway.sandbox.push.apple.com';
$tPort = 2195;
$tToken = '*****************';
$tAlert = 'Hi this is a test message from vineeth';
$tBadge = 8;
$tSound = 'default';
$tPayload = 'APNS Message Handled by LiveCode';
$tBody['aps'] = array (
'alert' => $tAlert,
'badge' => $tBadge,
'sound' => $tSound,
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
if (!$tSocket)
exit ("APNS Connection Failed: $error $errstr" . PHP_EOL);
$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);
?>

最新更新