【发布时间】:2021-02-08 03:16:19
【问题描述】:
我正在编写代码以使用 PHP Laravel 向 Apple 推送通知服务器 (APN) 发送通知。它在文档中说它需要 HTTP/HPACK 标头压缩。
我尝试过使用 cURL
$cURLConnection = curl_init();
if(strcmp(env('APP_ENV'), 'production') == 0) {
curl_setopt($cURLConnection, CURLOPT_URL, 'api.push.apple.com:443');
} else {
curl_setopt($cURLConnection, CURLOPT_URL, 'api.development.push.apple.com:443');
}
curl_setopt_array($cURLConnection, [
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_HTTP_VERSION =>CURL_HTTP_VERSION_2_0,
]);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
'path: /3/device/<devicetoken>',
'authorization: bearer ' . $token,
'Content-Type: application/json'
));
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt ($cURLConnection, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
$apiResponse = curl_exec($cURLConnection);
但 APNS 服务器总是返回“来自服务器的空回复”
【问题讨论】:
-
已解决 - HTTP/2 PHP - Laravel Helper Class 为我使用 cURL github.com/webblufter/…
标签: php laravel http-headers php-curl