APNを使用して自分のiPhoneに通知をプッシュしようとするときにトラブルシューティングがあります。私は、私は、問題はそれについてだとは思わない私は、インターネット上で何度も見ておくPHPのコードを使用します。Appleプッシュ通知サービスに接続するときの禁止アクセス
<?php
// Put your device token here (without spaces):
$deviceToken = 'mytoken'; // Of course this is my correct token here
// Put your private key's passphrase here:
$passphrase = 'mypassphrase'; // Same here
$message = $argv[1];
$url = $argv[2];
if (!$message || !$url)
exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://raywenderlich.com\'' . "\n");
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', __DIR__.'/cert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'link_url' => $url,
);
// 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;
stream_set_blocking($fp, 0);
// 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);
接続が成功してきたので、私は、「メッセージが正常に配信され、」出力を持っています確立され、送信されたメッセージのidem。ただし、デバイスは何も受信しません。
(配列は文字通り空である)私が間違っているかを知るしようとするフィードバック機能を使用しますが、結果は空です:
<?php
function send_feedback_request() {
//connect to the APNS feedback servers
//make sure you're using the right dev/production server & cert combo!
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', __DIR__.'/cert3.pem');
stream_context_set_option($stream_context, 'ssl', 'passphrase', 'meteor0405');
$apns = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context);
if(!$apns) {
echo "ERROR $errcode: $errstr\n";
return;
}
$feedback_tokens = array();
//and read the data on the connection:
while(!feof($apns)) {
$data = fread($apns, 38);
if(strlen($data)) {
$feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
}
}
fclose($apns);
return $feedback_tokens;
}
var_dump(send_feedback_request());
あなたは私が何を把握するために何ができるか上の任意のアイデアを持っているだろう違う?証明書に起因することはありますか? .cerファイルはアップルのWebサイトから生成され、キーチェーンアクセスにインポートされて.p12ファイルになりました。その後、opensslコマンドを使って.pem形式に変換しました。これは、以下のファイルで使用しています。
ありがとうございました!
実際にお手伝いしました、ありがとうございます!問題は実際にPEMファイルから来ていました。私は同じ問題を抱えている人のために問題の答えを投稿しました。 –
あなたへの誇り.. :) – Aparna