php - 未定义常量 http/2
问题描述
我正在尝试研究如何从 php 站点向苹果 iOS 设备发送推送通知。我有一个在新的 http/2 方式之前工作的 php 脚本,但由于他们不再支持它,它当然不起作用。
我的新脚本是这样的:
<?php
$ch = curl_init();
$device_token = 'correctDevice';
$pem_file = 'correctPemfile';
$pem_secret = 'correctCode';
$apns_topic = 'correctAppID';
//curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic"));
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
curl_setopt($ch, CURLOPT_VERBOSE , true);
echo "Try 1 ================================================" . PHP_EOL;
//setup and send first push message
$url = "https://api.development.push.apple.com/3/device/$device_token";
curl_setopt($ch, CURLOPT_URL, "{$url}");
$sample_alert = '{"aps":{"alert":"hi #1","sound":"default"}}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch);
//var_dump($response);
//var_dump($httpcode);
echo "Try 2 ================================================" . PHP_EOL;
//setup and send second push message
$url = "https://api.development.push.apple.com/3/device/$device_token";
curl_setopt($ch, CURLOPT_URL, "{$url}");
$sample_alert = '{"aps":{"alert":"hi #2","sound":"default"}}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch);
//var_dump($response);
//var_dump($httpcode);
curl_close($ch);
?>
当然,我已经屏蔽了设备令牌、pem 文件、秘密和应用程序 ID,但它们都是正确的。
问题是我收到此错误:
Warning: Use of undefined constant CURL_HTTP_VERSION_2_0 - assumed 'CURL_HTTP_VERSION_2_0' (this will throw an Error in a future version of PHP)
解决方案
推荐阅读
- puppeteer - 禁用 Chrome “恢复页面?Chrome 未正确关闭”和其他浏览器消息
- postgresql - TypeORM PostgreSQL 无法连接
- python - ModuleNotFoundError:没有名为“src.testproject”的模块
- c# - 将图片框的图像从用户控件更改为带有图像链接的表单
- c# - JsonConvert 反序列化 Avro 文件得到“解析值时遇到意外字符:O. Path '', line 0, position 0。” 错误
- jestjs - 使用 NEXT/IMAGE 开玩笑时出错:`next/image` 上的 src 属性无效,主机名“res.cloudinary.com”未在`next.config.js` 中的图像下配置
- mysql - 存储过程返回空值
- amazon-web-services - zencoder 存储桶策略不适用于域级隐私存储桶策略
- r - 基于两个变量合并两个数据框
- javascript - 我如何在 traget 数据属性上应用会话存储