我跟隨光芒Wenderlich的IOS通知教程: http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1解析錯誤
所有進展順利,並且建立我可以連接到APNS和原來測試我的證書被認可一切順利。儘管我已經將所需的詳細信息和ck.pem添加到文件夾,但我嘗試運行他提供的php腳本時出錯。 完整的錯誤是: 解析錯誤:在/Users/carsoncarbery/Desktop/SimplePush/simplepush.php解析錯誤在第10行
這裏是我的PHP腳本代碼:
<?php
// Put your device token here (without spaces):
$deviceToken = '521fbe4fbee30cb68ec7303a12a9d1ea56d89e6c18557479311f9417a2208415';
// Put your private key's passphrase here:
$passphrase = 'pushchat!’;
// Put your alert message here:
$message = 'My first push woo hoo :-)’;
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://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'
);
// 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);
我應該補充一點,我是新來的(因此試圖從教程中學習)並且不理解PHP,但我已經檢查過這個在線的解決方案,但沒有找到任何可以幫助的參考。 非常感謝您的任何幫助
確保ck.pem,委託和簡單推送在同一個文件夾中。 –
嗨,感謝您的回覆。我回去重新創建了ck.pem,然後再次確認它位於同一個文件夾中,但仍然出現錯誤。有一件事,雖然什麼是「委託」,我沒有在我的文件夾中有這個名字的文件nore是在教程中提到的? – Kitcc
你還沒有關閉最後的php標籤?>在你的php腳本 –