我使用了著名的 Ray Wanderlich tutorial 的 php 脚本在开发阶段发送推送通知。在我创建 pem 文件(来自 p12 和 aps_development.cer 文件)并在 php 脚本中提及设备 token 后,它们被正确触发。
但是,当我使用包含生产 p12 和 aps_production.cer 文件的 pem 文件时,通知甚至没有到达 APNS 服务器。它在本地服务器端本身显示以下错误。
Unable to set private key file `/Users/administrator/Desktop/SimplePush/ck.pem' in /Users/administrator/Desktop/SimplePush/simplepush.php on line 22
Warning: stream_socket_client(): failed to create an SSL handle in /Users/administrator/Desktop/SimplePush/simplepush.php on line 22
Warning: stream_socket_client(): Failed to enable crypto in /Users/administrator/Desktop/SimplePush/simplepush.php on line 22
Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) in /Users/administrator/Desktop/SimplePush/simplepush.php on line 22
这可能是什么原因。 p12 文件没有任何密码(虽然我已经为 pem 文件配置了密码),这是在 php 脚本中给出的密码。
// Put your private key's passphrase here:
$passphrase = '';
最佳答案
这不是正确的 p12 文件。我从 Keychain 导出了正确的 p12 文件,一切顺利。
经验教训 -
如果您使用的 p12 和 cer 文件彼此不对应,显然在串联 pem 文件创建过程中不会显示任何错误。但是当你执行脚本时,会出现错误。
上述错误消息并不一定意味着 p12 文件的密码不正确。它们也可能意味着 p12 文件与使用的 cer 文件不对应。
关于php - 通过 php 脚本 : 'Unable to set private key file' 发送 iOS 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21013848/