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.