我才知道 iOS 13 更改了推送通知设备令牌和有效负载。我已经更新了 App 并发布了它。现在,我们在 PHP 中有服务器,我们向用户发送警报和静默通知。我已经浏览了“ https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns ” Apple 文档,但我仍然无法理解如何在有效负载中传递新标头。
这是我的 PHP 脚本。
<?php
// Put your device token here (without spaces):
$deviceToken = 'deviceToken';
// Put your private key's passphrase here:
$passphrase = 'dummyPassword';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.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;
$body['aps'] = array(
'content-available' => '1',
'type' => 'message',
'msg' => 'We detected a failure when sending a message.'
);
// Encode the payload as JSON
$payload = json_encode($body);
echo "\njson::::\n";
print_r ($payload);
// 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 脚本,以便我可以为 Apple 推送通知创建有效负载。任何帮助将不胜感激。