I tried executing the API APNS using CURL . The code is as below
$pem_file = 'public/assets/pem/test.pem';
$pem_secret = '';
$apns_topic = 'com.test.demo';
if(defined('CURL_HTTP_VERSION_2_0'))
{
$devicetoken=['54688ae0e1ecc3bc0d517521f4935c014342ecca792ef798f0e63652a4620ed4','de963dfbc03f5de416c7d806e04a6f3276716f246942fa2a61cffa393a780120','a08832de8b72567aa487beefe50e4e29caaa4a51ab14706fc8f0ef9df1f6b9c4','48335901c12bf02a03cef453d2e7739eaac9779991cafef3fa70ffe587ea3f12'];
$sample_alert = '{"aps":{"alert":"hi","sound":"default"}}';
foreach($devicetoken as $device_token)
{
$url = "https://api.development.push.apple.com/3/device/$device_token";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic"));
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//On successful response you should get true in the response and a status code of 200
var_dump($response);echo "----";var_dump($httpcode);
}
}
else{
echo"NOt a supported version";
}
Iam getting the result as :
�@@uUnexpected HTTP/1.x request: POST /3/device/54688ae0e1ecc3bc0d517521f4935c014342ecca792ef798f0e63652a4620ed4 bool(true) ----int(0)
I was trying this method to handle the invalid device token .Earlier i tried ssl using PHP like this link(http://learn-php-by-example.blogspot.in/2013/01/working-with-apple-push-notification.html) , In that when a invalid device token is in the db and when we pass it through the loop the push notification stops working . So i was trying the API method .
Thanks in advance for your response guys