dongxi4235 2015-06-18 17:13
浏览 174

无法使用php-apn向IOS发送推送通知

Hi I have installed the package php-apn on linux for sending push notifications to IOS and the error I get is:

"unable to use specified private key"

I also initially tried it using stream_socket_client and got a similar error. The path to the key/cert are correct, I have regenerated the keys/certs again with the same outcome

The code is below

        // 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);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog