您好我已经在linux上安装了php-apn软件包,用于向IOS发送推送通知,我得到的错误是:
“无法使用指定的私钥”
我最初也尝试使用stream_socket_client并得到了类似的错误。密钥/证书的路径是正确的,我已使用相同的结果再次重新生成密钥/证书
代码在
之下 // APNS contex
$apn = apn_init();
apn_set_array($apn, array(
'certificate' => '/var/www/html/scripts/certs/PushChatCert.pem',
'private_key' => '/var/www/html/scripts/certs/apns_cert.pem',
// 'private_key_pass' => '',
'mode' => APN_PRODUCTION
));
//APN_SANDBOX
// Notification Payload context
$payload = apn_payload_init();
apn_payload_set_array($payload, array(
'body' => 'push ',
'sound' => 'default',
'badge' => 1,
'tokens' => array ('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
)
));
apn_payload_add_custom_property($payload, 'test', 56);
$error = NULL;
$errcode = 0;
// Opening Apple Push Notification Service connection...
if(apn_connect($apn, $error, $errcode)) {
// and if ok, try send push notification....
if(!apn_send($apn, $payload, $error, $errcode)) {
echo 'Could not sent push notification: ' . $error;
}
} else {
echo 'Could not connected to Apple Push Notification Service: ' . $error;
}
apn_close($apn);
apn_payload_free($payload);
apn_free($apn);