[英]Apple push notification not working in php
我的 php 脚本总是为苹果推送通知提供错误代码 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);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.