我收到了来自 Apple 支持的以下电子邮件。以下是其中的摘录:
……
根据您报告说您的推送通知已停止工作而您没有进行任何更改,我们怀疑这可能是由于继续使用已于 2021 年 3 月 31 日停用的旧版二进制接口 (https://developer.apple.com/news/?id=c88acm2b)。
此更改要求您迁移推送服务器以使用 HTTP/2 API。任何仍在使用旧接口的推送服务器都将无法连接到 APN,从而导致推送通知不起作用。
有关 HTTP/2 提供程序 API 的更多信息可以在这两个 WWDC 会议中找到:
您可以在此处阅读有关新 APNs 提供程序 API 的更多信息:
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/
........
所以我现在更改了我的 PHP 文件并且它可以工作了:
function sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token) {
//////////////////////////////////////////////
// @param $http2ch the curl connection
// @param $http2_server the Apple server url
// @param $apple_cert the path to the certificate
// @param $app_bundle_id the app bundle id
// @param $message the payload to send (JSON)
// @param $token the token of the device
// @return mixed the status code
///////////////////////////////////////////////
// url (endpoint)
$url = "{$http2_server}/3/device/{$token}";
// certificate
$cert = realpath($apple_cert);
// headers
$headers = array(
"apns-topic: {$app_bundle_id}",
"User-Agent: My Sender"
);
// other curl options
curl_setopt_array($http2ch, array(
CURLOPT_URL => $url,
CURLOPT_PORT => 443,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $message,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSLCERT => $cert,
CURLOPT_HEADER => 1
));
// go...
$result = curl_exec($http2ch);
if ($result === FALSE) {
throw new Exception("Curl failed: " . curl_error($http2ch));
}
// get response
$status = curl_getinfo($http2ch, CURLINFO_HTTP_CODE);
return $status;
}
所以你可以这样称呼它:
include_once './sendHTTP2Push.php';
error_reporting(E_ALL);
// open connection
$http2ch = curl_init();
curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
// send push
$apple_cert = 'pem4.pem';
$message = '{"aps":{"alert":"Hi!","sound":"default"}}';
$token = 'c4942de20b30792b8f1e04c2f5488e05a24bf72f14f1fc849e6581faf9571111';
$http2_server = 'https://api.development.push.apple.com'; // or 'api.push.apple.com' if production
$app_bundle_id = 'com.gl.xxxxxxxx';
$status = sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token);
echo "Response from apple -> {$status}\n";
// close connection
curl_close($http2ch);
效果很好。
创建密钥文件 pem4.pem
Create a push certificate on the Apple site under Certificates and download it ---> aps-XX.cer
Call up keychain management
Insert the downloaded file
Apple Push Service: Export Com.gl.xxxxxxxx ---> xxx.p12
Call the terminal program
cd desktop
openssl pkcs12 -clcerts -nodes -out pem4.pem -in xxx.p12
Copy pem4.pem to the server
this is now @param $ apple_cert (see below)