我正在使用以下PHP脚本进行APNS
function send_push_ios_test($msg)
{
// Put your device token here (without spaces):
$deviceToken = '6778601ee2fd7809a90f2eaf709d5bbbbd3bec38c5b35e1428d7857f4b6ec0a7';
//$deviceToken = '6778601e e2fd7809 a90f2eaf 709d5bbb bd3bec38 c5b35e14 28d7857f 4b6ec0a7';
// Put your private key's passphrase here:
$passphrase = 'Pass@123';
// Put your alert message here:
$message = $msg;
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '../uploads/ios_pns/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
//$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
$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' => array(
'body' => $message,
'action-loc-key' => 'Bango App',
),
'badge' => 2,
'sound' => 'oven.caf',
);
// 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&然后消息传递成功,但我没有在我的设备上收到推送消息。任何人都可以帮我解决这个问题。 在我的设备上为示例应用程序以及XCODE启用了推送通知。