Withdraw FCM notification PHP - php

After sending a FCM notification using PHP a multicast id has been received.
is there any way withdrawing the sent notification using this multicast id?
For instance:
When whatsapp web is open on my pc, the whatsapp notification will be gone from my home screen on my phone after reading it on my pc.
$url = 'https://fcm.googleapis.com/fcm/send';
$notification= array(
'body' => $message,
'priority' => 10,
'sound' => "default"
);
$fields = array(
'to' => $targets,
'notification' => $notification,
'sound' => "default",
'priority' => 10
);
$headers = array (
'Authorization: key='.$gcmKey,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_exec($ch);
curl_close($ch);
This is how i 'send' the notification.
My app is being build using phonegap

Related

Receive Push Notification Twice firebase PHP Script

I'm new to Firebase Send Push Notification. I'm working on Send Push notification To multiple Users Using PHP Script.
PHP SCRIPT
function sendPushNotification($fb_key_array, $title) {
$finalPostArray = array('registration_ids' => $fb_key_array,
'notification' => array(
'title' => $title,
'sound' => 'default',
'badge' => '1'
),
'priority' => 'high',
);
$server_key = env("SERVER_KEY");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($finalPostArray)); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: key=' . $server_key));
$server_output = curl_exec($ch);
print_r($server_output);
return $server_output;
curl_close($ch);
}
I'm send notification using Queue Jobs on Particular Time.
I have a problem when I send Three notification at same time than Notification receive Twice.
Response From This Curl
App\Jobs\PushNotification
<pre>{"multicast_id":4668247729883149905,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1616386021446151%e609af1cf9fd7ecd"}]}[2021-03-22 04:07:01][261] Processed: App\Jobs\PushNotification
[2021-03-22 04:07:01][262] Processing: App\Jobs\PushNotification
<pre>{"multicast_id":4539206321688711164,"success":2,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1616386022124068%e609af1cf9fd7ecd"},{"message_id":"0:1616386022123922%e609af1cf9fd7ecd"}]}[2021-03-22 04:07:01][262] Processed: App\Jobs\PushNotification
[2021-03-22 04:07:02][263] Processing: App\Jobs\PushNotification
<pre>{"multicast_id":1591082090876608595,"success":3,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1616386023195991%e609af1cf9fd7ecd"},{"message_id":"0:1616386023196003%e609af1cf9fd7ecd"},{"message_id":"0:1616386023195724%e609af1cf9fd7ecd"}]}[2021-03-22 04:07:02][263] Processed: App\Jobs\PushNotification
And Receive 6 Notification .but I send Only Three Notification. Where is my Fault ?
Help Thank You
I am not so sure about that there is nothing wrong with your func but you can try this it's the same but little different if not work so that mean you have a loop somewhere in your code ..
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array (
'registration_ids' => $target,
// fix new json format
'notification' => array(
'body' => 'this is firebase test mesging',
'title' => 'hello from firebase',
'badge' => 1,
'sound' => 'default',
'priority' => 'high',
)
);
$fields = json_encode($fields);
$server_key = 'ur_server_kay';
// inherited key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
var_dump($result);
if ($result === FALSE) {
die('Oops! FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);

Json received = false

I am using ci framework, and i try to create notification using
onesignal API. I have hosted the website using https. But why my JSON
received is always false using onesignal API, but if i test using
postman it runs fine without error.
This is my code
function send_message($id, $nama) {
$content = array(
"en" => $nama
);
$heading =array(
"en" => $id
);
$fields = array(
'app_id' => "2cd5ad24-a2d9-4e7d-ac66-7494cebd8e84",
'included_segments' => array(
'Active Users'
),
'contents' => $content,
'headings' => $heading,
'url' => "https://esop.matahariled.com"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic MDQ0NjY0ZmYtZjQ2Yi00ODVmLTkzZjgtZmVkZDBkODk0MDFl'
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CAINFO, $_SERVER['DOCUMENT_ROOT']."/cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}

Firebase notification gives me "Success" but I don't get the notification on IOS

I get notifications on Android but when I send the notification to an IOS device, it doesn't get received, even though it says success.
I added badges, sound, vibration, priority.. etc but none of this solved the problem.
function sendNotification($title, $body, $aid,$destination)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$message = array(
'title' => $title,
'body' => strip_tags($body),
'vibrate' => 1,
'sound' => 1,
"action" => "url",
'sound' => 'default',
'badge' => '1',
'priority'=>'high',
"action_destination" => $destination,
);
$fields = array(
'registration_ids' => $aid,
'data' => $message
);
$headers = array(
'Authorization: key=KEYHERE',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
}
The mobile developer says that theres a new firebase update and I frankly think hes bsing... Can someone explain to me whats going on? I think my part here is done, but you guys might see something wrong with my code...

Error code 410 when polling Skyscanner flight live prices

I am polling live prices from the Skyscanner API. Although I receive the session_key and although I am immediately polling the results I am getting a 410 (Gone) response header with an empty body. It used to work fine from my localhost environment but not on my live server anymore.
Has anybody experienced this before and can maybe give me a hint what the issue could be?
$url_api = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/";
$api_key = "XXX"; // Not shown here
$data = array('apiKey' => $api_key, 'country' => 'DE', 'currency' => 'EUR',
'locale' => 'de-DE', 'originplace' => 'HAM', 'destinationplace' => 'AMS', 'cabinclass' => 'economy', 'outbounddate' => '2017-01-27',
'inbounddate' => '2017-01-30' , 'locationschema' => 'Iata', 'groupPricing' => true);
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$response = curl_exec($ch);
curl_close($ch);
$headers = get_headers_from_curl_response($response);
$url = $headers['Location']."?apiKey=".$api_key."&stops=0";
echo $url;
return;

Pushbullet no notification on smartphone using API

I created a little app which uses Pushbullet's API.
It is writtent in PhP and uses cURL to proceed the different requests.
At first, I use oauth2 to recieve an access token.
Then it is /v2/pushes/ to send a push to the registred account.
The message is recieved on the Pusbullet account but nothing shows up on the smartphone. There is no notification.
I hope someone can help me.
Thanks.
My function which sends the push:
function send_push($token){
$data = array(
'type' => 'note',
'title' => 'Alert',
'body' => 'My body :)!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pushbullet.com/v2/pushes');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$token
));
$data = curl_exec($ch);
curl_close($ch);
}

Categories