APNS server responds with status 8-invalid-token, but devices are being registered properly

坚强是说给别人听的谎言 提交于 2019-12-24 08:30:26

问题


I am implementing passbook funcationality for my iOS app. I am using php as server side language to generate pass and distribute to devices. Passes are being successfully installed on the device and I am also able to update pass manually using pull to referesh. When I try to update pass automatically from server side I get the response status 8-invalid-token with message "Identifier is the rowID(index) in the database that caused the problem. Apple will disconnect you.....". I don't get why it is happening. Devices is being registered correctly and other end points are also working fine. If pass was not correct in the first place it should not get installed on the device. I signed the pass using the same pass type id certificate which I am using to send push notification. I also checked my certificates using this command listed here.

    $ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile server-ca-cert.pem  

I treid it for both sandbox and production and it doesn't show any error. I am using production url for sending push notification to update pass; Here is my code for sending push;

        $apnsHost = 'gateway.push.apple.com';  
        $apnsPort = 2195;  
        $apnsCert = base_path().'/path/to/ptypeidcert.pem';//converted using ssl from passtypeid.p12 certificated  
        $push_token = $token;  
        $passIdentify = 'pass.myidentifier.coupon';  
        $payload = '{}';  
        $msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($payload)) . $payload . pack('n', strlen($passIdentify)) . $passIdentify;  

        $streamContext = stream_context_create();  

        stream_context_set_option($streamContext, 'ssl', 'cafile', base_path().'/path/to/entrust_2048_ca.cer');  
        stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);  
        stream_context_set_option($streamContext, 'ssl', 'passphrase', 'export_password');  

        $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);  

        fwrite($apns, $msg);  
        PushNotifications::checkAppleErrorResponse($apns);// Just created a class to read response from apn server  
        @socket_close($apns);  
        fclose($apns);  

Any help to further debug would be really appriciated. Something to debug my certificates? Note: My API end points are served on http protocole just for test purpose, will update them to https protocole. I've enabled HTTP services on device to install pass on passbook.

============ UPDATE ============= Here are the steps to generate my certificates.

  1. First I downloaded my Pass Type Id certificate(.cer) using CSR request with my key.
  2. Then exported that certificated using keychain access on Mac, to a .p12 extension required for signing the coupon on creation time. That coupon is being successfully installed on device.
  3. Then I converted that .p12 to .pem used in above code for connecting push server. Using command;

    openssl pkcs12 -in path.p12 -out newfile.pem

If anything wrong with my certificate generation please point out.

来源:https://stackoverflow.com/questions/40183151/apns-server-responds-with-status-8-invalid-token-but-devices-are-being-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!