0

我的 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文件进行一些修改吗?

4

1 回答 1

1

尝试这个,

<?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);

?>
于 2016-12-21T11:41:20.937 回答