简体   繁体   中英

Apple Push Notification Feedback Service with PHP - Socket Errors

I followed this question for consuming APNS Feedback Service. Here is my code for requesting feedback servers;

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;
}

When I use this function, it reports following errors;

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

I am using my production certificate (.pem) which I use for sending push notification messages, and it's valid + working. So an invalid certificate is not the issue here. What am I doing wrong here?

After much annoyance I finally figured out what this issue was for me. Our cert was perfectly fine for sending messages, but I had to create a cert without encryption or passphrase for it to work with feedback

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

Was the step we did not use on our pem for the pushes being sent. After using it the feedback seems to be OK, but it is only returning 3 tokens although I feel we should have more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM