File "push_notification.php"
Full Path: /home/analogde/www/filechange/WEBSITE/douche/push_notification.php
File size: 5.04 KB
MIME-type: text/x-php
Charset: utf-8
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$serverAPIKey ="AAAA-53wG4I:APA91bGyXIRJl0X-AoWeU57KseVze8aiB1rooMerHZmd83vmwX7Q7kFh9-Ugq2S3h_1X_gubzQZjb28YUzgFLRqeQmkJ7_9gukwUnla6_vugNBrp-PHOtx3fHNKrGgUIJ3GFBwBY9EVt7P5rbt5ZS0RJI9qJfpLBHA";
$reg_token = "cUhdLggoAxw:APA91bFn01YDsQMX0RiBFldG6QglBmQc4cZqMctew7AdWMSAMRYEG02JjD_rOAA5j_nZ_2EmWlraI2uhcUKBghNt2PGDGQyxTl41HfnuaorNqqPjd2iZQqH3WeETDl0AA6kLHMPgiVHt4ev8Hw7mnECATeVX0POaXQ";
$reg_token ="d7qymBF9f8c:APA91bGhcUXInAjwaGeoorXFD8qr87a_1TWuMg09bqXFWKwz2zMyq5nwGfT9T79IF6LwdTyW3p2F2Bzm-K0QMTznovj2z0dyEyTWc3vOGf9oL38HAPgm_BVjf5gbZpagP4r_xsqCGjRXkavs3jQY_MhONCIrxZnMXw";
$title= $_POST['title'];
$message= $_POST['message'];
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key='. $serverAPIKey,
'Content-Type: application/json'
);
//Initializing curl to open a connection
$ch = curl_init();
//Setting the curl url
curl_setopt($ch, CURLOPT_URL, $url);
//setting the method as post
curl_setopt($ch, CURLOPT_POST, true);
//adding headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//disabling ssl support
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$gcmRegIds = array($reg_token);
// $gcmRegIds = array($reg_token);
// print_r($gcmRegIds);exit;
// $messagearray = array("message" => $message , "title" => $title , "image" => $image);
$messagearray = array();
$messagearray['data']['title'] = $title;
$messagearray['data']['message'] = $message;
//adding the fields in json format
$fields = array(
'registration_ids' => $gcmRegIds,
'data' => $messagearray,
);
/// autre test
$title = "pipotron";
$notification = "cretin";
$msg =
[
'message' => $notification,
'title' => $title
];
$fields_test =
[
'registration_ids' => $reg_token,
'data' => $msg
];
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
echo json_encode($fields);
//finally executing the curl request
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
//header("Location: https://www.demonuts.com/Demonuts/JsonTest/Tennis/sendMultipleFCM.php");
// exit();
//Now close the connection
curl_close($ch);
//and return the result
return $result;
} else{
//echo json_encode(array( "status" => "false","message" => "Error occured, please try again!") );
}
?>
<html>
<head>
<title>DemoNuts Firebase Cloud Messaging (FCM) Server in PHP</title>
<style type="text/css">
#submit {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
#navigation
{
position: absolute; /*or fixed*/
right: 0px;
margin-right: 270px;
}
.large
{
font-size: 14pt;
height: 40px;
}
</style>
</head>
<body>
<div id="navigation" style=" height: 600px ; width : 300px ;">
</div>
<h1>Firebase Cloud Messaging (FCM) Server in PHP</h1>
<form method="post" action="push_notification.php">
<h3>FIREBASE SERVER KEY</h3>
<div>
<input type="text" class="large" name="serverapi" size="55" placeholder="Enter Your Server KEY"></textarea>
</div>
<h3>DEVICE TOKEN OR REG.ID</h3>
<div>
<input class="large" name="token" size="55" placeholder="Enter Device Token or Reg.ID"></textarea>
</div>
<h3>DEVICE TOKEN OR REG.ID-2</h3>
<div>
<input class="large" name="token2" size="55" placeholder="Enter Device Token or Reg.ID-2"></textarea>
</div>
<h3>Message</h3>
<div>
<textarea rows="6" name="message" cols="63" placeholder="Message to transmit via FCM"></textarea>
</div>
<h3>Title</h3>
<div>
<input class="large" name="title" size="55" placeholder="Title to transmit via FCM"></textarea>
</div>
<h3> Include Image? </h3>
<input type="radio" name="isImage" id="no" value="Yes" checked/>Yes
<input type="radio" name="isImage" id="no" value="No">No<br>
<input type="submit" name="submit" value="Go Go Go...!" id="submit" /><br>
</form>
<p><h3><?php echo $pushStatus; ?></h3></p>
</body>
</html>