Reputation: 11
For APNS, I had tried with my certificate and web script (.php file) and its working everything fine. Now I am trying the same thing with client provided certificate, he has sent me his .p12 file, I have done all correct stpes and generated .pem file for server but its not working. I didn't get why its happening?? Any one has an idea about it? Here is my server file which I am using to send notifications.
<?PHP
if($_POST['message'])
{
$deviceToken = '<my device token id>';
$message = stripslashes($_POST['message']);
$payload = '{
"aps" :
{ "alert" : "'.$message.'",
"badge" : 3,
"sound" : "bingbong.aiff"
}
}';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', '<my passPharse>');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if(!$fp){
print "Failed to connect $err $errstrn";
return;
} else {
print "Notifications sent!";
}
$devArray = array();
$devArray[] = $deviceToken;
foreach($devArray as $deviceToken){
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack ("n",strlen($payload)) . $payload;
//print "sending message :" . $payload . "n";
fwrite($fp, $msg);
}
fclose($fp);
}
?>
<form action="send-notification.php" method="post">
<input type="text" name="message" maxlength="100">
<input type="submit" value="Send Notification">
</form>
This file working well with my .pem file but giving error "Failed to connect 0" with my client's file. I can't able to find the reason for it.
If any one having idea of it then please guide/show me path to solve the problem, Please.
Thank you in advance.
Upvotes: 0
Views: 624
Reputation: 11
Its was a bug with .pem file. If you not providing the correct password while creating the .pem file from .p12 then the file will be created but it will not work. I checked that process with remote login and caught the issue.
Thank you all for your help and support :)
Upvotes: 1
Reputation: 371
i think thats issue of p12 files if its not making properly then this error will came and to make sure it again just use follow code to generate pem file then also if not working then its wrong p12 file
openssl pkcs12 -in server_certificates_bundle_sandbox.p12 -out server_certificates_bundle_sandbox.pem -nodes -clcerts
Upvotes: 0