0

Apple プッシュ通知のエラー コード 0 を常に与える私の php スクリプト。私が使用したコードは以下のとおりです

$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 に答える