curl - Apple 推送通知 - “无法加载客户端密钥:-8178”
问题描述
我目前正在尝试使用连接到 CentOS 生产服务器上的苹果推送通知服务的 PHP cURL 发送推送通知。我能够在具有相同库的单独开发服务器上成功发送通知(它是生产服务器的克隆),但是当我从https://api.sandbox.push.apple.com/3/切换目标 URL 时设备到https://api.push.apple.com/3/device/,我收到此 cUrl 错误:无法加载客户端密钥:-8178 (SEC_ERROR_BAD_KEY)。
我的服务器设置在两台服务器之间是相同的,这是我的 curl 和 openssl 信息:
curl --version
curl 7.61.0 (x86_64-redhat-linux-gnu) libcurl/7.61.0 NSS/3.36 zlib/1.2.7 libpsl/0.7.0 (+libicu/50.1.2) libssh2/1.8.0 nghttp2/1.33.0
Release-Date: 2018-07-11
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy PSL Metalink
和openssl:
openssl version
OpenSSL 1.0.2k-fips
据我所知,这些是使用 HTTP2 和访问 APN 的可接受设置。这是我用于发送通知的 php 代码:
// these are loaded from a config file. I know these are correct because it works on the development server
private static $passphrase = CERTIFICATE_PASSWORD; //password for pem file
private static $certificate_file = CERTIFICATE_FILE; // pem file
private static $apns_topic = APNS_TOPIC; // app bundle id
private static $ios_url = IOS_URL; // "https://api.push.apple.com/3/device/"
...
public static function sendNotification($data, $devicetoken){
$wsTitle = $data['mtitle'];
$wsBody = $data['mdesc'];
$body['aps'] = array(
'alert' => array(
'title' => $wsTitle,
'body' => $wsBody,
),
'sound' => 'default'
);
$payload = json_encode($body);
$apns_topic = self::$apns_topic;
$url = self::$ios_url . $devicetoken;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTP_VERSION,3);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["apns-topic: $apns_topic"]);
curl_setopt($ch, CURLOPT_SSLCERT, self::$certificate_file); //pem file
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, self::$passphrase); //pem secret
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo curl_error($ch);
}
上述脚本的输出是之前讨论过的这个错误:无法加载客户端密钥:-8178 (SEC_ERROR_BAD_KEY)。$response 为空,$httpcode 为 0,这意味着据我所知,这根本没有连接到 Apple。
似乎尝试向 Apple 的生产 URL 发送推送通知有我不知道的额外安全要求。同样,这个脚本可以在相同的服务器上完美运行,只需使用沙盒苹果 url。
有人对我在这里可能缺少的东西有任何想法吗?任何帮助表示赞赏。
解决方案
推荐阅读
- bash - 删除所有少于 X 个文件的子文件夹
- haskell - 为什么“++”函数比“:”贵很多?
- data-visualization - 可视化数据,跟踪特定 SD 值
- javascript - 组件不再渲染 React JS
- android - 尝试将文件夹内容转换为 zip 文件时出现 IndexOutOfBounds 异常
- amazon-web-services - 如何获取 AWS JavaScript SDK 调用的响应标头?
- python - PYQT5 物理计算器
- javascript - Javascript Regex 在开始和结束时限制下划线
- sql - 空记录集的Excel VBA SQL SUM不返回零
- php - 获取多维 PHP 数组大小的最便宜方法