0

can you determine what is the problem is my code. I am trying to send notification via parse from PHP code on my localhost but did not show result at all in my parse dashboard. Thank you in advance.

my php version : 5.5.28

 <?php
 require "connect.php";
 require "parsePHP/autoload.php";

$app_id = "xxxxxxxxxxxxxxxxxxxxxxxxx";
$rest_key = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$master_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$MESSAGE = "HI.. Testing";

use Parse\ParseClient;
use Parse\ParsePush;
ParseClient::initialize( $app_id, $rest_key, $master_key );

$url = 'https://api.parse.com/1/push';
$data = array(
    'channel' => 'Android',
    'type' => 'android',
    'data' => array(
        'alert' => $MESSAGE,
    ),
);
$_data = json_encode($data);
$headers = array(
    'X-Parse-Application-Id: ' . $app_id,
    'X-Parse-REST-API-Key: ' . $rest_key,
    'Content-Type: application/json',
    'Content-Length: ' . strlen($_data),
);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_exec($curl);
?>
Shehary
  • 9,548
  • 9
  • 33
  • 66
  • Are you getting an error? Maybe try [displaying PHP errors](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) or checking for any [curl errors](http://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php) – John C Dec 21 '15 at 04:21
  • i have added curl errors and it shows (error:SSL certificate problem: unable to get local issuer certificate) @JohnC do you know how to fix it? Tqvm – user3089772 Dec 21 '15 at 09:07
  • That's a fairly common one - this is an issue with the Certificate Authority (CA) that your server uses to check SSL certificates. [This answer](http://stackoverflow.com/a/32095378/628267) should help solve the issue. – John C Dec 21 '15 at 09:43
  • I've just noticed the Parse PHP SDK you are using should have a fix for this - is there a reason you start with that, but then use curl? – John C Dec 21 '15 at 09:44
  • @JohnC actually i dont know how to use Parse PHP SDK then googling and paste it. first i use curl only but does not work then i use sdk only and it also not work.. if we use Parse PHP SDK, is the curl does not have to be used? – user3089772 Dec 22 '15 at 03:55
  • It looks like the certificates were never actually added to the SDK, so that wouldn't help you. [This quesion](http://stackoverflow.com/q/25516518/628267) has someone with the same issue if the link earlier didn't help. – John C Dec 22 '15 at 04:36
  • tq @JohnC , I already post the answer.. thank a lot. – user3089772 Dec 23 '15 at 02:42
  • @JohnC if we want to use the code in server, does we need to paste the SSL certificate on the server? tq – user3089772 Dec 29 '15 at 01:46
  • It depends how up to date your server is - most of the time it should be fine. If not you'll need to copy the certificate across or ask your host to update the server's certificates. – John C Dec 29 '15 at 11:20

1 Answers1

0

Thank you @JohnC for great solution in his comment

this my code

<?php
require "connect.php";
require "parsePHP/autoload.php";

$app_id = "xxxxxxxxxxxxxxxx";
$rest_key = "xxxxxxxxxxxxxxxx";

$url = 'https://api.parse.com/1/push';
$data = array(
    'channel' => 'AndroidHive',
    'type' => 'android',
    'expiry' => 1451606400,
    'data' => array(
        'alert' => 'greetings programs',
    ),
);
$_data = json_encode($data);
$headers = array(
    'X-Parse-Application-Id: ' . $app_id,
    'X-Parse-REST-API-Key: ' . $rest_key,
    'Content-Type: application/json',
    'Content-Length: ' . strlen($_data),
);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_exec($curl);

if(curl_errno($curl))
    {
echo 'error:' . curl_error($curl);
    }   ?>

and as mention in his comment, about the SSl certification, u can read this answer (https://stackoverflow.com/a/32095378/628267)

Community
  • 1
  • 1