PHP推送通知反馈服务 - 套接字错误

时间:2013-04-08 13:52:45

标签: php ios push-notification apple-push-notifications

我关注了消费APNS反馈服务的this问题。这是我的请求反馈服务器的代码;

function send_feedback_request() {
    //connect to the APNS feedback servers
    //make sure you're using the right dev/production server & cert combo!
    $stream_context = stream_context_create();
    stream_context_set_option($stream_context, 'ssl', 'local_cert', 'my_production_cerficate.pem');
    $apns = stream_socket_client('ssl://feedback.push.apple.com:2196', $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context);
    if(!$apns) {
        die("ERROR $errcode: $errstr\n");
    }


    $feedback_tokens = array();
    //and read the data on the connection:
    while(!feof($apns)) {
        $data = fread($apns, 38);
        if(strlen($data)) {
            $feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
        }
    }
    fclose($apns);
    return $feedback_tokens;
}

当我使用此功能时,它会报告以下错误;

Warning: stream_socket_client() [function.stream-socket-client]: Unable to set private key file /my_directories/my_production_cerficate.pem in /my_directories/apnsfeedback.php on line 7

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /my_directories/apnsfeedback.php on line 7

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /my_directories/apnsfeedback.php on line 7

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://feedback.push.apple.com:2196 (Unknown error) in /my_directories/apnsfeedback.php on line 7

我正在使用我用于发送推送通知消息的生产证书(.pem),它有效+正常工作。因此,无效证书不是问题。我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

在烦恼之后,我终于弄明白这个问题对我来说是什么。我们的证书非常适合发送邮件,但我必须创建一个没有加密或密码的证书才能使用反馈

openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

我们没有在我们的pem上用于发送推送的步骤。使用它之后,反馈似乎没问题,但它只返回3个令牌,虽然我觉得我们应该有更多。