Sending iOS notification through a php script: 'Unable to set private key file'

后端 未结 7 1596
囚心锁ツ
囚心锁ツ 2021-01-06 00:49

I have used the php script from the well known Ray Wanderlich tutorial to send push notifications during development phase. They were triggered properly after I created the

相关标签:
7条回答
  • 2021-01-06 00:57

    It was not the correct p12 file. I exported the correct p12 file from Keychain and it went well.

    Lessons learnt -

    1. If the p12 and cer files you are using do not correspond to each other, obviously there wouldn't be any error shown during the concatenated pem file creation. But when you execute the script, there will be an error shown.

    2. The above error messages do not necessarily imply that the p12 file's passphrase is incorrect. They may also mean that the p12 file does not correspond to the used cer file.

    0 讨论(0)
  • 2021-01-06 00:58

    if you running the file from the command line maybe try to give the full path to the ck.pem file

    change the line : stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');

    to

    stream_context_set_option($ctx, 'ssl', 'local_cert', '/path/to/your/file/ck.pem');

    work for me

    0 讨论(0)
  • 2021-01-06 00:58

    Setting $passphrase = '1234' to $passphrase = "1234" fixed the issue for me.

    0 讨论(0)
  • 2021-01-06 01:01

    If the file ck.pem does exist in that location it may be that the php script does not have access to it. I would change the permissions of the folder/files to something more lenient or try running the script as the superuser:

    sudo php simplepush.php
    

    Edit 1:

    After some research it looks like the pem file could be in an unexpected format. You could try changing the order of the certificates that were combined in the file. You can also try using separate files and specifying each file using the 'stream_context_set_option' functions.

    Edit 2:

    If you can, try to set up the passwords for your production files the same way as the tutorial. It's possible the passphrase is required for it to work. Again, sounds like something is wrong with the pem file, either generated incorrectly, missing, or in the wrong format. Check the file. Maybe even post it up in your question if it is not a security risk. You can probably just regenerate a new key after figuring out what is wrong.

    0 讨论(0)
  • 2021-01-06 01:08

    I have encountered the same problem, I am using 1234 as passphrase. Instead of writing $passphrase = '1234'; I have written as $passphrase = 1234; and it is working fine

    0 讨论(0)
  • 2021-01-06 01:16

    I got the same error.

    I'm sure my pem file is right, i follow this guide: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ProvisioningDevelopment.html

    debug a lot and i figured out i forget the passphrase.

    PS: I used this php script: https://github.com/duccio/ApnsPHP, maybe it helps you.

    0 讨论(0)
提交回复
热议问题