How to send push to specific devicetoken on php function - php

I'm Using Ionic Framework V1.
I've already get push notifications through Postman using
and I've already save all devicetokens in my DB, but i'm stuck at getting any push for specific devices in php functions.
curl -X POST -H "Authorization: Bearer API_TOKEN" -H "Content-Type: application/json" -d '{
"tokens": ["DEV_DEVICE_TOKEN"],
"profile": "PROFILE_NAME",
"notification": {
"message": "This is my demo push!"
}
Example:
public function confirmAction($request){
$action = $this->find($request->idtblAction);
$action->idtblStatus=1;
if($action->save()){
//I need to send notification in this part
return Response::json(array('success'=>'true'));
}else{
return Response::json(array('success'=>'false'));
}
}
Ionic io uses Bearer key and profileapp
Any idea?

I've already solve this without using php. I did it through my internal ionic app code.
Thank you to everybody!

Related

cURL and PHP post request

I am new at cURL and can`t understand. I have for example this code
curl -d '
{
"data": {
"title": "Bubble Nebula",
"body": "It`s found today at 21:00",
"icon": "https://peter-gribanov.github.io/serviceworker/Bubble-Nebula.jpg",
"image": "https://peter-gribanov.github.io/serviceworker/Bubble-Nebula_big.jpg",
"click_action": "https://www.nasa.gov/feature/goddard/2016/hubble-sees-a-star-inflating-a-giant-bubble"
}
"to": "YOUR-TOKEN-ID"
}' \
-H "Content-Type: application/json" \
-H "Authorization: key=AAAAaGQ_q2M:APA91bGCEOduj8HM6gP24w2LEnesqM2zkL_qx2PJUSBjjeGSdJhCrDoJf_WbT7wpQZrynHlESAoZ1VHX9Nro6W_tqpJ3Aw-A292SVe_4Ho7tJQCQxSezDCoJsnqXjoaouMYIwr34vZTs" \
-X POST "https://fcm.googleapis.com/fcm/send"
How should i do it work well with php?
Most of the time I just use file_get_contents() for my requests, but that trick is sadly only for GET requests.
However, I recently discovered a new trick that can be used with Post and Get requests(Including everything else that curl can) and still avoids the horrible php library phpcURL, And the best part is, that you don't even need to change your curl command. Try the code below.
<?php
$curl = "your curl command" // paste your curl command here
exec("$curl > curloutput.txt");
$response = file_get_contents("curloutput.txt");
echo($response);
?>
This code should execute your given curl command and return the output. Yes, I know this sounds like a really janky method but it works every time bugless and it is super easy to use.

Send notofication to firebase by PHP Curl, get success response but no notification delivered

please help.
My request to firebase looks like this:
curl https://fcm.googleapis.com/fcm/send -X POST \
--header "Authorization: key=my-api-key" \
--Header "Content-Type: application/json" \
-d '
{
"to": "firebase-instance-id"
"notification":{
"title":"New Notification!",
"body":"Test"
},
"priority":10
}'
And I get response:
{
"multicast_id":7748668110190879774,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{
"message_id":"0:1505463398077072%3f95c2ka3f95c2ca"
}]
}
But I see no added notification in Firebase Console List, nor in phone. Any suggestions? Maybe there are some settings I should change in order to can send notifications from my server through curl? Thanks in advance.
Firebase is weird, according to their documentation you are sending the correct JSON content but Apple's documentation requires a slightly modified format, specifically an "aps" wrapper around the message.
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5
}
Try adding Apple's JSON format to your current JSON payload and see how it responds. From there you can adjust your payload to make sure it works for both Android (which is what Firebase's documentation is for) and iOS.
I think you malformed your FCM payload. It's missing a comma ("firebase-instance-id") and the value for priority should be high.
'{
"to": "firebase-instance-id",
"notification":{
"title":"New Notification!",
"body":"Test"
},
"priority":"high"
}'
Contrary to Chris' answer, don't use the APNs payload format since you're sending it from FCM first.

Facebook graph API: mark message as read

I get message conversations via Facebook graph API which looks like:
https://graph.facebook.com/' + id + '/messages?fields=message
and I want to mark as read the message but I can't find how to in documents.
please, can someone point me to some examples?
You only have read access to the Inbox via the API. So this is not currently possible.
You can set typing indicators or send read receipts using the API, to let users know you are processing their request.
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"sender_action":"typing_on"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
Check below.
sender action = mark_seen..
I am using it and its working fine..
https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions/
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"sender_action":"mark_seen"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=
<PAGE_ACCESS_TOKEN>"

How to use ChromePushNotification in PHP

I need to push notification to user , when new task is assigned to the user, I am planning to use "ChomePushNotification" , but i could not understand how to use it in php to invoke notification..
https://storage-cdn.realtime.co/chrome-push/index.html
Can anyone give me the overview how to use this in PHP , to invoke notification if a record inserted in a table "Task" with agent_id =123, i need to send notification to user "123".. "NEW TASK ASSIGNE.."
The first step is to use javascript to give the user the option to subscribe to the push notifications...
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('sw.js').then(function(reg) {
console.log(':^)', reg);
reg.pushManager.subscribe({
userVisibleOnly: true
}).then(function(sub) {
console.log('endpoint:', sub.endpoint);
});
}).catch(function(error) {
console.log(':^(', error);
});
}
The next step is to use cURL to send the request to Google using the following cURL command, either from the command line or by extrapolating it into a PHP cURL command...
curl --header "Authorization: key=AIzaSyAc2e8MeZHA5NfhPANea01wnyeQD7uVY0c" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration\_ids\":[\"APA91bE9DAy6\_p9bZ9I58rixOv-ya6PsNMi9Nh5VfV4lpXGw1wS6kxrkQbowwBu17ryjGO0ExDlp-S-mCiwKc5HmVNbyVfylhgwITXBYsmSszpK0LpCxr9Cc3RgxqZD7614SqDokwsc3vIEXkaT8OPIM-mnGMRYG1-hsarEU4coJWNjdFP16gWs\"]}"
Please note the cURL example is take directly from the Google Developers page at https://developers.google.com/web/fundamentals/getting-started/push-notifications/step-07?hl=en and uses their sample hashes and keys.
For further information you can review the details of how to send push notifications by checking out the Google documentation at https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en

POST json returns 400 with curl but functional test working

I am trying to build the POST of an API using Symfony2 and FOSRestBundle. The following functional test returns OK.
public function testPostArticleAction(){
$this->client->request(
'POST',
'/api/v1/articles.json',
array(),
array(),
array('CONTENT_TYPE' => 'application/json'),
'{"articleContent":"The content of the content"}'
);
$response = $this->client->getResponse();
$this->assertJsonResponse($response,201, false);
}
But when I try to send a request via Curl with the same request body, it gives me a 400 invalid json message:
{"code":400,"message":"Invalid json message received"}
Here are the curl commands I have tried:
curl -X POST -d '{"articleContent":"title1"}'
http://localhost:8000/api/v1/articles --header
"Content-type:application/json"
curl -X POST -d '{"articleContent":"title1"}'
http://localhost:8000/api/v1/articles.json
Please to note that the GET returns to me a json like:
{"id":68,"article_content":"contents contents"}
But my field is articleContent in my doctrine mapping file. What am I missing?
Your help is much appreciated.
Try updating your header option to:
"Content-Type: application/json"
Additionally - does this request require any type of authentication? You'd need to pass in an auth cookie if so.

Categories