2

モバイル デバイス管理システムに取り組んでいますが、プッシュ通知が機能しません。私のコードは

//$apnsHost = 'gateway.push.apple.com';
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'PushCert.pem';

// Put your device token here (without spaces):
$deviceToken = 'my-device-token'; //I have replaced my actual token here

// Put your private key's passphrase here:
$passphrase = 'pushchat';

// Put your alert message here:
$message = 'My first push notification!';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
//stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp)
    exit("Failed to connect: $error $errorString" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default'
    );

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered' . PHP_EOL;

// Close the connection to the server
fclose($fp);

「APNSに接続しましたメッセージが正常に配信されました」のようなメッセージが表示されました。しかし、iPhoneデバイスには通知が来ませんでした。他に何を確認する必要があり、解決策は何ですか? Iphone のログも構成ユーティリティで確認しましたが、スクリプトを実行してもログが表示されません。

4

0 に答える 0