繁体   English   中英

Apple 推送通知在 php 中不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM